Planning the internal structure of the program

After planning the external description of a program, you should plan its internal structure. This planning should precede coding, and should be done in English not Geek or VB.

This planning will take some time, but, it will save time in the long run. The plan will also become part of the documentation of the program.

For now, you can plan what your event handlers will do and what variables you will use. Once you have the plan, coding will be simple, and you will cut down on logical errors.

You should state what each event handler will do. (This may be only one thing or it may be a complex series of steps, a complex algorithm).

You should also state the characteristics of each variable you plan to use: purpose, name, data type, initial value and scope. If a variable can be local, it should be. If possible, make all variables local. Doing so will make your program easier to read and there will be less chance of inadvertent logical errors.

For example, here is the plan I made before writing a payroll program:

Event handlers:

Event:  The user clicks on the Calculate Pay button
Action(s) to take:  Compute and display gross pay, tax and net pay

Event:  The user clicks on the Stop button
Action(s) to take:  Close the program

Event:  The hours worked textbox gets focus
Action(s) to take:  Clear the gross pay, tax and net pay

Event:  The hourly rate textbox gets focus
Action(s) to take:  Clear the gross pay, tax and net pay

Variables:
Name:  sngHours
Data type:  single precision
Purpose:  the number of hours worked
Initial value:  0
Scope:  local

Name:  sngRate
Data type:  single precision
Purpose:  the rate of pay
Initial value:  0
Scope:  local

Name:  sngGross
Data type:  single precision
Purpose:  the number of hours worked
Initial value:  0
Scope:  local

Name:  sngTax
Data type:  single precision
Purpose:  the amount of tax
Initial value:  0
Scope:  local

Name:  sngNet
Data type:  single precision
Purpose:  the number of hours worked
Initial value:  0
Scope:  local

Name:  sngTotal
Data type:  single precision
Purpose:  the sum of everyone's gross pay
Initial value:  0
Scope:  global

In an earlier note we spoke of five steps in developing a program. We have now added a new step, planning the internal structure of the program:

  1. Define the external specification including the user interface and event handlers
  2. Build the user interface
  3. Plan the internal structure of the program
  4. Code event handlers and write common code
  5. Debug the program
  6. Document the program


Disclaimer: The views and opinions expressed on unofficial pages of California State University, Dominguez Hills faculty, staff or students are strictly those of the page authors. The content of these pages has not been reviewed or approved by California State University, Dominguez Hills.