Rules of Programming in any Language
-
Write self commenting code. Use variable names that are full words or common
abbr. (note that "abbr" is not a common abbreviation)
-
Write comments which remain true even if the code changes. E.g.
GOOD: if (INPUT_PIN_1) { //Input 2 is data
BAD: if (INPUT_PIN_1) { //Data pin
(notice that pin 2 is the data pin, but the code was changed to test another
pin instead. The bad comment will lead future programmer to think of pin
1 as data.)
(notice that this is a bad example, because the constant should have been
INPUT_DATA... see Rule 1 above.)
-
Write lots of comments
-
Retain lines of code which are bad for non-obvious reason as a warning to
future programmers. Just comment them out and add the reason.