Dots vs Spaces [Edit]
- Use spaces when passing blocks delimited with curly braces
- Use dots for side-effecting methods
- Use dots for consecutive accessors
- Use spaces to separate pure operations
- When in doubt, try to reduce the line noise
Use spaces when passing blocks delimited with curly braces
// good
missiles foreach { missile => missile.fire() }
// not on this planet!
missiles.foreach { missile => missile.fire() }
Use dots for side-effecting methods
// don't even think about it!
missiles fire()
Use dots for consecutive accessors
// good
for (c <- competitors.view.reverse) {
allocate(c)
}
// nope.
for (c <- competitors.view reverse) {
allocate(c)
}
// what did I tell you about spaces?
for (c <- competitors view reverse) {
allocate(c)
}
Use spaces to separate pure operations
// good
val evenlyDistributed = pref.selectors zip distribute(pref.quantity, avails)
// good
log.info("Distribution: " + (values mkString "\n"))
// good
selectors map getOrCreateNode map { _.available(priority) }
// wrong: get is an accessor, not an operation
customers get selectedId
// wrong: available is an accessor
// (an operation is verb, not an adjective)
customers available today
When in doubt, try to reduce the line noise
// mmm-kay
overflow -= (exclude map { _.available(priority) } sum)
// better: slightly less noisy since dots are less noisy than parenthesis
overflow -= exclude.map { _.available(priority) }.sum