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.
- 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.
- 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.
- 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.
The last test will take place at the final exam time on
Tuesday, 12 December, from 1:30-3:30. It will be written as a one-hour (not
50 minute) exam, but you may have the full two hours for it.
In other respects it will be very like the other tests, but
comprehensive - it will emphasize Python, but cover all the
topics we have seen.
There is a
Sample Exam, but be aware that things will have changed somewhat
with the advent of ChatGPT.
Assignment A
is posted.