r/java • • Jan 29 '14

Google Java Coding Standards

http://google-styleguide.googlecode.com/svn/trunk/javaguide.html
156 Upvotes

103 comments sorted by

View all comments

36

u/[deleted] Jan 29 '14

4.1.1 Braces are used where optional Braces are used with if, else, for, do and while statements, even when the body is empty or contains only a single statement.

I hate when people omit curly braces for some insane reason. At least Google has my back.

9

u/clutchest_nugget Jan 29 '14 edited Jan 29 '14

if(done) return 1;

Can someone please explain to me what is wrong with this? Not questioning that it's bad style, genuinely curious as to what makes it bad style.

Edit: thanks for the responses.

0

u/[deleted] Jan 29 '14

[deleted]

-18

u/[deleted] Jan 29 '14

I've been programming for 7 years and have literally never made that mistake.

22

u/treerex Jan 29 '14

It's usually not made when you're writing the code, but later when you're maintaining it. Including the braces is simply good defensive programming.

-18

u/[deleted] Jan 29 '14

That's rediculous. It isn't defensive either. If you're doing that lousy of a job maintaining your code, your going to make more serious mistakes.

We also live in the 21st century, aren't working with cathode ray monitors and should be putting our braces on a new line.

14

u/treerex Jan 30 '14

You have evidently never worked on a large project with many developers of varying skills with a 15 year old code base.

-3

u/[deleted] Jan 30 '14

Respect your projects code guidelines, I agree. I however have modernized them for my own team.

7

u/jtdc Jan 30 '14

Yes but we still have greenhorn coworkers straight from college to contend with. Rules like these protect the code.

-6

u/[deleted] Jan 30 '14

You wouldn't need to protect them from messy/obscure/unnatural/asymmetrical/old brace placement initially instated due to monitor constraints in the stone age if you place them where it makes most sense Now that we can afford it thanks to the luxuries introduced a decade ago.

4

u/geodebug Jan 30 '14

Chip meet shoulder

-8

u/[deleted] Jan 30 '14

1990, meet 2014

4

u/geodebug Jan 30 '14

Java's syntax hasn't changed that much since the 1990's so why would the best practices change just because a few years have passed?

Besides, most modern languages have a similar best practice when it comes to braces.

Doesn't matter, code how you want on your projects. If you coded for mine you'd be auto-formatted to the standard anyway.

-5

u/[deleted] Jan 30 '14 edited Jan 30 '14

Oh yeah, you mean like c#? It takes standards decades to change, it takes technology seconds (ie LCD displays.)

6

u/geodebug Jan 30 '14

You've lost me. I think you're just saying random things.

-1

u/[deleted] Jan 30 '14

Then you couldn't have understood the argument I was making from the start of this discussion at all...

→ More replies (0)

4

u/RagingOrangutan Jan 30 '14

Protip: touting your experience programming is not a good way to earn the respect of your fellow programmers.

-4

u/[deleted] Jan 30 '14

I'm not touting anything at all. 7 years isn't something to tout about.