(meaning their are my personal ones, not community ones)
I believe there is 3 very different groups in the Scala community:
- OOP puristes: coming from OOP languages and use Scala as a better OOP language
- FP minimalists: sold to FP but want to keep code
- FP purists:
Codes used in this guide:
- [MUST] is for rules that should be transgressed only in last resort and needs an explanation of why in comment next to it
- [PREFER] is for rules that should be followed in most cases but can be sometimes transgressed for more practical code
- Rules in bold are the important ones I consider you essential to any Scala code
- Preface
- [MUST] Do not take theses rules as is, you should understand and adapt them to your context
- General
- [PREFER] Code comments should explain WHY the code has been done this way, not HOW it does it
- [MUST] Names should be meaningful
- Language
- FP
- [MUST] Functions should be total
- [PREFER] Functions should be pure
- Architecture
- [MUST] Split technical and business code
- [MUST] Encode business rules in types as much as possible
- [MUST] Avoid building invalid objects
- [MUST] Avoid temporal coupling
- Performance
- [MUST] Performance should not be discussed without a benchmark highlighting the problem and the metrics that must be reached
- Play framework
- Syntax
- [PREFER] Functions should have less than 20 lines, less than 10 is better, more than 50 is not acceptable
- [PREFER] Lines should be less than 120 chars, more than 160 is not acceptable
- [PREFER] Indentation should use 2 spaces
- [PREFER] Each file should be terminated by an empty line
- scalafmt
- scalastyle
- wartRemover
- 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
Open a PR or an Issue and let's discuss