Programming Tips
Dianne Hansford, Ph.D.
dianne.hansford@asu.edu
- Understand the problem before coding
What are the given data (input) and what are the output?
What data structures will you need?
- Outline your task on paper
Design the structure of your code
What functions/subroutines will be needed?
- Design some data sets for which you know the answer
Start with very trivial data
- Code and test repeatedly
Don't program everything before testing
- Print out values for all key steps
Don't assume anything is correct
- Don't start using an interactive environment right away
First test several examples
- A pretty plot can make you feel like your code is correct even when it is not
Be sure to test simple examples for which you know the answer
How do you know the plot is correct?
Some Mathematica Tips
- If your program is behaving oddly, close MM and start again
- Keep in mind that variables are global unless they are protected
- Don't use Manipulate until you have tested your code for several examples