Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

braces are gonna be the death of me!

 
Belinda Lawson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not complaining, really. Just whining a wee bit. Anyone else have trouble adjusting to every brace being on a new line? Maybe it's just me. It's just a seriously new concept for my pea brain.

 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are code formatters out there (some that integrate with the more popular IDEs) that allow you to code in whatever style you like and then convert the braces to conform to the convention that you're required to use.

Since different companies have different conventions, it is a good idea get comfortable with several of the more common ones. A large part of programming is reading and modifying other people's code so this is something you can expect to run into on a regular basis.

I prefer the K&R style of brace matching myself but, when I donate code to the Ranch, I follow the Ranch's convention.
 
Marilyn de Queiroz
Sheriff
Posts: 9066
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I actually used to have the opposite problem. I was so used to seeing each brace have it's own line that I would miss seeing them at the end of the line ...
 
Dick Summerfield
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally I find the big advantage of the "block indent" style as used on Cattle Drive, is that it gives a direct and clear visual cue to the block structure.

Mind you, I did not really have to adjust. My only previous experience with "block type code" (or whatever it's called officially) was many years ago. It was pre-Java and pre-OOP, not C (but did use the Kernighan & Ritchie style).

So I'm happy to continue using the block indent style but I would be interested to know what the advantages of K&R style are, and which presumably I've missed?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dick Summerfield:
...
So I'm happy to continue using the block indent style but I would be interested to know what the advantages of K&R style are, and which presumably I've missed?


Having a coding convention and sticking with it company wide is much more important than the particular style you choose. Experienced developers should be able to adapt quickly to either style.

That being said, I personally prefer the K&R style for three reasons.

1.) I'm used to it.
2.) Matching braces generates a lot more whitespace which causes developers
to have to scroll around the file more to read it, buring the brain's
CPU cycles in the process. The extra white
space also makes lines of related code, grouped like paragraphs,
separated with whitespace less prominent.
3.) It embeds the line of code to which the braces belong to the block of
code itself which helps avoid typos like this:



There is merit to both and a developer should be able to submit work to the company or school in a format that matches the convention of that institution.
 
Belinda Lawson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all of you for you helpful comments. I poked around in Eclipse and found their code formatter and taught it to do braces correctly for java ranch. Now I can run it through there to remind myself. It's all good!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic