Growing up with C made me assume semicolons and braces were needed to avoid subtle bugs, but experience with more recent languages showed me that it’s possible to reliably parse the same semantic cues that humans use: indentation, parentheses, and other such context. (Perhaps this was less viable when C was invented, due to more constrained hardware.)
I was skeptical at first, but in practice, I have never encountered a bug caused by this approach in Python, Nim, or any other language implementing it consistently, over the course of a decade or two using them. Meanwhile, I have seen more than a few bugs caused by brace and semicolon mistakes.
So nowadays (outside of niche & domain-specific languages) I see braces and semicolons as little more than annoying noise and fuel for religious arguments.
In Java it’s quite difficult to forget semicolon and still have a syntactically correct program.
I think braces are incredibly important. With Python it can be confusing which indentation is correct when copying code between files. Different indentations can easily be still syntactically correct, but the outcome is vastly different. It’s often I have to double and triple check to verify I copied the code with correct indentation.
It’s often I have to double and triple check to verify I copied the code with correct indentation.
I vaguely remember facing that issue once or twice in the past, but certainly not often. It was because the pasted code was too long for its starting point to be easily found in my editor, even if I scrolled up a bit.
If this happens to you often, I wonder: perhaps the code you maintain should be broken into smaller functions?
If I was in that situation again, I think I would simply place a bookmark before pasting and then jump back to the bookmark to indent/dedent the pasted block appropriately.
Edit: Come to think of it, I would have to check and correct it regardless of the language and braces, since confusingly indented code is unwelcome in my commits.
As someone used to working in c# (and before that Java, C++, Visual Basic, and Pascal) I haven’t seen any brace or semicolon related errors since the days of Borland IDEs (any remotely self respecting IDE will highlight them and refuse to compile, these days), but working with Kotlin has shown me that I, at least, read code with semicolons slightly faster than code without.
There’s a reason we use punctuation when writing, and the same applies to code.
Ugh, you just gave me Turbo Basic flashbacks. My favorite thing was that variable names could be as long as you liked and mixed case, but the compiler only used the first two letters and case insensitive at that. So “BatShitCrazy” and “BALLPARKESTIMATE” actually referenced the same variable.
Growing up with C made me assume semicolons and braces were needed to avoid subtle bugs, but experience with more recent languages showed me that it’s possible to reliably parse the same semantic cues that humans use: indentation, parentheses, and other such context. (Perhaps this was less viable when C was invented, due to more constrained hardware.)
I was skeptical at first, but in practice, I have never encountered a bug caused by this approach in Python, Nim, or any other language implementing it consistently, over the course of a decade or two using them. Meanwhile, I have seen more than a few bugs caused by brace and semicolon mistakes.
So nowadays (outside of niche & domain-specific languages) I see braces and semicolons as little more than annoying noise and fuel for religious arguments.
In Java it’s quite difficult to forget semicolon and still have a syntactically correct program.
I think braces are incredibly important. With Python it can be confusing which indentation is correct when copying code between files. Different indentations can easily be still syntactically correct, but the outcome is vastly different. It’s often I have to double and triple check to verify I copied the code with correct indentation.
I vaguely remember facing that issue once or twice in the past, but certainly not often. It was because the pasted code was too long for its starting point to be easily found in my editor, even if I scrolled up a bit.
If this happens to you often, I wonder: perhaps the code you maintain should be broken into smaller functions?
If I was in that situation again, I think I would simply place a bookmark before pasting and then jump back to the bookmark to indent/dedent the pasted block appropriately.
Edit: Come to think of it, I would have to check and correct it regardless of the language and braces, since confusingly indented code is unwelcome in my commits.
Don’t you use a formatter that fixes whitespace in sloppy writing?
I’ve never needed one.
As someone used to working in c# (and before that Java, C++, Visual Basic, and Pascal) I haven’t seen any brace or semicolon related errors since the days of Borland IDEs (any remotely self respecting IDE will highlight them and refuse to compile, these days), but working with Kotlin has shown me that I, at least, read code with semicolons slightly faster than code without.
There’s a reason we use punctuation when writing, and the same applies to code.
Ugh, you just gave me Turbo Basic flashbacks. My favorite thing was that variable names could be as long as you liked and mixed case, but the compiler only used the first two letters and case insensitive at that. So “BatShitCrazy” and “BALLPARKESTIMATE” actually referenced the same variable.
It’s kinda organic in python, but God forbid how often I made mistakes in yaml learning k8s
Haha… Yes, I’ve found yaml to be problematic in this area, too. Probably because it lacks the context cues and modularity of a programming language.
Context cues could be provided by jsonschema, but still it’s unbearable in comparison even with json.
Plus any decent editor catches when lines are unreachable or in violation due to misformatting.
If not that, which seems unlikely, your unit tests would
GCC has separate warning when braces don’t match identation