dr. andy seddon staffordshire university school of computing code design (the use of pseudo code for...
TRANSCRIPT
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Code Design
(The use of pseudo codefor Elementary Process Descriptions)
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
What are mini specifications?
A process descriptor provides a detailed explanation of the internal processing policy of a
functional primitive that transforms input data into output data
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Documenting a process
Various means and tools include pseudo code (structured English) decision trees decision tables action diagrams mathematical algorithms
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Documenting the policy
Need only specify the processing policies necessary to transform data or simply provide data.When stating policy, only specify what rather than how with regard to processing data.Try to specify data transformations from the user’s vantage point.
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
A process descriptor...
must exist for every functional primitive in a DFD
must state the ways in which data flowing into the process are transformed into output flows
must state the policy that governs the transformation, not the method to do so
should seek to control redundancy should use a small set of constructs
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Additional process descriptor information
As well as logic the process descriptor should mention
processor requirements security requirements time requirements processing requirements performance requirements safety requirements
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Specifying logic (1)
Sequence
Repetition
A B
A
A
Do While Repeat Until
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Specifying logic (2)
Selection
A
A B A CB
IF IF THEN ELSE CASE
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Pseudo code/structured English
Programming Design Language (PDL) by Caine and Gordon, a ‘pidgin’ language that
uses the vocabulary of one language (i.e. English) and the overall syntax of another (i.e. a structured programming language)
Tom DeMarco defines structured English asa specification language that uses a limited
vocabulary and a limited syntax
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Structured English vocabulary
The vocabulary consists of imperative English-language verbs terms defined in the data dictionary certain reserved words for logic formulation
The structured English minimal set can now be defined
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Syntax and variables
Data flows, data stores, common processing routines: upper case hyphenated words (define in data dictionary)
Local variables: upper case hyphenated words (do not define in data dictionary)
Commands, primitive functions, sources/sinks: lower case first letter capitalised
Prepositions/verbs: lower case
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Assignment statements
Assign values to single variables with
VARIABLE = Value / Literal / Expression
VARIABLE Value / Literal / Expression
Set VARIABLE to Value / Literal / Expression
Compute VARIABLE = Expression
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Operators (1)
Arithmetic expressions Results are numeric Operators are: addition (+)
subtraction (-)multiplication (*)division (/)exponentiation (**)
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Operators (2)
Boolean expressions Results are either True or False Logical operators And, Or and Not Relational operators: less than (<)
less than or equal (<=)equal (=)not equal (< >)greater than (>)greater than or equal (>=)
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Sequence of execution
All commands are intended to be executed in a forward sequential order as written unless the logic or command indicates otherwise.
It is helpful to establishindentation rules to helpidentify computationalunits.
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Repetition statements (1)
Do While statement
While condition Do
:
statements
:
EndWhile
condition
statements
False
True
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Repetition statements (2)
Repeat Until statement
Repeat
:
statements
:
Until condition
condition
statements
TrueFalse
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Decision statements
If...Then...Else
If condition then
:
statements1
:
else
:
statements2
:
endif
condition
statements1 statements2
True False
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Input/output statements
Various ways of designating flow of data into and out of a functional primitive process are acceptable
Input OutputAccept SendGet PutRead Write or Print
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
File manipulation
These commands not absolutely necessaryCreate data-entry in data-store-name
Delete data-entry from data-store-nameSearch data-store-name for conditionLocate data-element(s) in data-store-name for conditionMatch data-element-1 to data-element-2 in data-store-nameMerge data-store-name-1 into data-store-name-2
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Case statements
Allows several alternative sets of processing logic to be distinguished without the need for multiple If..Then..Else statements
Case 1 (condition)statements1
Endcase 1Case 2 (condition)
statements2Endcase 2:Else statements (n+1)Endcases
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Common processing routines (1)
Defined in the data dictionary Can be called more than once in the system CALL statement lists the parameters needed
by the called process to perform its tasks. The calling process receives the output data
elements from the called routine
CALL common-processing-routine-name (parameter list)
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Common processing routines (2)
7.1.1Validate currencyexchange
7.1.3Calculatecommission fee
7.1.2Calculate currencyvalue
Determine currentexchange rate
Currency Type
ExchangeRate
Currencydetails
Converted currency
Exchange request
Total currency
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Common processing routines (2)
Calculate Currency Exchange descriptor 7.1.2
Input Currency details from Validate currency exchange:
Call Determine current exchange rate(Currency Type, Exchange Rate)
Multiply Currency Value by Exchange Rate:
Output Total currency to Calculate commission feeStop
Dr. Andy Seddon
StaffordshireUNIVERSITY
Schoolof
Computing
Suspension, termination & comments
It may be necessary at times to halt processing temporarily:
– to allow a passage of timeOutput Request-For-Info-Msg to CustomerWAITInput Customer-Info from Customer
– to wait to be reactivated by another processOutput Customer-Rec to Master-FileWAIT