Along with self and or well documented code, there is a way to format the code.
A style guide (or manual of style) is a set of standards for the writing and design of documents, either for general use or for a specific publication, organization, or field. (It is often called a style sheet, though that term has other meanings.) from Wikipedia.
In software(and firmware) coding it is good to follow a style guide. Some software developers are very passionate about which style they follow. My opinion is to pick one that you like you and stick with it. When working on code that was not written by yourself, you should match the style of the original author. I am not passionate about which particular style to use, but I believe that a project should follow the same style in every file. When the compiler or interpreter doesn’t require specific details, things like indent size, block placement, and capitalization, are left to the programmers choice.
I have not chosen a particular style. This week I am looking at the common coding styles that are used. I intend to pick one for this project. I want to choose wisely because I will probably use whatever I choose on all subsequent “C” projects. I want to choose a style that is popular because, I want a high probability of seeing it in other code I will be working with. I also want a style that is easy to read. I don’t care whether tabs or spaces are used for indenting, or how far indenting goes. I found a good article describing why to use and adhere to a style guide.
One thing I found useful in that article, is that Eclipse has a code formatter that will verify your code follows a particular style. There are four built in “C” code styles: K&R, BSD/Allman, GNU, and Whitesmiths. If I type Shift+Ctrl+F while a source file is selected, Eclipse will apply the style to the whole file. A online poll I found indicates Allman and K&R are the most commonly used. I personally like the Allman style better.
I have decided on the BSD/Allman style moving forward with this project.
Do you have a particular coding style you use. What are it’s advantages and or disadvantages?