Skip to content

Latest commit

 

History

History
108 lines (94 loc) · 1.78 KB

STYLE-GUIDE.md

File metadata and controls

108 lines (94 loc) · 1.78 KB

Style Guide

Core Principles

  1. Use C-style Braces
  • Always use braces for control structures, even for single-line blocks
  • Opening brace on the same line
  • Closing brace on its own line
// Good
if (condition) {
  doSomething()
} else {
  doSomethingElse()
}

// Bad - No braces
if (condition)
  doSomething()

// Bad - Indentation-based syntax
if (condition)
  doSomething()
  andThenThis()  // Unclear scope
  1. No Indentation-Based Syntax
  • Do not rely on indentation for scope
  • Always use explicit braces to define scope
// Good
def method() = {
  val result = {
    val x = compute()
    transform(x)
  }
  result
}

// Bad - Indentation-based
def method() =
  val result =
    val x = compute()
    transform(x)
  result
  1. Function Definitions
  • Opening brace on the same line as the function definition
  • Use explicit return types
// Good
def process(input: String): Result = {
  // implementation
}

// Bad
def process(input: String): Result = 
  // implementation
  1. Pattern Matching
  • Use braces for case blocks
  • Align case statements
// Good
expr match {
  case Literal(value) => {
    process(value)
  }
  case Identifier(name) => {
    lookup(name)
  }
}

// Bad
expr match
  case Literal(value) =>
    process(value)
  case Identifier(name) =>
    lookup(name)
  1. For Comprehensions
  • Use braces instead of indentation
// Good
for {
  x <- xs
  y <- ys
} yield {
  combine(x, y)
}

// Bad
for
  x <- xs
  y <- ys
yield combine(x, y)

Additional Guidelines

  • Use parentheses for method calls even when they could be omitted
  • Prefer multi-line formatting with braces for complex expressions
  • Use explicit type annotations for public APIs
  • Keep line length reasonable (max 120 characters)
  • Use two-space indentation within braces