Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't consider the optional braces in C-if a flaw. I use them for early return often, eg

  if (somethingBad)
    return NULL;

  restOfBody();
And I find that the braces are often just unnecessary visual noise. Of course, there is always the issue of people adding extra statements, but I haven't found that to be a problem in practice. YMMV though


The trick to avoiding the problem of extra statements is to only skip the braces if it all fits on one line:

    if (somethingBad) return NULL;
That's a clear visual indicator that the braces have been skipped, but it's basically impossible to look at the next line and not know that it's NOT part of the conditional. Also, if you're having trouble fitting it all on one line, it's a good cue that you're not in a situation where skipping the braces is safe.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: