Good Programming Practices
- Plan on paper before typing on computer when you attempt to
write a program. Pseudocode is almost always the answer to a major problem.
- Use printf or scanf statements to find errors in your program.
- Identing your code to make it more readable.
- Commenting your code liberally . This is important, a mark is usually
lost on the labs if you fail to document your program effieciently.
- Choose meaningfull variable names.
- Use underscores in long variable names to make them more readable i.e.
this_is_your_age.
- There should be no more than one statement per line.
- Use identifiers of 31 or fewer characters. This helps
ensure portability and can avoid some subtle programming errors.
Common Errors
- Forgetting to terminate a comment line with */ or starting
a comment with */.
- Mismatched braces {}. To be sure you have the right number
count them, if they are even then maybe you have misplaced
them, if odd then your missing at least one.
- Typing the name of the output function printf as print in a program.
- Using a capital letter where a lower case should be used. C is CaseSensitive!
- Forgetting one or both of the double quotes surrounding the
format control string of a printf or scanf.
- Placing an escape sequence such as \\n outside the format
control string of a printf or scanf.
- Confusing the equality operator = = with the assignment operator =.
- Forgetting to terminate a statement with a semi-colon;
- An attempt to divide by zero is normally undefined on computer systems
& generally results in a fatal error i.e. a crash.