Programming tips
May 31, 2004
- Write your code nicely, with the body indented and useful names for variables
- Make your changes one at a time and test them
- When your program works, make a copy of it to make further changes on. If you mess things up,
you will be able to go back to your last working version
- Think your changes out on paper before you make random changes to your program
- Try to find precedents for your program in other programs you or others have written
- Read the course book and exercises for analyses and suggestions
- If something goes wrong, break the problem down into small stages: if a sentence fails to parse, try
the subject and VP separately; if the VP fails, try its constituents separately, and so on, until you
identify the place where things break
- then try tracing the execution of the program; typing ’s’ (for ’skip’) instead of carriage return allows
the trace to jump over sections of the program you are not interested in.
- Watch any error messages that are thrown up when you compile your program, they tell you where
to look for mistakes in your code and give you the line number where the error was detected