Thursday, October 19, 2006

Code Style and Conventions

Code Style and Conventions should appear in your SDD. The central aims in devising a coding style for your projects is predictability and readability:

  • Predictability Can members of your group identify semantic features of the code at a glance. You should avoid bad variable names (a, f(), etc), instead use nouns for variables and verbs for functions (m_date, up_vector, computeLocalTime()). Use names to indicate member variables "m_date". If you are using set/get style for member variables, use those names "setTime(), getTime()"; make sure you have symmetry in your names too.

  • Readability Can you read the code and tell what it does. The pinnacle of readable code is Literate Programming, which intertwines documentation and source. You can move toward this without a special programming environment by enforcing good names, liberal use of space, and frequent English comments to lead the eye through the code.


Since many of you are using a web interface, be sure to have conventions for your HTML and style sheets, even if they are automatically generated.

Standard Java conventions.

Details on Naming Conventions.

An example style guide for Mozilla code practice. Note, this style assumes "C" code. Here is a more java friendly style guide called "Turbine".

An example of a code style enforcer for visual studio.

No comments: