Steil’s OOP Coding Style Requirements
- Classes
- Use
humpback notation. The first
letter of each word in the class name should be capitalized (this
includes the first letter of the class name). Example: SuperHero
- The class
name should describe the data type it describes not any particular
instance of it.
- Variables
- Use
humpback notation. The first
letter of each word in the class name should be capitalized (this
excludes the first letter of the class name). Example: averageBalance.
- Absolutely
no abbreviations, ever!!! But
there are a few exceptions.
- Each
variable should be declared on its own line with its own data type
listed.
- Be
Descriptive
- Use
Booleans for binary flags (not integers.)
- Use
enumerations or other flags (not integers)
- Give
Boolean variables names that indicate true or false. (Not Status)
- Prefix
all pointers with p.
- Constants
should appear in all capital letters with underscores between each word.
- If
you use a notation such as Hungarian be consistent.
- Arrays
or any other list should be named with a plural name. (For example, playingCards)
If the array describes a single entity such as a gameBoard, it can be named as such.
- Never
use global variables. Global constants are good if they are used
globally.
- Never
use a variable for multiple purposes.
- Functions
- No
Abbreviations
- Be
Descriptive
- Void
functions should be named with a verb or verb-noun combination.
- Non-void
functions should be named with a noun or an adjective-noun
combination. This name should describe
the value being returned.
- Use
as many as you can. Even if it is only used once.
- A
function should do only one logical thing. It should be named accordingly.
- Main should be the first function in the file where
it is found.
- All
non-void function should have one and only one return statement. (It must
be structured.)
- No
void function should have a return statement.
- Always
include parameter names in function prototypes. This helps document the function.
- Use
humpback notation for all function names.
That means the first letter of each word should be capitalized (this
excludes the first letter of the function name).
- White
space
- Use
it liberally.
- Place
a blank line before and after all control structures.
- There
should be a blank line between each function.
- All
code within a function, switch, if, for, while or do while should be
tabbed over one level. Do not use
spaces.
- Put
one space between each arithmetic, assignment, or comparison operators
and the operands they work on.
- Within
a conditional statement there should always be a leading and trailing
space. Example: if( x > y )
- {}
- Always
use {}, switch, if, for, while or do while, even if only one line is
contained within the structure.
- The
beginning { should be on the next line after the
beginning of a control structure or function.
- The ending } should be on a line by itself at the end of a
control structure or function.
- Comments
- At
the top of each file list:
- Your
name
- Course
Name
- Assignment
Name
- Never
use flower boxes
- Never
repeat the code
- Never
use end of line comments
- Should
not be used to clarify confusing code.
Rewrite the code.
- Comments
should explain what not how
- Comments
should not contain code
- All
code that has been “Commented Out” should be removed.
- Keep
comments close to the code they describe
- Be
sure comments are up to date.
- Document
the source of algorithms you use.
- Document
where constant values came from.
- Compiler
Messages
- 10%
will be deducted for each compiler warning your program produces in
Visual Studio .NET 7.0 (2003).
- If
the compiler reports the same warning multiple times the 10% penalty
will be deducted for each one.
- There
may be some exceptions to this rule; you will be informed in that case.
- At
least 50% will be deducted for a program that will not compile because of
compiler errors in Visual Studio .NET 7.0 (2003).
- Comparisons
- Never
compare a Boolean variable with true or false. Just use the value of the Boolean
variable in conditions. If you
need to reverse the logic use a ‘!’.