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

Module Vocabulary (could be) Chapters 3

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

alternative accessible content

(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).

  1. Has a name to be called.
  2. Must be called to activate.
  3. Receives no values.
  4. Returns no values.
  5. Designed to only group instructions.
  6. Usually relies on global variables to work with values between module calls.
  7. This is not a data safe module.
  8. This is not a code safe module.

2) A formal procedure.

  1. Has a name to be called.
  2. Must be called to activate.
  3. Can receive multiple values.
  4. Can return multiple values.
  5. Designed to group instructions and share data.
  6. 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.
  7. This is a data safe module.
  8. This is not a code safe module.

3) A function.

  1. Has a name to be called.
  2. Must be called to activate.
  3. Can receive multiple values.
  4. Designed to return only one value.
  5. Designed to group instructions and share data.
  6. 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.
  7. The function call can be embedded in a mathematical formula.
  8. This is a data safe module.
  9. This is not a code safe module.

4) A method.

  1. First a method must be part of an OBJECT.
  2. Has a name to be called.
  3. Must be called to activate.
  4. Can receive multiple values.
  5. Designed to return only one value.
  6. Designed to group instructions and share data.
  7. 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.
  8. The method call can be embedded in a mathematical formula.
  9. This is a data safe module.
  10. 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.

alternative accessible content

2) Demo Raptor using modules that are passed values to accomplish a specific task.

alternative accessible content  

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).