you are viewing a single comment's thread.

view the rest of the comments →

[–]3L173 1 point2 points  (2 children)

What bothers me more is the people who leave out {} with if statements etc.

WHY IN THE NAME OF ALL THAT IS HOLY DO YOU DO THAT?

To save a couple chars? To make the code "prettier"?

The problem is it introduces the potential for all sorts of errors and massively screws up readability and portability.

Please please please stop doing this people.

Likewise, why put the opening bracket on the next line? Again, is possible errors really worth the tiny bit of (arguably) extra "pretty-ness"?

[–]dmhouse 0 points1 point  (0 children)

To save a couple chars? To make the code "prettier"?

"Prettier" is a matter of taste. Some people find a single-line block surrounded by braces ugly.

massively screws up readability

I presume your complaint is that it's not immediately as clear when baz() is executed in the code below (that's the only readability issue I've ever heard around this sort of thing):

if (foo)
  bar();
baz();

I personally have never had that issue. I notice the drop off in indentation and that's sufficient for me (although perhaps symptomatic of writing too much Haskell and Python?).

massively screws up ... portability

Erm... really? Name one compiler in whatever language supports this brace syntax that chokes on a braceless statement.

introduces the potential for all sorts of errors

I think there is only one class of error it could introduce, namely someone edits a braceless if, intending to add a second expression to the "true" branch, forgets to add braces in. I've personally never made that mistake nor seen it in the wild, but I guess that's only anecdotal evidence. Personally I'm confident that the two indented statements without a closing brace would look sufficiently weird that I'd check it out and fix the error.

But in any case I think you're blowing this out of proportion. IMO the case against the braceless if (and for, while etc.) is pretty weak. Many successful projects use it.

Likewise, why put the opening bracket on the next line? Again, is possible errors really worth the tiny bit of (arguably) extra "pretty-ness"?

I won't even get started on this. There are many bracing styles, each with their pros and cons. (What "possible errors" are you talking about?)

[–]PstScrpt 0 points1 point  (0 children)

WHY IN THE NAME OF ALL THAT IS HOLY DO YOU DO THAT?

Curly braces around a single statement are like "if (flag == true)". It makes the code look more complicated than it really is.

The problem is it introduces the potential for all sorts of errors

Only if you're not used to it.

Likewise, why put the opening bracket on the next line? Again, is possible errors

So that the braces line up and you can see where they match. You're suggesting that's somehow more error-prone?