Language Neutral Code Style Guide

Copyright (c) 2007 NDP Software. All Rights Reserved.

Introduction

This document provides a minimal set of style requirements for small to medium size projects. Beyond what's stated here, it's important to create code that promotes readability, re-usability and consistency.

Packaging

Delivery

Products are delivered in one of the following formats, as negotiated at project start:

Components

The code provided should be a complete package with all components needed for a 3rd party to install, build and run the product:

Organization

The recommended directory structure is:

Documentation

The following are required supplemental documents.

Data dictionary

This data dictionary should include:

README.txt

A doc/README file contains the following:

Files

File names

File names should be understandable to a new programmer reading the code. File extensions should be self-consistent and follow the prevailing industry standard. In object-oriented languages, files should match the class name.

In all cases:

Comments

Each file should contain a block level comment indicating the purpose, author and related files. This should include a copyright header (provided).

Functions

The following guidelines apply to all functions.

Names

Comments

Each public function should contain a block level comment indicating its purpose. (For languages without public/private constraints, all functions are considered public.)

Parameters

A maximum of five (5) parameters are allowed in strongly typed languages, and three (3) in dynamically typed languages.

Size

Functions should be 50 lines or fewer.

Complexity

Arithmetic and boolean expressions should have 6 or fewer terms.

Functions should aim for a cyclomatic complexity <= 10. See MCCABE

Parameters, Constants and Variables

Parameter, constant and variable names should be understandable to a new programmer reading the code.

In all cases:

Non-Functional Code

Code that is no longer needed should be removed from the project (not commented out). Files not required by the project should not be delivered in the package.

Code that needs further work should be tagged with the comment keyword "TODO" for easy identification.

References

See these references for more information:

  1. McCabe, Thomas J. "A Complexity Measure." IEEE Transactions on Software Engineering, Vol SE-2, No. 4, Dec 1976.
  2. Taking Cyclomatic Complexity For A Ride (WebLog)
  3. JavaDoc, and java.sun.com coding style guidelines.
  4. Doxygen.org
  5. Coding Conventions for C++ and Java Applications,

Attachments

Last revised NDP, 3/2007