this post was submitted on 17 Aug 2024
713 points (95.5% liked)
Programmer Humor
32562 readers
394 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I mainly found it annoying while writing code, because the lack of braces makes it difficult to tell when a scope ends. Plenty times, I've wanted to add something to the end of a for-loop, but had too little indentation.
Usually this means I get a runtime error, because it can't access some variable from the loop-scope. But worst case, it only executes once after the loop and I don't notice the problem.
Another big thing I miss when not having explicit braces, is opening up new/anonymous scopes to isolate variables, which helps prevent mistakes down the line + reduces code complexity.
For example, this is a thing I do quite regularly:
It allows me to visually group the initialization code for the client and I don't need to have the
timeout
variable in scope afterwards. Depending on the language, you can also have theclient
variable mutable inside the scope and then immutable outside.Yes, this could be pulled out as a function to achieve something similar, but in my experience people (including me) will often just not do that, because it's only the
timeout
variable or whatever.To address this, I prefer reducing length & depth of nested code, so the
for
/while
is rarely ever not visible along with everything inside it. Others have success with editors that draw indentation lines.I occasionally use Python nested functions for this purpose