Evaluating Programs for Clarity
"Good ideas can be buried in impenetrable code." Looking at a program and deciding on ways to revise the code can be an interesting and challenging task.
A software engineer knows that a working program needs to be understood by others. The current Y2K problem is an example of how critical this is.
Top Down Design
- Function main ( ) is an outline, consisting of calls to other functions that contain actual code.
- All functions called by main( ) are prototyped above and written below it.
- Each function performs one task, usually less than a screen (20 lines).
- Every variable is either passed to a function as a parameter or declared locally in a function.
- Upper/lower case is clear and consistent with meaningful identifiers
beginning with a lowercase letter;
if more than one word, subsequent words begin with caps;
constants all caps. EXAMPLES:
distance, totalDistance, getValues( ), MAX
- Bodies of code delimited by curly braces are indented a consistent 3 to 5 columns and white space is used appropriately.
- The comment block at the top of the program contains your name, date written, lab name, teacher, period, and short paragraph describing what the program does.
- Each function, other than
main( ), contains pre- and post-conditions
Continue to: Unit 1