Some of our coding style rules are enforced programmatically by Scalafmt, which are run automatically with static checks and on every Pull Request (PR), but there are some rules that are not yet automated and are more sbt specific.
General style
-------------
### Naming
- Use short names for small scopes, for example `xs` and `x`.
- Prefer the use `Either` rather than `Exception`.
- Prefer scala.util.Using over try-finally.
```scala
importscala.util.Using
privatedefwithLog[A1](f:Capture=>A1):A1=
Using.resource(newCapture):log=>
f(log)
```
- Prefer functional constructs such as `.map` and `.foldLeft`, instead of a while loop.
### Scala data types
- Prefer Scala collection library over Java data structures. For example prefer `scala.collection.concurrent.TrieMap` over `java.util.concurrent.ConcurrentHashMap`.
- Use `end` marker for a class, trait, and object definition, regardless of the length of the template.
```scala
// BAD
objectO1{
deffoo:Int=1
}
// GOOD
objectO1:
deffoo:Int=1
endO1
```
### Infix notation
- Avoid the infix notation for non-symbolic methods `a foo 1`, and use the method call notation `a.foo(1)` instead.
### Comments
- Use ScalaDoc to provide API documentation. In general, however, document the intent and background behind the code, rather than transcribing code to English.