How to maximize your program grade in CSC270
Your program will be graded on two factors: correctness and programming style.
Program correctness
Your program will be automatically compiled and run against test data sets.
There are several important points.
How do I test my code?
Good testing of code is a learned skill. Generally, you need to look at your
code and think of what types of data may cause it to fail and then test your
program on that data. Generally, there are four types on inputs you must
test.
-
Legal values: Does your code correctly handle the types of values you expect?
-
Illegal values: Does you code correctly deal with incorrect values?
-
Boundary values: Consider the values which are legal, but close to illegal.
Does your code correctly handle these?
- Special cases: If you have cases in your program to deal with special
values, you must test each of these values.
Program style
The programming style of your code will count significantly to your grade.
Simply getting your program to run correctly is not enough. Your code must
also be simple, easy to read, and easy to understand. A short elegant solution
will receive a higher grade than a long, convoluted solution.
Please follow the style guidelines. Some key
points are as follows.
- Comment your code.
No comments will yield a significant loss of points,
but avoid too many comments that clutter your code. Good commenting is a
skill that you learn with practice.
- Use procedures.
Break up large programs into small procedures. The procedures
should encapsulate individual operations of your program.
For example, if you need to compute the factorial of a number, create
a separate function for that operation.
- Use descriptive names.
If you have a procedure that computes the factorial of a number, call it
factorial not helper_proc. The same goes for
variables, with the exception of loop counters whose meaning
is obvious from context.
- No magic numbers.
- Organize your programs as follows:
- #includes
- #defines
- type definitions (enum, struct, typedef)
- global variables
- function prototypes
- main()
- definitions for all other functions
If your program is comprised of more than one .c
file, then each .c file should have a corresponding
.h file in which you put the type definitions and
function prototypes for types and functions that will be
referenced by other .c files. Types and functions
that are used only by a single .c file don't need to
go into a .h file.
- Always indent your code. There are various common
indentation styles specifying how many spaces to indent and where to
put your braces. We don't care which style you use as long as you
pick one and use it consistently.
Tristan
Miller
Last modified: Wed May 15 01:06:37 EDT 2002