Standards-11
Layout and Indentation


Major errors

Extremely poor indentation [up to 50%]

If your work is extremely poorly indented, as it would be if every line begins at the left margin, then you will lose 50%. Always indent well.

Indentation [4-6 points for each poorly indented line, 10% max]

Indent the contents of compound statements from 2 to 4 spaces. Choose a consistent indentation in that range. Follow this idea.
  if(condition)
  {
    statement
    ...
    statement
  }
  else
  {
    statement
    ...
    statement
  }
If you do not follow the component rule, you are still expected to indent the bodies of statements such as if-statements and while-statements. If you violate both rules, you will lose points for both.

Indent sequencing correctly

This is classified with indentation. Two statements that are performed one after another must be indented the same amount. For example,
  int x;
    int y;
is not correctly indented. Similarly,
  int badindentdemo(int n)
  {
    for(int i = 0; i < n; i++)
    {
      if(test(i))
      {
         return i;
      }
    }
      return -1;
  }
is not correctly indented. Since statement return −1 is performed just after the for-loop (assuming that the return statement inside the for-loop is not done), it should be indented the same amount as the word for.

Braces [4 for each poorly aligned pair of braces, 4% max]

Each right brace should be directly above the matching left brace (in the same column), without any characters on or to the left of the line segment between the left and right braces. Here is an example.
  if(condition)
  {
    statement
    ...
    statement
  }
  else
  {
    statement
    ...
    statement
  }


Minor errors

Template [4 points per file that does not use the template, 4 points for missing name, 1 point for a missing part]

Use the template(s) given with each assignment for all source files. Replace the asterisks by appropriate text. Provide your name, the assignment number, the name of the file and the number of columns between tab stops that you have used.

Show tab stops, if used [2 points per file]

If you use tabs, you must say, in the heading at the top of the file, where the tab stops are. Just give one integer, the spacing between tab stops. For example,
  // tabs: 4
indicates that tab stops are 4 characters apart. (If you do not use tabs, you may write none for tab stops.)

Pay attention to this! If you specify the wrong spacing of tab stops, your program might look good to you but be very poorly indented when I look at it.

If you do not specify the distance between tab stops, your indentation will be graded based on a default of 8 characters between tab stops.


Do not use long lines [2 points per long line, 1% max]

Do not write lines longer than 80 characters. Break long lines.

Do not use a semicolon as an empty statement [5 points each, 2% max]

Do not write a bare semicolon anywhere as an empty statement. If you need an empty statement, write { }.

Do not write a bare semicolon in between definitions.


Do not write more than one statement on one line [6 points each, 3% max]

Instead of
  x = y+1; y = z;
write
  x = y+1;
  y = z;
You may use chained assignments, as in
  x = y = 0;

Write a contract before the function that it describes [4 points each, 2% max]

Write a contract for each function just before the function definition, without any intervening things unrelated to the function, except a blank line. If you choose to write contracts in a header file, write each contract just before the function prototype, with a blank line between them.

Blank lines [3-6 points each, 1% max]

  • Put a blank line between the end of one function and the contract for the next function.
  • Put a blank line between a function's contract and the function definition.
  • There should be a blank line before and after each type definition.
  • If a contract appears in a header file, put a blank line before and after it and a blank line after the function's prototype.
  • If a function body contains paragraph comments, put a blank line before and after such a comment.

No excessive blank lines [2-3 points each, 1% max]

  • Do not leave excessive blank lines in function bodies or between functions.
  • Do not double-space code.
  • Do not double-space header files that do not contain contracts.
  • Do put blank lines between major paragraphs of code.

If layout and chained ifs [3 points each, 1% max]

Align the 'e' in else with the 'i' in if, to make it easy to spot.

When several if-statements are used to simulate multiple cases, indent all of the cases the same amount, as in the following example.

  if(condition)
  {
    statements
  }
  else if(condition)
  {
    statements
  }
  else if(condition)
  {
    statements
  }
  else
  {
    statements
  }