Anonymous Code Blocks [Edit]
- Use parenthesis for pure anonymous functions with placeholder syntax (underscore)
- Use braces for side-effecting anonymous functions with placeholder syntax (underscore)
- Use braces and new indented code block for longer anonymous functions
Use parenthesis for pure anonymous functions with placeholder syntax (underscore)
// preferred
val cubes = _localCubes.values flatMap (_.values)
// hmmm-kay
val cubes = _localCubes.values flatMap { _.values }
Use braces for side-effecting anonymous functions with placeholder syntax (underscore)
// good
nodes.valuesIterator foreach { _.delete() }
This produces clearer grouping and delimiter-balance than consecutive parenthesis.
// wrong
nodes.valuesIterator foreach (_.delete())
Use braces and new indented code block for longer anonymous functions
// right
val remotePartitions = latest.partitions map { p =>
val partition = Json.parse(p.partition)
val pv = new PartitionVersion(new Partition(dims, partition), p.version)
new RemotePartition(cube.database, cube.cube, pv, path(cubeURL, pv.partitionPath))
}