6C. Standards for Function Definitions

Here are some of the standards for functions. See the standards for a complete list.

To return the value of an expression, return that expression.

Instead of
  int x = 0;
  return x;
write
  return 0;
Instead of
  int length = sequenceLength(nextNum(n)) + 1;
  return length;
just write
  return sequenceLength(nextNum(n)) + 1;

Do not change a parameter that is passed by value [1-5 points]

A function must not change the value of a parameter that is passed to it by value.

No long function definitions [1-30 points]

Each function body must have no more than 15 noncomment lines.

A noncomment line is defined to be a line that has at least two noncomment, non-white-space characters. For example, a line that only contains a brace does not count as a noncomment line by this definition.

Do not violate other requirements in order to squash a long function definition down. Break the function up into smaller functions and document each function.