1. Start Here
    1. Introduction
  2. Guidelines
    1. White Space
    2. Indentation
    3. Line Wrapping
    4. Methods & Side Effects
    5. Code Blocks
    6. Anonymous Code Blocks
    7. Dots versus Spaces
    8. Files
  3. Reference
    1. Scala
    2. Bizo
    3. Official Scala Style Guide
  4. Google Custom Search

White Space [Edit]

  1. Spaces over Tabs
  2. Trailing whitespace
  3. Spaces around arguments and operators

Spaces over Tabs

No tabs, ever.

If you need to clean up a codebase with tabs, you can type the following which converts all tab occurences to 2 spaces:

% find . -name "*.scala" | xargs sed -i 's/\t/  /'

Trailing whitespace

Try to leave no trailing whitespace behind.

If you need help cleaning a codebase, type the following which strips all trailing whitespace (spaces, tabs):

% find . -name "*.scala" | xargs sed -i 's/[ \t]*$//'

Spaces around arguments and operators

One space after commas

// wrong: missing space after comma
def foo(a:Any,b:Ref) = ...
// wrong: extra space before comma
def foo(a:Any ,b:Ref) = ...
// right
def foo(a: Any, b: Ref) = ...

One space after colon

// wrong: missing space after colon
def foo(a:Any,b:Ref) = ...
// wrong: extra space before colon
def foo(a:Any,b :Ref) = ...
// right
def foo(a: Any, b: Ref) = ...

Spaces around operators

// wrong: missing spaces around operator
val x = 1+1
// right
val x = 1 + 1

No spaces after parenthesis

// wrong
val threads = 10 + ( Runtime.getRuntime.availableProcessors * 4 )
// right
val threads = 10 + (Runtime.getRuntime.availableProcessors * 4)
// right
if (options.has("?") || options.has("h")) {
  parser.printHelpOn(System.out)
  System.exit(-1)
}