Department of Mathematics

Math 300: Mathematical Computing

Ideas of Programming

In this class we are learning that Mathematicians can make good use of small programs to perform repetitive tasks. Writing these is not intuitive for everyone. Here are some ideas to use when you work on yours.

  1. Write small chunks, then test. Rinse, repeat.
    • One of the biggest mistakes people make in programming is trying to write the entire program in a single sitting. While it is good to have a plan for the overall structure of the program, if you write too many lines of code without testing, then the program is difficult and frustrating to debug. If you write just a few lines of code, test, and then add some more, things are much easier.
  2. Use the KISS principle.
    • Keep It Simple, Stupid! Why write five lines of code when one will do? Always strive to keep programs as simple and transparent as possible. This makes them easier to write, easier to debug, and easier to change. Professional programmers pride themselves on brevity - you should too.
  3. Print out intermediate variable values to check your work.
    • Mistakes happen, but if you don't know what they are, you can't eliminate them. Printing out intermediate results as you test your code allows you to see what is happening to various variables inside the program. You can delete the printing statements when you are finished.
  4. Test, then test some more.
    • It is not enough that your program can handle the little 3 by 3 example you made up. You must test it on larger, more difficult problems. Use more than one test. Try to think of how you can break it. You can be sure that in this class the instructor will be thinking of how to break it! Win by being the first to break it, and then fixing the weakness.
  5. Did I mention that testing goes hand in hand with programming?
    • You must test your program as you write it! Build a good test data set before, or as, you write your program. Do not wait until the end - you must test as you go. The testing will help you in writing - knowing how to run your program will help you write it efficiently.

Assignment 7 is posted.

A solution to the exam has been posted.

Department of Mathematics, PO Box 643113, Neill Hall 103, Washington State University, Pullman WA 99164-3113, 509-335-3926, Contact Us
Copyright © 1996-2015 Kevin Cooper