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.
- 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.
- 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.
- Print out intermediate variable values to check your work.
Test, then test some more.
- 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.
Did I mention that testing goes hand in hand with programming?
- 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 fist to break it, and then
fixing the weakness.
- 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