Keunwoo Lee : CSE 142 : HW2 Notes

Tips/common mistakes:
  • #define every constant! Most of you missed at least a few. Recall the guideline: anything that's not 1 or 0 should be #defined, even things that don't aren't likely to change (e.g., number of minutes in an hour). Remember that named constants serve as documentation as well.
  • Function comments should describe at least every parameter and the return value:
        /* Evaluates a binomial function ax^2 + bx + c.
           RETURNS: Value obtained by evaluating the binomial.
           PARAMETERS:
               base : base variable
               co1  : square term coefficient
               co2  : linear coefficient
               co3  : constant term
         */
        double eval_binomial(double base,
                             double co1, double co2, double co3) {
            /* etc. */
        }
        
    Notice, by the way, that I don't have to name the types or order of the parameters in the comment, because that is provided by the function definition.
  • Please comment all constant and variable declarations. Even when the names are self-explanatory, it often helps to break your variable declarations into groups (and comment the groups), especially when there are many declarations in one function.
  • A few students didn't use prototypes, instead opting to define all their function bodies directly at the top of the program. It's much easier to grasp the flow of a program when you get main() near the beginning, and besides it's conventional C style. In the future, please use prototypes.

  • Keunwoo Lee
    Last modified: Wed Oct 27 14:53:18 PDT 1999