Scholarly Resources for CompSci Undergrads

C Programming

Common Mistakes & Marking Codes (BGSU edition)

Made with CSS

This list of mistakes commonly seen in undergraduate computer science programming assignments is based on a version I used while teaching introductory C++ at Bowling Green State University.

This version is in XHTML and uses Cascading Style sheets. You might prefer to view a PostScript® version or a PDF version instead. I've also go an HTML version of an earlier edition (at UWO).


The mistakes are grouped into the following 5 categories:


  1. Comments

    1. Comment briefly on what your program does.
    2. Comment on what each function does.
    1. Comment the `logical sections' of your code. Be brief but precise.
    2. Do not restate what the source code says but rather explain what it is for.
  2. Comment on what your variables represent.
  3. Readability

  4. Use meaningful variable and function names.
  5. Avoid `magic numbers'. Use meaningfully named const variables instead.
    1. Indent consistently for readability.
    2. Seperate sections of your program with blank lines.
  6. Do not unnecessarily repeat code in a program. Implement repeated tasks as functions or loops.
  7. Use modularity: main() should mostly just call the functions that are the sub-modules of the program.
  8. Clear coding

  9. Do not include unnecessary code. Do not initialize unnecessarily — it's confusing.
  10. Use appropriate conditional structures (e.g., if or if/else or switch).
    1. Use the appropriate loop structure (e.g. while instead of do/while or for).
      • Use a while loop when you want to test the condition before you enter the loop the first time.
      • Use a do/while loop when you want to execute the loop at least once.
    2. Use a for loop only when you know how many times you want to repeat the body of the loop.
    3. Don't use break to jump out of loops.
      • (This was a department policy for the first C++ course, for an opinion about how break can make some loops clearer see The Practice of Programming by Kernighan & Pike.)
  11. Use parameters instead of global variables to pass information to (and from) functions.
  12. Do not use unnecessary parameters.
  13. Output

  14. Prompts to the user should be explicit, and helpful to the user.
  15. Format your output for readability.
    1. Submit all your output.
    2. Test runs should be executed in the order presented in the assignment.
  16. Other

  17. Check your spelling.
  18. main() always returns an int.
    1. Unless you are passing arguments on the command line, use int main(void)

See Also


http://www.csd.uwo.ca/~jamie/C/Mistakes/BGSUCS205.html
Version:
07 May 2002
Author:
J. Blustein <jamie@cs.dal.ca>

Valid XHTML 1.0!, Valid CSS!