File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Cattle Drive and the fly likes braces are gonna be the death of me! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "braces are gonna be the death of me!" Watch "braces are gonna be the death of me!" New topic
Author

braces are gonna be the death of me!

Belinda Lawson
Greenhorn

Joined: Feb 10, 2007
Posts: 10
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
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 ...


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Dick Summerfield
Ranch Hand

Joined: Oct 04, 2007
Posts: 90
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Feb 10, 2007
Posts: 10
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: braces are gonna be the death of me!