Notes: Perl Lab 14

Program Design

The following are some things that can be done to help in the design, development, and maintenance of a program. Most are not specific to Perl and can be applied to most scripting or programming languages.
  1. Look at the whole problem.

    Don't take the requirements and deal with them linearly. Read through the entire problem (if it is written) so that it is fully understood.
  2. Break the problem down into smaller pieces.

    Look at the overall problem and look at the steps that will be necessary to complete the task. Define each step as a separate problem to be solved.
  3. Outline how the program will function.

    This does not need to be a formal flow chart but rather, a simple outline of what operations will need to be performed. This can be done simply by writing in my comments and then later filling in the actual code for the program.
  4. Write and test each step of the program one at a time.

    Do NOT write the entire program and then start debugging. Doing this will waste a lot of time and make it much more difficult to isolate errors. Use print statements to verify the values of variables when debugging.
  5. Use subroutines.

  6. Use indentation.

    indentation and consistent code formatting make it much easier to identify which groups of code are part of a given block structure. It also helps to be able to visually recognise when a block of code is not properly defined (such as mis-matched braces). Nested blocks can be difficult to find without indentation.
  7. Use descriptive variable names.

    If the variable names actually reflect the values they are expected to store then it will make reading the code and debugging much easier. Good variable names reduce the need for code comments.
  8. Comment your code.

    This should be a given. Not every line needs a comment but there should be enough comments to explain what is happening with each block of code. Any unusual syntax or complex statements should specifically be commented.
  9. Make the beginning of your code a configuration area.

  10. Look at other code examples.

    Don't waste time reinventing the wheel when your problem has already been solved. There are many sources for viewing code examples that are *LEGAL* to reuse. Do not use copyrighted code without the author's permission.
  11. Read the documentation.

    Perl has a wealth of good documentation. Use it.

last updated: 05 May 2004 15:08