How to write a computer program

  • Sketch out the solution on a piece of paper or in design mode. If you don’t know what the solution looks like, you don’t understand the problem yet, so do this first. Try to show this sketch to somebody else, preferably the person you are doing the project for.
  • List the variables you will need to solve the problem. Define what they are used for and give them meaningful names. If you can’t do this, you don’t understand the problem and you need to figure out a smaller part of the problem to solve first.
  • Write a narrative of what the user is going to do in order to use the program. Write down what your program is going to do for each step of the narrative. This can be in an abbreviated form of English.
  • For each step in the narrative, write the code on paper. If you are uncertain of how the code should work or look like in that step, try to write a little program to test your understanding. You are trying to avoid experimenting. When you actually write your program, which, unless you are lucky, wastes time.
  • You are almost ready to get on the computer. Find a sympathetic friend or classmate and walk them through your design.
  • Write your code. If you did the last 5 steps correctly, this should be more like typing.
  • Run the code. Locate and correct any syntax errors. Avoid the temptation to ignore these errors. Testing while ignoring syntax errors is a waste of time.
  • Pretend you are your own worst enemy, intent on making you look bad. Test the code.

Leave a Reply

Your email address will not be published.