We'll visit some of the mistakes or issues that we can encounter while working with scala, and how we can solve them. We'll also go through some of the common and preferred practices in Scala.
2. Lack of etiquette and manners is a huge turn off.
KnolX Etiquettes
Punctuality
Respect Knolx session timings, you
are requested not to join sessions
after a 5 minutes threshold post
the session start time.
Feedback
Make sure to submit a constructive
feedback for all sessions as it is
very helpful for the presenter.
Silent Mode
Keep your mobile devices in silent
mode, feel free to move out of
session in case you need to attend
an urgent call.
Avoid Disturbance
Avoid unwanted chit chat during
the session.
11. Arrays
Solution: Here we can use sameElements method to compare values of an
Array
In Scala 2.13 we have ArraySeq which solves this problem for immutable
Array
17. String Concatenation
● Use String interpolation
● Call toString explicitly
Note: String concatenation has been deprecated in Scala 2.13
18. Exceptions
● MUST NOT throw exceptions for validations of user input or flow control
Instead Use:
○ Option
○ Either
○ Try
● MUST NOT catch Throwable when catching Exceptions
20. Say No to Return
return statement signal side effects as it alters the flow of the method.
It leads to multiple exit points which is anti-structural programming
For eg:
21. MUST NOT use magic values
Problem: Intent of solution is not clear, could lead to unnecessary issues.
Solution: Use : Option, Either, Try or create your own ADT’s.
23. Type Annotation
Change in Implementation:
Problem: This could lead to incompatibility
Solution: Provide explicit type annotation for public methods
24. Common Practices
● Do not use null
● Never use Option.get
● Give meaningful names
● Should break long functions
● Set Maximum Line length: prefered 120