Presentation is loading. Please wait.

Presentation is loading. Please wait.

Herbert G. Mayer, PSU CS Status 8/2/2013

Similar presentations


Presentation on theme: "Herbert G. Mayer, PSU CS Status 8/2/2013"— Presentation transcript:

1 CS 106 Computing Fundamentals II Chapter 43 “Designing With Procedures”
Herbert G. Mayer, PSU CS Status 8/2/2013 Initial content copied verbatim from CS 106 material developed by CS professors: Cynthia Brown & Robert Martin

2 Syllabus Designing With Procedures Information Sharing
Procedure Specification Implementation Refactoring Example

3 Designing With Procedures
If the code for your program is way less than one page, normally don’t bother with formal design; otherwise: List the major steps of the program. See if it makes sense to use a procedure for each major step Look for opportunities to use a procedure to avoid duplication of code

4 Information Sharing What information does each procedure need? What should the formal parameters be? Which global variables will be accessed or even changed? What should be handled by local variables? Keep in mind that variables should be local unless there is a very good reason to make them global!

5 Procedure Specification
For each procedure in your design, write a brief description of what it does, what global variables it changes, and what parameters it needs. If it is a function, include what value it returns Step through an execution of your process and make sure the information flow is correct Remember to develop tests before you write code!

6 Implementation DO NOT WRITE THE WHOLE PROGRAM AT ONCE!!!!
You can write just one procedure, or just parts of a couple of procedures, and test them. Keep adding bits using your design as a guide until you have all the functionality. Write enough printing code as you go along to see what’s happening. If you have to write extra code, it will save you time in the long run. Or, step through.

7 Refactoring Rewriting existing code to improve it is a common operation Often features are added to a program incrementally and at some point it just gets too messy, unwieldy, and hard to understand Changing and improving the code structure is called refactoring


Download ppt "Herbert G. Mayer, PSU CS Status 8/2/2013"

Similar presentations


Ads by Google