page18
Making Mistakes (and fixing them)
Mistakes – we all make them. In computer programming there are two different types of mistake you can make in the software. A “syntax error” means you have written something in the program that the computer can't understand. If your sketch contains syntax errors it can't be uploaded to the Arduino.
A “semantic error” means your sketch is understandable but you discover it doesn't do what you meant it to do. This normally means you have made a logical mistake in designing your sketch.
Syntax Errors
Syntax errors will be detected when you either verify a sketch or try and upload it to the Arduino. When a syntax error is detected the status bar will turn from blue to red and red error messages will appear in the program notification area. The area where the computer detected the mistake will be highlighted in the editor.
Unfortunately Processing doesn't handle syntax errors very well. Its messages can be very hard to understand (even for experts) and it doesn't always guess right where the error occurred
Here are some things to check to try and fix any errors:
- Mistyping of names (spelling or case of letters)
- Missing semicolons after statements
- Unpaired round brackets or curly brackets
- Spaces in the middle of names
To minimise problems with syntax errors I suggest you start by evolving the examples and make small steps towards what you want, frequently verifying so that mistakes get caught early.
Semantic Errors
Semantic errors are normally called “bugs”. They could be anything from a program that does nothing to a program that works 99% of the time but occasionally fails unexpectedly.
The process of finding and fixing semantic errors is often a piece of detective work. Normally you should test your sketches thoroughly to make sure that they behave the way you want them to under all circumstances.
If a sketch doesn't do what you expect then try and work out why it follows the behaviour it's showing. Pretend you are the Arduino and “dry run” the instructions in your head. Think about where in your sketch the problem may be and what circumstances trigger the problem. Try and narrow down the range of possible points where the problem originates.