Coding Style Guidlines

When handing in software code observe the following guidelines:

  1. Strictly follow an indent style, such as described in the Wikipedia entry: https://en.wikipedia.org/wiki/Indent_style.  You may use either the “K&R” or “Allman” styles.  I prefer the Allman style, with 4 spaces per indent.  You may want to ensure proper formatting by using a tool for “prettyprinting”, such as Polystyle (free trial at http://www.polystyle.com/download/)
  2. Fully comment your code — any non-obvious steps must be commented.
  3. Use descriptive variable names — do not be afraid of long variable names.  Your primary goal is to produce bug-free code that someone else can easily read and understand.
  4. Adhere to a single variable/type/procedure naming convention.  You can use underscores or camel-case (I prefer all lower case, and underscores). DO NOT MIX conventions!
    1. void my_function ( int this_is_a_variable )
    2. void MyFunction ( int ThisIsAVariable )
  5. Use “spaces” rather than “tabs”.  This ensures that the text format appears the exact same for everyone, regardless of editor/viewer settings.
  6. Do not insert special numbers in your code.  For example instead of:
    1. velocity = velocity + 32;    // do the following instead
    2. #define GRAV_ACCEL (32)
    3. velocity = velocity + GRAV_ACCEL;
  7. ORGANIZE YOUR CODE into subroutines and separate files, as appropriate!