Theses guidelines are a consensus among the dev team and should be followed as much as possible.
They can be modified at any time by anyone but the modification PR should be approved by the whole dev team.
There is two kind of rules:
- the [MUST] rules should not be transgressed. If some exceptions are needed, they should be specified in the rule (and accepted by the whole team)
- the [PREFER] rules are a strong recommendation but can be transgressed if needed. A comment should explain why we need to ignore the rule.
Rules in bold are the most important ones.
- Language
- [MUST] Never throw an exception
- [MUST] Never use
null
- [MUST] Never use
return
- [MUST] Never return
Unit
- [PREFER] Do not abuse of primitive types
- [PREFER] Do not abuse of little typed types
- [PREFER] Use types to define constraints
- [MUST] Use
final
forcase class
es - [PREFER] Use value classes when possible
- [PREFER] Do not use
lazy
- [MUST] Do not pattern match on
Throwable
, useNonFatal(e)
- [PREFER] Do not use default parameters
- Functional programming
- [PREFER] Use pure functions as much as possible
- [PREFER] By default, use immutable values
- Architecture
- [PREFER] Split technical and business code
- [PREFER] Write a wrapper for lib that do not follow theses guidelines to adapt them
- [MUST] Avoid using mutable shared state
- [PREFER] Do not rely on temporal coupling
- [MUST] Do not build an invalid object
- Syntax
- [MUST] Always write type for public methods and attributes
- [PREFER] Write type for private methods and attributes
- [PREFER] Functions should be less than 25 lines
- [MUST]
object
attributes should start with a lower case letter to avoid conflicts with types
Open a PR with your rule and let's discuss.
To adopt a rule, the PR should be approved by every team member.
They are here just as a source of inspiration, they are not included in our guidelines
- Alexandru Nedelcu best practices
- Nicolas Rinaudo best practices
- Li Haoyi's Strategic Scala Style: Principle of Least Power Conciseness & Names Practical Type Safety Designing Datatypes
- Jakub Kozłowski talk: 7* sins of a Scala beginner (vidéo)
- Nicolas Rinaudo talk: Scala Best Practices I Wish Someone'd Told Me About (vidéo)
- Knoldus best practices
- Databricks best practices
- PayPal best practices
- Twitter best practices
- Why are Default Parameter Values Considered Bad in Scala?