45 ms·
The problem with braces is that as a human, you'll still rely on whitespace, and when the whitespace isn't enforced, it can be misleading. if (launch_butto
by xigoi 3y ago
The problem with braces is that as a human, you'll still rely on whitespace, and when the whitespace isn't enforced, it can be misleading.
if (launch_button_pressed)
prepare_missile();
launch_missile();
- Spongman 3y agogcc will give a warning for this. <source>:6:17: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if' 6 | launch_missile(); | ^~~~~~~~~~~~~~ https://godbolt.org/z/cYqhhqz47 https://godbolt.org/z/cYqhhqz47
- lamontcg 3y agoThat should fail a lint check in your CI and your editor/IDE should autoformat that indentation away. You also claim that is a "problem with braces" but you're not using braces and languages like rust no longer allow brace-less single statements like that.
- bobbylarrybobby 3y agoWhich is why you configure your editor to auto format, and then those errors can't exist once you press save.
- x3haloed 3y agoYeah, if I had my druthers, brace-less shorthand syntax like that would never be allowed. I never use it in my own code. Beautify takes care of all questions about what an indent means. C-syntax devs never assume an indent has syntactic meaning. We use it has a helpful hint. We innately understand that it's the braces that matter, and it's really easy to Beautify a file if the original author was sloppy. C-syntax devs read differently. We're not reading a book. We're reading code. And we generally strongly prefer correctness. Braces avoid all unintended bugs related to where the instructions are located on the screen. Pretty is nice. Structure and correctness are better.