One of the goals of this course is to show you how to break up a program into short functions. To that end, every function must have no more than 16 noncomment lines, where a noncomment line is defined to be any line that has at least 2 noncomment, non-white-space characters.
Do not violate other requirements in other to reduce the number of lines in a function. For example, do not put more than one assignment statement on a line, as in
x++; y++;
Each function that returns a value (that is, its return-type is not void) must always return a value, unless it aborts the program.
The parameters that we have seen so far are call-by-value parameters. A function body not change the value of any call-by-value parameter. For example, do not write
int f(int n) { … n++; … }
You do not need to store a value into a variable in order to return it. Do not do that without any justification. Instead of
int result = g(y); return result;write
return g(y);Instead of
return result = g(y);write
return g(y);
Do not call a function with the same parameters more than once in the body of a function when
C++ supports default parameters. We will not talk about them and you must not use them.
C++ supports more things than we will use. We will not talk about instance methods (methods that belong to a class) or static functions. Do not use them.
C++ allows gotos, which cause a function to jump to a labeled line. We will not talk about them and you must not use them.
C++ supports exception handling (try blocks). We will not talk about exception handling and you must not use it.
See the standards for more details.