4 ms·
But the problem the author described in the article can be solved just by better programming habit- always add braces even for a one line condition statement.
by jw2013 13y ago
But the problem the author described in the article can be solved just by better programming habit- always add braces even for a one line condition statement.
Or just put the one line statement in the same line with the conditional statement such as: if(condition) statement; so when you try to add a line next time, you will notice it was a one line if statement.
But yeah, not explicitly requiring braces for one line condition statement can give us more succinct code but does requires better programming pratice.
- sltkr 13y agoProgrammer's habits are possibly less reliable than requirements enforced by the compiler.
- loumf 13y agoExactly. And these things can be enforced by style checkers, so you don't even need to have good habits.
- Jtsummers 13y ago> And these things can be enforced by style checkers At which point you've got a subset of the primary language, and might (if it were available and appropriate) as well be using a language that already had these good style things as language features.
- knocte 13y agoThis.
- Jtsummers 13y agoknocte, in case you were wondering why you got downvoted (though by the time you read this you may be back to 1 or higher, who knows), on this forum there's a bit of pressure to avoid the "this" and "+1" comments. Some with high enough karma will downvote these sorts of comments when they come across them. To avoid those downvotes, but still post something, minimally add a sentence or two explaining why you're in agreement. For example: This. With Ada, for instance, there's SPARK which is a restricted version of Ada with additional constructs (in Ada comments) for formally verifying the program. Spark, then, has grown to the point where it's almost its own language (though Ada compilers can handle it because of how the annotations are placed in comments).
- loumf 13y agoThe cost to adopting a style checker (if one exists for your language) is very low. Even if one doesn't exist, they aren't very complex -- e.g. Facebook thought it was appropriate to create one for C++ https://code.facebook.com/posts/729709347050548/under-the-hood-building-and-open-sourcing-flint/ https://code.facebook.com/posts/729709347050548/under-the-ho... The costs are more around build process and compile time. Whereas the costs for wholesale language migration include the risk of not being able to ship or hire.
- pdpi 13y agoStyle checkers should be exactly that: tools that check code for correct style. If you have "stylistic" choices that are so important that you disallow their usage altogether because they might lead to critical bugs, then what you're really saying is that the language design is broken. In fact, you're saying that you think that certain parts of the language design are so broken you'd rather work with a subset of the language that doesn't include those features rather than risk having them be misused. This very much puts the choice of language in question.
- AnimalMuppet 13y agoNot necessarily. "This language is the best available tool for the job. It would be even better if..." That doesn't necessarily make it a bad choice. (It may in fact be a bad choice, but more data is needed.)
- loumf 13y agoYes -- I admit to saying all of those things. I am also saying, I have other concerns that are more important, so what can I do to mitigate the problems by my language's design?
- stonemetal 13y agoif (error_of_fifth_kind) {goto fail;} {goto fail;} How do braces save you?
- Terr_ 13y agoThat's why you put your opening curly-braces on the same line as the if-statement, like the good lord intended! if(expr){ expr; }
- Dylan16807 13y agoYou don't allow naked braces either. They have to be tied to control flow.