Sample style rules for programming

One of the simplest ways to enhance the readability of code and documentation is to develop (and enforce) the use of style guidelines. This will become critical when moving to multi-person development, but in many cases substantially improves code quality even when applied on an individual basis.

Below we have a set of sample style guidelines for programming. Obviously there are many possible stylistic choices, the one below is purely used as an example.

Some of these will correspond closely with the lab standards used for this course, and you will find comparable patterns of rules you must adhere to in most software development organizations.

Having such guidelines makes it easier to read, comprehend, debug, and modify large programs written by a variety of developers over extended periods of time.

  1. Define a common layout: this ensures you (and others) know where to look for the definitions of key program parts. For example, all source code files must follow the organization format shown below:
    1. User description
    2. Design description
    3. Header files (include statements)
    4. Other pre-processor directives (# statements)
    5. Global constant definitions
    6. Prototypes (function and type declarations)
    7. Main function body
    8. Other function bodies

  2. Define subroutine size restrictions: no function or method, including main, should have more than 40 lines of code including comments and whitespace, and following the style rules listed below.

  3. Define the minimum common files: Each executable should be accompanied (in the same directory) by a README.TXT file and a MAKEFILE, which should outline all actions necessary to created the desired executable and possible variations.

  4. Define the development environment: development is to be carried out using one of the following packages/compilers:

  5. Define the code layout/style:

  6. Define the notaton for identifiers: (the style suggested here is often referred to in other references as Hungarian notation) variable and function names should not be cryptic - they should convey the role of the function or variable to anyone reading your code.