Common Mistakes & Marking Codes
This is a list of mistakes commonly seen in undergraduate computer
science programming assignments. It is based on a list of marking codes by
an anonymous author. I've changed some of the wording and added some more
explanation to some of the points. There are separate sections of problems
specific to C programs and Pascal programs.
A revised version that was used at Bowling Green State U. is also
available in PostScript, and PDF formats. I've also got an XHTML version but it doesn't look right on today's browsers.
- Use meaningful variable and subprogram names.
- In C subprograms are all functions. In Pascal procedures and
functions are subprograms.
- Comment on what your variables represent.
- Comment briefly on what your program does.
Also comment what each subprogram does.
- Comment the `logical sections' of your code. Be brief but precise.
Do not just restate what the source code says.
- Indent consistently for readability.
Seperate sections of your program with blank lines.
- Do not unnecessarily repeat code in a program.
Implement repeated tasks as subprograms or loops.
- Use modularity: the main routine should mainly just call the
procedures that are the sub-modules of the program.
- 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.
- Do not use unnecessary parameters.
- Use parameters instead of global variables to pass information to
and from subprograms.
- We will never give you an assignment where global variables are
appropriate.
- Use the appropriate loop structure (e.g. post-test instead of pre-test).
- In C the loops types are:
while
(pre-test), do
... while
(post-test), and for
(counted
pre-test).
Pascal loops have the same names as C loops except that the
post-test loop is repeat ... until
.
- Do not include unnecessary code.
- Check your spelling.
- Use appropriate conditional structures.
- Avoid `magic numbers'.
Use meaningfully named constants.
- In Pascal use
const
.
In C use #define
or typedef
(but note that
typedef
is only for int
s).
Note: Comments specific to Pascal programs are below.
- If you use the gcc compiler then be sure that it is
running as a standard C compiler and not a GNU C compiler.
- gcc -ansi -pedantic makes it run as a standard C compiler
- gcc -ansi -pedantic -Wall -O makes it run as a standard
C compiler and check for several types of errors
I recommend using a shell alias (e.g. `alias c89 gcc -ansi
-pedantic -Wall -O' for csh) or a Makefile with gcc so that you
always have it running the way you want.
//
is not (yet) a valid C comment.
- You should never use
gets()
.
- Learn to use
fgets()
instead.
- Include appropriate library headers.
You don't have to cast calls to
malloc()
.
main()
must return an int
.
- Declare proper prototypes for your functions.
foo();
is not a proper prototype.
Prototypes should declare a function's parameters and type.
- Use the appropriate kindof subprogram: a function if only one value
is to be returned, a procedure otherwise.
http://www.csd.uwo.ca/~jamie/C/Mistakes/mistakes.html
About this document
- Owner
- J. Blustein
- Created
- 23 Feb 1998 by J. Blustein
- Last updated
- 12 October 2000 by J. Blustein