STYLE
COSC1540 adopts a simple programming style that aims at enhancing clarity and
maintainability, and eliminating certain logical errors. Any program you write,
for Labs or Tests, must adhere to this standard style.
- All names must be indicative of what they represent.
- Program names (in the
program
statement) must start with
a capital letter; e.g. program Convert
- Letters in variable, subroutine and function names must be small-case.
For multi-word names however, you must
capitalize the first letter of the 2nd (and subsequent) word.
Examples:
real*8 pressure
, integer*2 nodeCount
,
subroutine sort(list, size)
.
- Letters in constant names must be all capital. For multi-word names, use the
underscore character to separate names. Example:
real*4 PI
,
real*4 FRICTION_COEF
.
- Indent by at least 3 spaces all statements between
if
and
end if
except for else if
and else
,
which must be aligned with the preceding if
. When an if
statement is nested within another, its body will be indented further by an
additional 3 or more spaces.
- Indent by at least 3 spaces all statements in the body of a loop.
When a loop
is nested within another, its body will be indented further by an
additional 3 or more spaces.
- Refrain from using magic numbers in your code (numbers whose role and/or
origin is not readily obvious). Use constants instead. The only exception to
this rule would be the numbers zero, +/-1, and +/-2.
- Full-line comments must appear before each function, subroutine, or program
to explain what it does (not how it does it).
- Full-line or in-line comments must appear as needed within the code to partition
it into logical segments or explain subtle steps. Any code that cannot be readily
understood by a programmer familiar with the problem, must be documented.