C++ Intro

Lecture 8: Program Development & Debugging


What about a programming cookbook?


Unfortunately, due to the extraordinary diversity of application areas, there is no cookbook solution for programming tasks.

However, there are a few useful tips that you could employ almost universally when solving a problem on a computer:

  1. Be clear about what you are trying to build.

  2. Prepare for long-term activity.

  3. Experimentation is a must.

  4. You have to translate abstract ideas into concrete features of the programming language(s) of your choice.

  5. Dealing with complexity requires division of one problem into multiple smaller problems. Fortunately, separation of tasks is easy for both humans and computers. However, enabling effective communication between parts of the program could become a challenge.

  6. Functions give life to the functionality. Think which functions you should create, what are their parameters and return types.

  7. Try to implement clean internal structure. Add comments to explain what your code does.

  8. Approach development by small, incremental steps.

Typical Implementation Steps


When you are building your program, distinguish and keep track of the following activity phases:

  1. Analysis:
    • What is the user view of your application (user interface).
    • Learn the vocabulary that describes the problem.
    • Create a list of features that you will include in your solution of the problem.


  2. Design:
    Go to the drawing board and decide which components you will create, and what type of communication will exist between them.

  3. Implementation:
    • Implement your features (write code for your functions).
    • Think what groups of functions constitute components; that is, be clear about sharing common data between functions.
    • Implement data structures required for proper communication between program components and functions.
    • Use step-by-step (incremental) approach, compile and test your code often.


  4. Documentation:
    When building commercial applications, you will have to provide functional specifications for your code, as well as use case and sequence diagrams. Sometimes these documents will be written by someone else, so you should to be able to understand such such documents.

  5. Remember:
    Good communication with your peers and superiors is one of the advanced programming skills, so don't be afraid to ask questions and discuss issues with the rest of your team.

Debugging

While first meaning of debugging is to remove errors, it's real meaning is the ability to see the execution of the program.

When you are creating a program, you are making many assumptions about its execution. This is a necessity, since it is impossible to see what program will do before it is written. Some of your assumptions could be wrong, and will result in code errors. Even if the code compiles, you might get a strange behavior at run time.

Solution to this problem is to add visibility of the execution, gain control, find precursors to the problem, and, finally, remedy the problem.

OK! You found a problem, and now is the time to fix it. However, remember to make one change at a time. Do not attempt to change too many lines of code at once. "One change at a time" is the only known scientific approach to manual debugging!

Take a break when you have to!

Communication is advanced programming skill, so ask for help if you are getting stuck on an unexpectedly stubborn problem