devcon³: scala best practices
Post on 10-May-2015
Embed Size (px)
DESCRIPTIONA lecture given at the DevCon TLV conference in February 2013 (http://devcon-february.events.co.il/presentations/771-scala-best-practices): Although Scala has been gaining tremendous traction over the last couple of years, it's still a relatively new language with few "common knowledge" best- and worst-practices. This lecture will attempt to distill working knowledge from 1.5 years of production Scala use, articles from around the web and other sources into a coherent set of recommendations for those considering Scala, as well as existing practitioners.
- 1.Scala Best PracticesTomer Gabel @ DevConFebruary 2013
2. Scala is awesome But its new andmisunderstood 3. Were gonna focus on DOS AND DONTS 4. Dont 5. overuse tuples 6. Do 7. Also 8. did you know you can do this? 9. Dont 10. use null 11. Do 12. use Option! 13. Dont 14. overload operatorsWhat the hell does this mean? s(7) (s(8) (s(9) add3)) 15. Dont 16. abuse implicit parametersdef lookup( id: Int )( implicit jdbcUrl: String ) Danger, Will Robinson! Primitives may be reused elsewhere Wrong semantics 17. Dont 18. abuse implicit methods, eitherimplicit def stringToInt( x: String ) = x.toInt Implicit conversion considered harmful Performance Ambiguity Code locality 19. Dont 20. over-importimport package1._import package2._import package3._ Namespace pollution Slow compilation Unintended implicits 21. Do 22. study the collection framework Its a layer cake! Always qualify mutability Aim for immutability But have no fear Many gems! 23. Dont 24. abuse the type system Path-dependent types Visibility modifiers (e.g. package-private) Case class inheritance Not allowed in 2.10 25. Our time isalmost up!Questions? 26. Thank you forlistening!Get in touch: http://tomergabel.com email@example.com @tomerg