Standards Document

coding-style

I am writing a coding standards document for a team of about 15 developers with a project load of between 10 and 15 projects a year. Amongst other sections (which I may post here as I get to them) I am writing a section on code formatting. So to start with, I think it is wise that, for whatever reason, we establish some basic, consistent code formatting/naming standards.

I've looked at roughly 10 projects written over the last 3 years from this team and I'm, obviously, finding a pretty wide range of styles. Contractors come in and out and at times, and sometimes even double the team size.

I am looking for a few suggestions for code formatting and naming standards that have really paid off … but that can also really be justified. I think consistency and shared-patterns go a long way to making the code more maintainable … but, are there other things I ought to consider when defining said standards?

  • How do you lineup parenthesis? Do you follow the same parenthesis guidelines when dealing with classes, methods, try catch blocks, switch statements, if else blocks, etc.

  • Do you line up fields on a column? Do you notate/prefix private variables with an underscore? Do you follow any naming conventions to make it easier to find particulars in a file? How do you order the members of your class?

What about suggestions for namespaces, packaging or source code folder/organization standards? I tend to start with something like:

<com|org|...>.<company>.<app>.<layer>.<function>.ClassName

I'm curious to see if there are other, more accepted, practices than what I am accustomed to — before I venture off dictating these standards. Links to standards already published online would be great too — even though I've done a bit of that already.

Best Answer

First find a automated code-formatter that works with your language. Reason: Whatever the document says, people will inevitably break the rules. It's much easier to run code through a formatter than to nit-pick in a code review.

If you're using a language with an existing standard (e.g. Java, C#), it's easiest to use it, or at least start with it as a first draft. Sun put a lot of thought into their formatting rules; you might as well take advantage of it.

In any case, remember that much research has shown that varying things like brace position and whitespace use has no measurable effect on productivity or understandability or prevalence of bugs. Just having any standard is the key.

Related Topic