Program Design Methodology
Program Design Methodology
- Programming = problem solving using a computer
- Small problems can be solved without writing down an algorithm.
- Larger problems require written design.
- Problems need to be broken down and solved one part at a time.
Why Plan?
- Group projects without a plan will not work.
- If you have not figured out the design before you begin coding, you may paint yourself into a corner and have to start over.
- You will save time by planning.
- You can verify that the algorithm works before coding.
- The plan is your "blueprint" for software construction.
How do I Design an Algorithm?
- Good question. There is no real answer to this question that works in all cases.
- Algorithm design is the creative part of programming--a very human endeavor.
- Computer programming is an art.
- Elegant solutions are the simplest, but not all problems can be solved elegantly
- Experience helps--patterns of problems and solutions emerge over time.
Some Help
- Make sure that specifications are complete and make sense. Do you understand the problem?
- Determine what the program is supposed to output.
- What errors might occur while the program is running?
- How should the program end?
- Get answers to questions about the specifications before writing any code.
More Help
- Break the problem into subproblems
- For each subproblem
- write a concise problem statement to be sure you understand
- find an existing algorithm (if there is one), or create a new one
- design the data structures needed
- write out the steps (algorithm) for solving the subproblem
- Create the code to implement your solution
- code and debug each function separately
- this is called procedural abstraction
- test all functions together
Diagramming Techniques
- System analysts often conduct the analysis phase of system design
- One way to work on the problem description is to model it graphically
Structure Charts
- Useful for decomposing the problem into smaller parts
- Think of the boxes as functions in your program.
- Relationship between the boxes--one function can call zero or more functions; a function can be called by zero or more functions.
- Create the diagram from the top down.
- The ultimate goal is functionally cohesive modules.
- Modules have one task with all of the parts of the module contributing to the task.
- Prevents side-effects
- Minimizes coupling (loosely coupled vs. tightly coupled)
Implementation
- Using the plan you developed, begin writing code.
- Document as you code. (Function header comments)
- Place detailed comments at the beginning of the program explaining the purpose of the program
- Make comments for each function and use comments for unusual logic (driver1.cpp PrintList)
Testing
- Testing can use about half the time for development of a system.
- Test modules independently.
- drivers to test modules
- stubs to test modules for which functions have not been developed
- test cases that exercise all logical possibilities. Test normal and borderline cases.
Robustness
- How will the program react to invalid data?
- Should the program crash?
- User-friendly error messages. Are compiler messages user-friendly?
- How robust a program needs to be depends on the specifications and the user.
System Testing
- Testing modules alone is not enough.
- The whole system with all modules included needs to be tested.
- Testing by end-users should be done since they are the ones who must ultimately accept the system. (Beta testers)
- Systems that do not get the acceptance of the end users will fail even if well written. Software designed with the user in mind.
Debugging
- When you encounter errors:
- Think!
- Random changes only make the problem worse.
- Use debugging tools. PC vs. Unix
- Fixing one error may cause another error (or more.) Retest with the same tests as before.
- Keep the test cases for future use.
Back to Outline