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.
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?
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.
Joined: Feb 10, 2007
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!