CS 250 Computer Programming and Problem Solving - FALL 1998 

[ Home | Syllabus | Notes | Glossary | CS250 WEB Version Home Page ]


 

Problem Solving and Software Engineering


Programming in the Large

Construction methods do not "scale up".
E.g., bridge construction

Site

Construction

Pedestrian bridges across small streams 2x4's lashed/nailed to an anchoring post
Pedestrian bridges across larger streams rope bridge with plank flooring
"country" bridge, light vehicular traffic wooden trestle bridge
suburban overpass, moderate traffic concrete and steel arch
medium width river, heavy traffic steel girder and cable suspension bridge
wide river, heavy traffic concrete and steel, pylon support

Programming methods do not scale up either.

"Toy" programs 100's of lines
Small programs 10,000 lines
Medium programs 100,000 lines
Large programs 1,000,000 lines
Very Large programs 10,000,000 lines

Small programs are typically implemented by individuals.
Medium and larger programs are implemented by teams.


Scaling in Time

Throwaway programs run a few times, discarded within a few weeks
Personal programs kept, run by programmer only
Local programs run under programmer's supervision
Released programs one version, run by "public"
Supported programs multiple versions released to public over months/years

 


Software Development

Students Professionals
Get assignment from instructor  
Ask clarifying questions 5%
Devise an appropriate algorithm 5%
Code the algorithm 20%
Validation: Testing 5%
Debugging 65%
Never_look_at_it_again  
   
Get request from user.  
Requirements_Analysis 10%
|Functional Specifications 20 %
Design 15%
Implementation 15%
Validation: Testing 30%
Debugging 10%
Maintainence 100-200%
   

("Professional" figures based on successful NASA projects.)


Software Life Cycle


The Importance of Abstraction


Phase 1: Specification: What vs How


Phase 2: Design: the Software's Architecture


Pre and Post Conditions

float SquareRoot(float x)
// Calculates the square root of a floating point number
// Precondition: x >= 0
// Postcondition: RV * RV = x (where RV is the value returned)


Phase 3: Verification (is it correct?)

// Chap 1, p 8
// computes the sum of A[0], A[1], . . ., A[N-1]
// for any N >= 1
int Sum = A[0];
int J = 1;
while (J < N) // loop invariant goes here
{ Sum += A[J];
++J;
}


// Chap 1, p 8
// computes the sum of A[0], A[1], . . ., A[N-1]
// for any N >= 1
int Sum = A[0];
int J = 1;
while (J < N) // Sum is the sum of the elements A[0] through A[J-1]
{ Sum += A[J];
++J;
}


Phase 4: Coding

Characteristics of Good Programs

Contributing to Those Characteristics


Clear Implementation

1. Extensive use of subprograms
2. Avoid global variables in subprograms
3. Proper use of REFERENCE parameters
4. Functions without side-effects
5. Orderly flow of control
6. Error Handling
7. Readability
8. Documentation


Proper use of REFERENCE parameters

If a subprogram needs to return only one value, consider
making it a function.
Procedures normally use REFERENCE for exactly those
parameters where a value is to be sent to the caller.
An exception: REFERENCE parameters may be used when
passing large arrays into a subprogram.
(but you can use the "const" adjective to tell the compiler that nothing is to be changed)


Functions without side-effects

Side effects are any change to the program status other than
returning a value.
o Changes to global variables.
o REFERENCE parameters in functions.
o I/O
As a rule functions should have no side effects. Procedures
should minimize side-effects, and explicitly document those
that they have.


Orderly flow of control

o The general flow is forward.
o Modules are entered only at their beginning and exited only
at their end.
o Conditions for entering and terminating loops are clear.
o The alternative cases of conditional statements are clear.
Most uses of "goto" violate one or more of the above.


Readability

o Choose meaningful names for variables, subprograms, and
constants.
(Pay special attention to numeric and string constants.
Should they be named?)
o Indentation and Whitespace to make programs readable


Documentation

1. Header comment for program.
(a) Purpose
(b) Author and date
(c) Description of program input and output.
(d) How to use.
(e) Assumptions (what type of data expected, what could go wrong).
(f) Brief description of global algorithms and data structures.
(g) Description of key variables.

2. Header comment for each module.
(a) Description
(b) Pre-condition and Post-condition
3. Comments within body explaining important and confusing parts of code.


Testing & Debugging Technique

Testing is the search to determine if errors exist.
o Test with valid data leading to a known solution.
o Test extreme or boundary cases.
o Test with invalid data to check error-detection capability.
o Test with random data.
o Test with actual data.


Testing & Debugging Technique 2

Debugging is the search for the causes and corrections to an
error.
Effective use of output is the key.
Debug output should indicate the location and the values of
key variables at that location.


User Interface

 


Copyright chris wild 1998.
For problems or questions regarding this website contact [Chris Wild (e-mail:wild@cs.odu.edu].
Last updated: August 30, 1998.