MOD4 - Writing Modular Programs
MOD4 - Objectives
- Locate Quick Check Link
- View MOD4 Demo
- View Building Modular Programs
- View Raptor Examples
- Feedback
Quick Check Link
As you advance your training you need to check to make sure you are ready to move on. You just might want to make the next link connection to take a Pre-test and see if you are ready for our subject. If it goes well you might take the Post-test to see if you are advanced. While you are here you could also look for any solution demonstrations.
(click here for Quick Check Link)
Vocabulary Critical
code simplicity |
reuse |
teamwork |
call statement |
heirarchy chart |
local variables |
global variables |
variable scope |
passing by value |
arguments |
passing by reference |
parameter list |
global constants |
return value |
function |
|
|
Modular Programming might take some getting used to. We will start here and add more as we move into future learning modules.
View MOD4 - Demo Tip, Tax, and Total
If you would like to see the next part to my demonstration series involving a simple restaurant example then click on the link below to get started. Make sure you have seen the MOD3 version first.
Link: (click here for Tip, Tax, and Total MOD4)
View MOD4 - ChangeUs (an Algorithm)
Passing values is not always easy. Check out this demo from the Gaddis book using module argument passing.
Link: (click here for ChangeUs MOD4)
Building Modular Programs
(after watching the intro video you might want to scroll to the bottom of this page to watch an example of program modules)
Why would people build programs that do not use modules?
- They are in a hurry.
- They start programming with no training or little training.
- They start with the intentions of building a very small project.
- They see the solution as one building unit and cannot visualize the separation of tasks into smaller components of the whole.
What happens when people start writing programs after they have design training?
- We hope the results will be better.
- A course in program design can help you as a programmer see the need to plan.
- Computer programming can be a very complex skill which is enhanced when it begins with a structured approach.
- Design training helps when you are building large interconnected applications.
- They start their programming assignments with sound development techniques. Developers tend to start their programming experience without an organized design approach plus they develop bad habits when they begin with no training.
- We know it is better to start with good techniques rather than have to change from bad techniques to good techniques. Y2K was an example of bad techniques that had to be changed. The cost was huge.
What might encourage the use of modules?
- Wanting to get a good start in programming style.
- Seeing the need, early on, how important it is to break tasks down into manageable pieces.
- To understand the benefits of working together in teams.
- Choosing to keep the program logic as simple as possible.
- Realizing that in the long run you can manage programming projects much better if they are developed using modular techniques.
What is a modular program?
A modular program is a program that was developed grouping statements that perform similar (specific) tasks together. Each module in a program can contain a few lines of code or may include several lines of code depending on how broad you define the operation being performed.
What are four levels of modules we might tend to use?
1) A simple procedure (might be called a subchart).
- Has a name to be called.
- Must be called to activate.
- Receives no values.
- Returns no values.
- Designed to only group instructions.
- Usually relies on global variables to work with values between module calls.
- This is not a data safe module.
- This is not a code safe module.
2) A formal procedure.
- Has a name to be called.
- Must be called to activate.
- Can receive multiple values.
- Can return multiple values.
- Designed to group instructions and share data.
- Usually does not rely on global variables to work with values between module calls. The desire is to pass all values from and to the module.
- This is a data safe module.
- This is not a code safe module.
3) A function.
- Has a name to be called.
- Must be called to activate.
- Can receive multiple values.
- Designed to return only one value.
- Designed to group instructions and share data.
- Usually does not rely on global variables to work with values between module calls. The desire is to pass all values needed to the module and return only one value.
- The function call can be embedded in a mathematical formula.
- This is a data safe module.
- This is not a code safe module.
4) A method.
- First a method must be part of an OBJECT.
- Has a name to be called.
- Must be called to activate.
- Can receive multiple values.
- Designed to return only one value.
- Designed to group instructions and share data.
- Usually does not rely on global variables to work with values between module calls. The desire is to pass all values needed to the module and return only one value.
- The method call can be embedded in a mathematical formula.
- This is a data safe module.
- This is a code safe module.
Raptor allows what module types?
- Raptor has Sub-Charts
- Raptor has Procedures
- Raptor does not have plain Functions
- Raptor does have Methods
Raptor Examples
1) Demo Raptor using 3 modules to show how modules can operate with a global approach to variables.
2) Demo Raptor using modules that are passed values to accomplish a specific task.
Feedback for MOD4
I really appreciate feedback from people who use my site. Each time you complete a subject from the top it would be great if you could send me feedback. Just email me to say what you like, what you dislike and any corrections you might suggest. You could also let me know if you had your own solution to suggest. My email is (objectcoach@aol.com).