Recommended C++ and Java Coding Standards? 40
Gerard J.
Pinzone queries: "My company is looking to implement C/C++
and Java coding standards. However, I can't seem to find a definitive
list. I'm more familiar with Java and have suggested that we use
'Elements
of Java Style' and Sun's
documentation. BTW, beware of
'Netscape's
Software Coding Standards Guide for Java.' It's woefully
out-of-date! Any suggestions?"
Try this (Score:3, Informative)
for java may I recommend.. (Score:3, Informative)
It reformats your code (i use it via ANT)
Just play with the settings and see what you like, it'll reformat the code to what you want.
I just set it up here, and it works a treat.
Saves all those source code arguments about where the squigaly brackets go.
Things to think about (Score:2, Informative)
I don't think you need to be reminded of the reasons for having a coding style standard, but in case anyone questions it, it undoubtly increases readability of people's code, and reduces the time needed to understand other people's code. We have also found that we are slightly better organized in how we produce code when we follow these guidelines.
Some suggested things to think about:
For example, you might say all begining capitals for functions, such as "void OnOKButtonClicked()", first lower case then all starting caps for variables, such as "fltNewGradePercentage", and all caps for macros, such as "STANDARDSIZE".
For example, at work, we use three-to-six letter prefixes to designate the type of the variable - intFiles is an int, chrpCurrent is a character pointer, etc.
I'm sure that there are other things to think about, which will be suggested, but these are places to start when considering a standard.
Linux (Score:5, Informative)
The proposed Boost C++ Coding Guidelines (Score:3, Informative)
What I like about the guidelines is the well thought out rationales presented and its adherance to current C++ standards. After reading them, I wanted to follow the guidelines because I agreed with the rationale, rather than simply because the document said so.
Avoiding anal retentiveness... (Score:3, Informative)
Too many coding standards get into issues that are, quite frankly, ludicrous. If the programmers I hire can't handle slight differences in C++ brace placement, I need to find better programmers! Sheesh, I've never had problems following code because someone places the open bracket on the same line as the if, while I put mine on a subsequent line.
Having written for publication, I've had quite some experience with the anal retentive crowd. For example, I was excoriated for having an algorithm with 1-character variable names -- the code was, however, an implementation of a specific mathematical formula, and my code precisely matched variables in the original notation. To change the names to longer "descriptive" ones would have broken the continuity between definition (in a math text) and implementation (C++). The short names were actually more descriptive and accurate!
And then we have the "goto" wars -- I actually use a single goto in one of my books, bringing down the ire of mypoic ninnies (usually pre-degree college students) who only know that "gogot is bad" without a clue as to why they've been taught that. A rare, judicious goto can make code faster and more readable! But try telling that to fools who only parrot dogma... if a programmer can't understand the rare usefulness of a goto, they probably can't think far enough "outside the box" to be useful in the real world.
This isn't to say that I'm against coding standards -- I'm all in favor of them! But a coding standard should by flexible in nature and open-minded where practical; the goal is readable code and ease of typing. Programmers have habits, a rhythm when they type, and so long as their code follows broad guidelines of style. I'll take a dozen good comments and a solid design document over the placement of curly brackets any day!