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

Code Blocks [Edit]

    Opening curly braces ({) should be on the same line

    … as the declaration they represent.

      // right
      def foo = {
        ...
      }
    

    Use braces and indented code block with if, while and for.

      // wrong
      if (condition) log.info("something interesting happened")
    
      // wrong
      if (condition)
        log.info("something interesting happened")
    
      // wrong
      if (condition)
        log.info("something interesting happened")
      else
        log.info("nothing happened, really")
    
      // right
      if (condition) {
        log.info("something interesting happened")
      }
    
      // right
      if (condition) {
        log.info("something interesting happened")
      } else {
        log.info("nothing happened, really")
      }
    

    One notable exception to this rule is when an if is used as substitute for the ternary operator (?) — which is not available in Scala — and when the entire expression fits in a single line,

      // right
      val level = if (state == "dev") debugLevel else warnLevel