1 04 Pseudocode Style Guide
1 04 Pseudocode Style Guide
INTRODUCTION
During the design phase, software developers create models of different aspects of the
system. Each type of model provides a different viewpoint on the prospective system.
Some emphasize functionality, some highlight data, and others model behavior of the
system in response to its environment.
As the design process progresses, the software developer refines high-level, abstract
models into more concrete models by adding detail. This process reflects increased
understanding of the program components. The culmination of the design process is the
creation of the most detailed model of the system: the pseudocode.
Pseudocode captures the final decomposition of the problem into its most refined design.
It embodies all three kinds of modeling perspectives: functionality, data, and state
transition. The purpose of the pseudocode is to represent the algorithmic level of program
functionality, including how the functions utilize the data and how the program reacts to
events and changes state. Pseudocode is essential during program design in allowing the
programmer to work through complex details of the algorithm without being concerned
with minor aspects of language implementation. (The final implementation phase is the
proper arena for addressing language-specific issues such as input/output formatting and
exact statement syntax.)
Pseudocode has the following properties:
STYLE OVERVIEW
Good pseudocode style includes:
• alternation operations
• repetition operations
Once a noun is used for a specific data object, that noun must be used exclusively.
Changing the data object's name or spelling makes your design read like a Russian novel.
Constant data should be written using all capital letters:
BONUS DISCOUNT MAX_SCORE RATE
THRESHOLD
The following logical, relational, and arithmetic operations can be used within
pseudocode expressions:
+ - * / div mod
and or not
= <> > < >= <=
Assignment of a value to a data element is done as follows:
Set x to 3
Every multi-line statement that contains a program control structure will begin and end
with a keyword. Following is a list of program control structure keywords:
Control Structure Ending Keyword
If Endif
Case Endcase
While Endwhile
Repeat Until
For Endfor
SIMPLE SEQUENCE OPERATIONS
Simple sequence operations may be broken into two primary groups 1) those that perform
input/output operations and 2) those that perform data manipulations operations. Some
sample pseudocode statements for simple sequence operations include:
Input/Output Operations
Prompt for menu selection
Display total with labels
Read selection
Write totals with labels to printer
Open inputFile using fileName
Write name, idCode, address to outFile
Close inputFile
Data Manipulation Operations
Compute grossPay
Add value to total
Compute average by dividing sum by count
Remove record
Subtract expense from subTotal
Append record
Calculate circumference
ALTERNATION OPERATIONS
The three types of alternation commonly used in procedural programming are:
• Repetition an unknown number of times, perhaps not at all / pre-test loop ( while )
• Repetition an unknown number of times, but at least once / post-test loop ( repeat
until / do while)
• Module name
Repeat
Read selection
Convert selection to upper case
If ( selection invalid ) then
Display advisory message to screen
Endif
Until ( selection is valid )
Case ( selection )
( Screen )
Assign outDevice
( Printer )
Assign outDevice
( File )
Prompt for fileName
Read fileName
Assign outDevice to fileName
Endcases