(Ce 309: Computer Programming Lecture Notes Part-Ii) : Structured Software Design and Maintenance
(Ce 309: Computer Programming Lecture Notes Part-Ii) : Structured Software Design and Maintenance
(Ce 309: Computer Programming Lecture Notes Part-Ii) : Structured Software Design and Maintenance
FRITZ ENGINEF::RING
l1\BORATO!-N Li8R,li,RY
by
...
Celal N. Kostem
Lehigh University
Bethlehem, Pennsylvania
August, 1986
4. E~FICIENCY OF SOFTWARE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.1. EFFICIENCY CHECKLIST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
5. RELIABILITY OF SOFTWARE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.1. RELIABILITY CHECKLIST . . . . . . . . . . . . . . . . . . . . . . . • . . . . . . . . 34
i
6. 1. UNDERSTANDABILITY CHECKLIST .. •• 3 5
6.1.1. Structuredness. .35
6. 1. 2. Documentation . • 35
6 .1. 3. Consistency .. . .36
6. 1. 4. Completeness .. . . . 37
6.1.5. Conciseness .... • ••• 3 7
6. 2. COMMENTS ON THE MODULE SIZE .. .37
ii
FOREWORD
1
1. STRUCTURED AND MODULAR PROGRAMMING
2
1 ····································-
F
r-+-.._..... IFC.. .. )2 3 1
~-....-~2 ...................-...........
t---+-e---i i ································
3 ..........................
5 .........................
t---+-~
GO TO 1
6 .............·-·············
DO 7 ........
---,._-t IFC.. .. ) GO TO 1
7 ······-····················
3
* The control of transfer of operations should be as sequen-
'!
tial as possible.
*Etc.
5
SOFJNRRE LIFE CYCLE
I ,.
ll£0UIR£KEnTS
J~
I .
I ~ : Sft£CIFICATIOHS ~,
I ... PRELIUHJliY
DESIIiH
......
I
_fONT.
.... DETrtiLED
DESI&H ~
• •
-
CODIHii JlHD
DUUiiliiHii ......
t
-
Of'ERATIOHS MD
,.....
...
IIAIHTEnftHC£
REVALIDATION
_...,._
! ! ! !
6
DESIGN
SPECIFICATIONS
COOING REQUIREMENTS
MODULE TES
7
Contrary to beliefs, the time requirement for the coding and
debugging is only 20% of the overall effort (See Fig. 1.3). An
equal amount of time is spent on the development of the
"specifications and requirements" of the software module. Just
the design of the software requires 15% of the total effort.
Before the inception of any coding effort one should spend about
one third of the allocated time and funding.
POSSIBLE DECOMPOSITION :
IF-THEN-ELSE BLOCK
~----~7
b) The module has one unique entry point and one unique
exit point.
9
c) The module represents one logical, self-contained
function.
•I..__ ___.
2. SELECTION
TRUE
FALSE
3. ITERATION
TRUE
FALSE
11
PROPER PROGRAM SEGMENTS
12
PROPER PROGRAM SEGMENTS (CONT.)
13
IMPROPER PROGRAM SEGMENTS
15
6. Documentation is required in the source code to intro-
duce each module by explaining its function, its data
requirements, and its invocation relationship to other
modules in the program.
17
14. NONSTANDARD LANGUAGE FEATURES SHOULD NOT BE USED AS A
GENERAL RULE. (This is a cardinal rule of programming.)
18
2. SOFTWARE DEBUGGING
19
The cost of these tests would be borne by the users.
(Example: ANSYS in the Civil Engineering Department's CAB-
Laboratory, NASTRAN at LUCC.)
(c) If you have full access to the source code, and if you
are responsible for the maintenance of the software, the
changes in the code will have to be undertaken by you. At
the completion of the reprogramming activity, extensive
tests need to be conducted by you to confirm the reliability
of the results. The cost of these tests may be borne by the
computer center only if the computer system change is sub-
stantial and during the interim period you are "invited" to
test the new configuration. This is a short duration window
of opportunity, and the tests can be conducted only at
select times and select dates. Other than this possibility,
the cost of the tests is usually borne by the software
developer.
If you have access to the source code and ~f you have to initiate
debugging operations, the following paragraphs should be noted,
and implemented.
20
to the compiler, and results in the compiler making an
"assumption" in the interpretation of the "code.'' Even though
most non-fatal errors may not have any detrimental effect on the
results of your program, all non-fatal errors should be expunged
through rewriting the source code, and recompiling the program.
After the successful compilation of the program with linkage, and
with or without execution, the following checks must be
performed:
21
2.3 ERROR CATEGORIES
I. Design Error
1. Missing cases or steps
2. Inadequate checking/editing
3. Initialization error
4. Loop counter error
5. Misunderstanding of "specifications"
6. Incorrect algorithm (e.g. math error)
7. Timing problems
8. Failure to consider all data types
V. Testing Error
1. Inadequate test cases/data
2. Misinterpretation of test results
3. Misinterpretation of program specifications
4. Negligence
VI. External
1. Hardware failure
2. Software reaction to hardware failure
3. Problems in other systems that interfaced with
this one
VII.Specification Error
1. Incomplete or ambiguous specification
2. Incorrect problem definition
22
2.4 DEBUGGING GUIDELINES
Almost any and all debugging activities, especially the ones in-
itiated by individuals who do not have a good grasp of software
engineering, tend to be disjointed. If the individual is under
constant pressure to debug the program to meet deadlines, the ef-
forts may be futile due to the disorganized attack to the bugs.
To remedy the situation, below you will find some specific
guidelines that must be observed. This list is taken from Martin
and McClure's book.
23
clerical/coding type errors.
24
3. OPTIMIZATION OF THE FORTRAN 77 SOURCE CODE
25
generated after the compilation is to be executed it is not pos-
sible to make a categorical statement as to which one will be
less costly.
For the type of program and problem described above, it will not
be unrealistic to say that "unoptimized compilation" will take
''1-unit of time," and the execution will require 100-units of
time. If optimization is to be used, the optimization time may
very well be 1.5-2 units of time. The execution time may very
well be 70-units of time. Thus the unoptimized run may cost
$101, and the optimized run will be $72.
26
levels of optimization the amount of time required for the
compilation, which also includes the optimization, goes up.
(III) During the later parts of the debugging, where you may
be getting execution errors, the optimization could be used
with the following proviso. If the time required for the
execution of the program is substantially longer than the
time required to compile the program, some level of op-
timization may be justifiable. If the additional time
required for the optimization is less than the execution
time, than the optimization is a viable alternative.
27
ing all of the following conditions:
It should be noted that (a) above could have been done by careful
programming. However, (b) is not normally considered by the
programmers. Thus, the optimization by the compiler would be far
more efficient than the amateur attempts. In order to do (c),
you need to program in assembler language, thus optimization by
the compiler is a highly desirable alternative.
When OPT=3 is not selected, the compiler assumes that any exter-
nal reference modifies all registers; therefore, it does not ex-
pect any register contents to be preserved across function calls.
28
If a math library other than FORTRAN Common Library is used in an
installation to supply intrinsic functions, the B-Register por-
tion of the OPT=3 option must be deactivated by an installation
option in order to ensure correct object code.
Good practice:
DIMENSION A(20,30,40), B(20,30,40)
.................................
...... . ....... ........... . .......
DO 10 K=1,40
DO 10 J:1,30
DO 10 I=1,20
10 A(I,J,K)=B(I,J,K)
29
(2) The number of different variable names in the subscript
expressions should be minimized. For example:
X:A(I+l,I-1) + A(I-l,I+l)
IPl=I+l
IMl=I-1
X=A(IPl,IMl)+A(IMl,IPl)
30
element stiffness matrix can be populated in one master
subroutine. In very crude terms 576 statements, ex-
clusive of any other statement to control the logic,
are needed to populate the matrix. Thus there are some
"algorithms'' that will inevitably need more than 600
executable statements to perform the assigned mission.
31
4. EFFICIENCY OF SOFTWARE
32
4. Are exception routines and error-handling routines iso-
lated in separate modules?
7. Is all invariant code, that is, code which does not need
to be processed within a loop, processed outside the loop?
16. Are the most efficient data types used for subscripts?
33
5. RELIABILITY OF SOFTWARE
34
6. UNDERSTANDABILITY OF COMPUTER SOFTWARE
6.1.1 Structuredness
6.1.2 Documentation
35
(d) A list of modules that this module invokes.
(d) Assumptions
6.1.3 Consistency
7. Does each variable and each procedure have one and only
one unique name in the program?
36
11. Are parentheses used to clarify the evaluation order of
complex arithmetic and logical expressions?
6.1.4 Completeness
6.1.5 Conciseness
37
(a) The old rule of thumb was that a routine should not be
larger than the number of cards that can be gripped in one
hand between the thumb and the index-finger. (Highly
unscientific and depends on your "anatomy.")
(c) IBM: Should not exceed 50 lines (B. Boehm, "Seven Basic
Principles of Software Engineering," in Infotech State-of-
the-Art Reports: Software Engineering Techniques, Infotech
International, Maidenhead, England, 1977).
38
7. MODIFIABILITY OF SOFTWARE
39
(d) Operate with different data structures or algo-
rithms depending on resource availability?
40
8. PORTABILITY OF SOFTWARE
41
4. Does the program use operating system functions mini-
mally or not at all?
42
9. TESTABILITY OF SOFTWARE
43
10. USABILITY OF SOFTWARE
44
detail with examples included?
45
(e) For interactive systems, are manuals "on-line?"
For batch systems, are manuals readily available?
(e) Does the program allow the user to extend the com-
mand language?
(g) Does the program allow the user to define his own
set of functions and features?
46
(i) Does the program allow the experienced user to
work with a faster version, allowing abbreviated com-
mands, default values, and so on, and inexperienced
users to work with a slower version, providing a help
command, monitoring capabilities, and so on?
47
11. OVERLAYING
COMPILERS
"ACCOUNTING FILES.,
LIBRARY ROUTINES ETC.
J
AlJAILABLE SPACE!!!!!
48
If the available central core space is less than the program
requirement (see Fig. 11.2), and if the computer system in ques-
tion is not a virtual system than the program can not be handled
by this computer without some modifications. Some of the
"scientific computers," e.g. CYBER 850, and most of the personal
computers do not have virtual memory. If these computers are to
be used for very long programs and/or programs that use many
, large arrays, such that they will not fit into non-virtual sys-
tems, the approach to take will be the use of OVERLAYING. This
is a definite need for the problem shown in Fig. 11.2.
49
COMPUTER MEMORY
.
I OPERATING SYSTEM
I COMPILERS
I LIBRARY
ACCOUNTING FILES ..
11
I ROUTINES} ETC.
A~JAILABLE SPACE!!!!!
PR06R8H
<MOTE: PR06R8H > RURILRBLE SPICE >
50
the original program will reside in core for the full duration of
the job. This program can be referred to as (OVERLAY 0,0), and
is also known as the MAIN OVERLAY. These discussions can best be
visualized through inspection of Fig. 11.3. It is then possible
to identify major program segments that can reside in the core
one at a time in addition to the executive program. OVERLAY-1,
OVERLAY-2, etc. can be considered as independent programs, or
"mega-subroutines." OVERLAY-1, OVERLAY-2, etc. can be called
only from OVERLAY-0, i.e. the executive program. When the execu-
tion of OVERLAY-0 reaches such a point that a call is made to
OVERLAY-!, OVERLAY-0 and OVERLAY-1 will be in the central core.
When this call is made the control of the flow of the program
will be transferred to OVERLAY-1. This is similar to the calls
that are made to SUBROUTINES. At the completion of the execution
of OVERLAY-1 the control will be transferred back to OVERLAY-0.
At this stage OVERLAY-1 is "automatically removed" from the
central core. The execution of OVERLAY-0 will continue, and a
call to OVERLAY-4 may be encountered. OVERLAY-4 will be brought
inro the core; thus, OVERLAY-0 and OVERLAY-4 will be in core. At
the completion of the execution of OVERLAY-4, the control will be
transferred back to OVERLAY-0, etc.
PROGRH"
E>{ECUTIUE PROGRAH 1 I.E. TRAFFIC CONTROLLER
(must reside tn-cot--e thr·oughout the execution)
CAti CALL 0 1JERLAYS-1 1 2 1 3 1 i
,OIJERLAV-1
OIJERLAY-2
CAN CALL OIJERLAYS- 2.1 1 2.2 1 2.3 1 2.i
OUERLRY-i!.l
OOERLRY-i!.l
OOERLRY-i!.i! OOERLRY
-i!.'l
IOl.IERLAY-3
JouERLAY-i
51
11.2.1 SECONDARY OVERLAYS
It is also possible to identify program segments within a primary
overlay that can be considered as "self-contained." Calls to
these SECONDARY OVERLAYS can be made from the PRIMARY OVERLAY to
which they ''belong." The general concept can be seen in Fig.
11.3. It should be noted that, for example, during the execution
of OVERLAY-2,3, the overlays that will be in the core are
OVERLAY-0, OVERLAY-2, and OVERLAY-2,3.
OVERLAY(CE309,0,0)
PROGRAM XXX
CALL OVERLAY(5HCE309,1,0)
CALL OVERLAY(5HCE309,4,0)
....
CALL OVERLAY(5HCE309,2,0)
CALL OVERLAY(5HCE309,3,0)
CALL OVERLAY(5HCE309,1,0)
STOP
END
SUBROUTINE PDQ(,,,,,)
RETURN
END
[additional subroutines, where needed]
OVERLAY(CE309,1,0)
PROGRAM YYY
RETURN
END
52
SUBROUTINE ABC( ..... )
RETURN
END
[additional subroutines, where needed]
OVERLAY(CE309,2,0)
PROGRAM ZZZ
CALL OVERLAY(5HCE309,2,1)
CALL OVERLAY(5HCE309,2,4)
CALL OVERLAY(5HCE309,2,2)
CALL OVERLAY(5HCE309;2,3)
. PROGRAM YYY
CALL OVERLAY(5HCE309,2,1)
....
RETURN
END
[as many subroutines as needed]
OVERLAY(5HCE309,3,0)
PROGRAM WWW
RETURN
END
[subroutines, i f needed]
OVERLAY(5HCE309,4,0)
PROGRAM XYZ
RETURN
END
In the above example CE309 is the name of the file on which gen-
erated overlays are to be written. "0,0", "1,0", "2,0", "2,1",
"2,2", etc. are the primary and secondary overlay numbers. These
numbers are in octal (0 through 77).
53
11.4 OVERLAY COMMUNICATIONS
Inspection of Fig. 11.3 and the ''program" given in the previous
section indicates that there exists a need for a mechanism to
transfer the values of the variables from one overlay to another.
If such a mechanism does not exist the values read or computed,
for example, in OVERLAY(CE309,0,0) can not be transferred to
OVERLAY(CE309,1,0).
(b) files.
54
11.5.1 Computer Resource Requirements
Limited benchmark tests conducted by the author may give some
''feel" for the CPU time requirements for overlayed vs. virtual
systems. Two finite element programs were fine-tuned for non-
virtual memory system, i.e. overlaying was used. A series of
finite element problems were executed. The same problems were
run using two different virtual memory minicomputers using two
different finite element programs. The programs were fine tuned
by the developers for these minicomputers. The same problems
were executed in these new programs with modified element and/or
node point numbering in order to give the best performance as far
as the specific program is concerned. The total CPU time for
these runs were at least five times larger than the corresponding
figures obtained in the non-virtual computer. For some problems
the factor was larger than "10." It is recognized that the mini-
computers are slower than the scientific mainframes; however,
such a discrepancy in the time requirements was unexpected(!!!).
55
I Start I
t
Read Data, Initialize Arrays,
Compute Constants
•
jApply Unit Load!
•
Compute Yield Load and
Scale up all Field Quantities
I . *
l Increment Load by ( F} I
lIteration• BeginsJ
t
Generate and Solve the Equilibrium Equa-
tions for the Increments in Displacement
'
Compute Curvature Rates in each Plate Element
and Total Strain and Stress Rates in eac~ Layer
t
Compute Effective Stress and
Total Stresses in each Layer
Yes
'
Is Effective Stress in
Plastic Plate Layers Acceptable?
No
Update all Records
t
J
Correct Stresses in
all Plastic Layers
56