Hacker News new | ask | show | jobs
by ja30278 4218 days ago
I never understand the desire to omit braces in single line blocks.

sure

   for ()
       foo
saves you a line, but it's a bug waiting to happen.
4 comments

Are there not examples where a statement is pretty much guaranteed to live on its own within a block? Having said that, my own style is to always include braces, for aesthetic reasons if nothing else.
When I omit braces I also omit the indented line. I would write:

    for () foo;
Makes it clear it's ONE statement. At least for me...
This makes debugging much harder.
A function or class that doesn't fit on a single screen is a bug waiting to happen.
People keep saying that, but do bugs like that really happen? In my entire career as a professional software developer I've never seen it happening. Not once.
Fair enough. That being said, -Wunreachable-code would have caught that.
>Fair enough. That being said, -Wunreachable-code would have caught that.

-Wunreachable-code was disabled in gcc years ago.

Yes, but I would assume that Apple uses clang internally?
Apple's goto/fail bug could only exist because single-line then clauses work.