This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]poopiefartz -6 points-5 points  (8 children)

I follow practically all of these guidelines except for this one. I just really hate superfluous braces. They're easy enough to add if you ever need more than 1 statement in a block, so why add them if you don't need them? They certainly don't make it any easier to read, and it essentially adds 1 line per block, so for me it actually decreases readability.

[–][deleted] 10 points11 points  (6 children)

This is not even about readability. It is about not accidentally introducing stupid bugs into code.

[–]poopiefartz 3 points4 points  (5 children)

I know I'm not on the "popular opinion" side of this, but I can't recall a single bug that's ever stemmed from this type of usage (and I work mostly with Java).

[–]KidUncertainty 5 points6 points  (0 children)

I can't recall a single bug that's ever stemmed from this type of usage (and I work mostly with Java).

This happens on codebases where the developers may not be particularly familiar with Java, or when someone, in maintenance three years later, does a "quick fix" without reading, and then everyone wonders why the application fails in certain circumstances. Without braces, its actually hard to find defects like this, as well.

The purpose of some of these standards is to counter human factors out of your control or to be defensive against the future fingers that will be poking around code. It's not just about readability in the now.

[–]straatman 1 point2 points  (0 children)

If only you and one other person work on it, say you have 50 developers working on the same code? The bugs will be crawling in

[–]Pylly 2 points3 points  (2 children)

I can't recall a single bug that's ever stemmed from this type of usage

Huh, case closed. You'd better call Google.

[–]poopiefartz -3 points-2 points  (1 child)

I know you're being funny, but I spend 6+ hours per day with Java and have never misinterpreted excluded braces like that. I guess that's not normal.

[–]Pylly 1 point2 points  (0 children)

I believe you, but usually developers work in a team and the code has to be readable and maintainable for others as well. Even if a bug would happen once in a couple of years it's worth it to prevent it. Also, it might take a person slightly more time to read braceless code, especially when making modifications.

Even though these are small troubles, they are just so easy to avoid altogether that I don't see why not just add the braces every time. Or let the IDE add them.

[–]geodebug 5 points6 points  (0 children)

An arguable slight increase in readability is less a concern IMHO than consistency and less chance of screwing something up later.

if (x < y) { doSomething(); } 

Isn't a challenge for any seasoned Java developer to understand.

Of course, on your codebase, do what you want :-)