WHITE SPACE

[Contents] [Prev] [Next]


8 - White Space

8.1 Blank Lines

One blank line should always be used in the following circumstances:

  • Between class and interface definitions
  • Between methods

Avoid using unnecessary blank lines.

8.2 Blank Spaces

Blank spaces should be used in the following circumstances:

  • A keyword followed by a parenthesis should be separated by a space. Example:
while (true) 
{
  ...
}

    Note that a blank space should not be used between a method name and its opening parenthesis. This helps to distinguish keywords from method calls.

  • A blank space should appear after commas in argument lists.
  • Don't separate binary operators with spaces. Blank spaces should never separate unary operators such as unary minus, increment ("++"), and decrement ("--") from their operands. 
  • Space should separate assignment operators
  • Example:
    a += c+d;
    a = (a+b)/(c*d);
    while (d=s) 
    {
      n++;
      d++;
      s++;
    }
    printSize("size is "+foo+"\n");

  • The expressions in a for statement should be separated by blank spaces. Example:
    for (int i=1; i<count; i++)

  • Casts should not be followed by a blank space. Examples:
    myMethod((byte)aNum,(Object)x);
    myMethod((int)(cp+5),((int)(i+3))+1);
    Address value = (Address)address_list.get(i);

[Contents] [Prev] [Next]