CIS 150 Coding Standard
Different instructors, like different organizations, have their
own coding standards which you must follow. In general, these
tend to be very similar to each other and usually reflect industry
standards. We want you to code in a style that is recognized and
respected in the field. We also want your code to be easy to read,
debug, and maintain. The coding standards help to achieve these goals.
Basic program structure
Your programs should be organized as follows:
- main program documentation
- include directives
- constants
- class definitions
- function prototypes
- global variables (these should be rare at best)
- main function
- all other functions
Documentation
- The main program documentation should be a block comment including your name,
the date, the course number, the assignment number, and a description of
what the program does. It should also include what is needed for input
and for output. Any additional notes that would be helpful should be included
after the main information. Samples will be provided in class and online, and
will get more detailed as the course progresses.
- Each function should have its own block comment documentation preceding it
which gives its prototype, describes what the arguments to this function are,
what the function returns, and a description of what the function does.
- Add comments to any section of code that is not obvious explaining what
is being done.
- Do not hand in code where sections of code have been commented out as if they
are documenting your failures. Code that doesn't work should be removed unless
it is needed for valid documentation purposes.
Capitalization and naming
- Variable and function names should be lowercase. If they are composed of
multiple word parts, each starting letter after the first should be
capitalized. This is called camel-casing. Examples: num, payRate, hoursWorked.
- Symbolic constant names should be in all caps. Words should be separated
using an underscore. Example: TAX_RATE.
- Variable names should be descriptive. Example: hoursWorked, NOT hw. An exception
is simple loop counters which may be a single letter or abbreviation.
- Function names should be descriptive of their purpose. Example: calcGrossPay().
Indentation
White space
- You may use blank lines to separate statements to make code more readable,
but do not use white space excessively.
- DO NOT double space your code. It's annoying and makes the code harder
to read and maintain.
Miscellaneous
- In this couse, the use of proper namespaces is considered important. Since
the statement "using namespace std;" makes namespaces close to worthless,
it is not allowed in your programs for this class unless specifically allowed
by the instructor. Instead, your programs should use specific "using"
statements as needed. See the example programs for actual C++ examples.