Date post: | 10-May-2015 |
Category: |
Technology |
Upload: | tomer-gabel |
View: | 2,283 times |
Download: | 1 times |
Scala Best Practices
Tomer Gabel @ DevCon³February 2013
• Scala is awesome
• But it’s new
• … and misunderstood
DO’S AND DON’TSWe’re gonna focus on…
Don’t
… overuse tuples
Do
… name intermediate steps
Also
… did you know you can do this?
Don’t
… use null
Do
… use Option!
Don’t
… overload operators
What the hell does this mean?
s(7) <*> (s(8) <*> (s(9) ∘ add3))
Don’t
… abuse implicit parameters
def lookup( id: Int )( implicit jdbcUrl: String )
• Danger, Will Robinson!
• Primitives may be reused elsewhere
• Wrong semantics
Don’t
… abuse implicit methods, either
implicit def stringToInt( x: String ) = x.toInt
Implicit conversion considered harmful• Performance• Ambiguity• Code locality
Don’t
• Namespace pollution• Slow compilation• Unintended implicits
… over-import
import package1._import package2._import package3._
Do
… study the collection framework
• It’s a layer cake!
• Always qualify mutability–Aim for immutability–But have no fear
• Many gems!
Don’t
… abuse the type system
• Path-dependent types
• Visibility modifiers (e.g. package-private)
• Case class inheritance–Not allowed in 2.10
Our time is almost up!
Questions?