DevCon³: Scala Best Practices
-
Upload
tomer-gabel -
Category
Technology
-
view
2.284 -
download
1
description
Transcript of DevCon³: Scala Best Practices
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?
Thank you for listening!
Get in touch:• http://tomergabel.com• [email protected]• @tomerg