No global or static variables [GLOBAL-VARIABLE: 5-25 pts] [STATIC-VARIABLE: 5-25]
| 
              
              These notes have very little to say about global and static variables.
              A global variable is one that is not created inside a function.  A
              static variable is created inside a function, but marked static.
              
               Do not use global or static variables, with a single exception. You may use a global variable that is used only for debugging. For example, a variable that acts as a switch to turn on or off debugging is normally global. Global constants are allowed.  | 
          
Do not change the same variable twice in one statement [DOUBLE-CHANGE: 1-2 points]
              
              Do not write a statement that includes two explicit changes
              of a variable.  For example, statement
x = x++;tries to change x twice. (This kind of thing has undefined behavior in C++.)  | 
          
| 
              
              Do not use any variable before you have put a value in it.
              
               Always ask the compiler to warn you about this. I suggest explicitly adding g++ option -Wunitialized.  | 
          
Do not make a change that will surely not be seen [INVISIBLE-CHANGE: 1 point]
              
              Do not use ++x where you really mean x+1.  Do not
              change the value of a local variable when the changed value
              cannot possibly be looked at again.  For example,  do
              not write
return test(++x);since the altered value of x cannot possibly be looked at. Instead, write return test(x+1);  | 
          
Do not store a value into a local variable just to return it [RETURN-VARIABLE: 1 pt]
              
              If y is a local variable, do not write
return y = x + 1;which stores the value of x + 1 into variable y, and then immediately returns that value. There is no point to variable y. Just write return x + 1;  | 
          
Avoid duplicate variables without justification [DUP-VARIABLE: 1-2 points]
              
              Look at the following function definition.
  int f(int x)
  {
    int m = x;
    return m + x + 1;
  }
              Variable m is just another name for x.
              It is never changed.  There
              is no reason to have two names for the same thing, and
              it only confuses things.  A better definition is
  int f(int x)
  {
    return x + x + 1;
  }
              There are some cases where having another variable is sensible.
              
  | 
          
| 
              
              Do not create a variable in a
              place where another variable or constant of
              the same name exists.  See
              shadowing.
              Option -Wshadow of g++ asks the compiler to
              warn you if you are shadowing something.
              
               Do not create a variable whose name is the same as a function's name. Do not create a variable whose name is the same as the name of the function that it is in. For example, function sum should not have a variable called sum.  | 
          
Do not change the value of a call-by-value parameter [CHANGE-CBV-PARAM: 1-5 points]
              
              If a function parameter is passed by value, then do not
              change the value of that parameter anywhere in the function
              body.  For example, function next defined by
  int next(int n)
  {
    while(!isgood(n))
    {
      n++;
    }
    return n;
  }
              takes parameter n by value.  It changes the value of n
              in the function body.  Do not do that.
              
             |