Common Mistakes & Marking Codes (BGSU edition)
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:
- Comment briefly on what your program does.
- Comment on what each function does.
- Comment the `logical sections' of your code. Be brief but
precise.
- Do not restate what the source code says but rather explain what
it is for.
- Comment on what your variables represent.
- Use meaningful variable and function names.
- Avoid `magic numbers'.
Use meaningfully named
const
variables instead.
- Indent consistently for readability.
- Seperate sections of your program with blank lines.
- Do not unnecessarily repeat code in a program.
Implement repeated tasks as functions or loops.
- Use modularity:
main()
should mostly just call the
functions that are the sub-modules of the program.
- Do not include unnecessary code.
Do not initialize unnecessarily — it's confusing.
- Use appropriate conditional structures
(e.g.,
if
or if
/else
or
switch
).
-
-
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.
-
Use a
for
loop only when you know how many times
you want to repeat the body of the loop.
-
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.)
- Use parameters instead of global variables to pass information
to (and from) functions.
- Do not use unnecessary parameters.
- Prompts to the user should be explicit, and helpful to the user.
- Format your output for readability.
- Submit all your output.
- Test runs should be executed in the order presented in the
assignment.
- Check your spelling.
main()
always returns an int
.
- Unless you are passing arguments on the command line, use
int main(void)
http://www.csd.uwo.ca/~jamie/C/Mistakes/BGSUCS205.html
- Version:
- 07 May 2002
- Author:
- J. Blustein <jamie@cs.dal.ca>
,