Scala Best PracticesTomer Gabel @ DevCon³    February 2013
• Scala is awesome• But it’s new• … and  misunderstood
We’re gonna focus on…   DO’S AND DON’TS
Don’t
… overuse tuples
Do
Also
… did you know you can do this?
Don’t
… use null
Do
… use Option!
Don’t
… overload operatorsWhat the hell does this mean? s(7) <*> (s(8) <*> (s(9) ∘ add3))
Don’t
… abuse implicit parametersdef lookup( id: Int )( implicit jdbcUrl: String )  • Danger, Will Robinson!  • Primitives may b...
Don’t
… abuse implicit methods, eitherimplicit def stringToInt( x: String ) = x.toInt Implicit conversion considered harmful   •...
Don’t
… over-importimport package1._import package2._import package3._   • Namespace pollution   • Slow compilation   • Unintend...
Do
… study the collection framework• It’s a layer cake!• Always qualify mutability  – Aim for immutability  – But have no fea...
Don’t
… abuse the type system• Path-dependent types• Visibility modifiers (e.g. package-  private)• Case class inheritance  – No...
Our time isalmost up!Questions?
Thank you forlistening!Get in touch:• http://tomergabel.com• tomer@tomergabel.com• @tomerg
DevCon³: Scala Best Practices
Upcoming SlideShare
Loading in …5
×

DevCon³: Scala Best Practices

3,522 views

Published on

A 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.

Published in: Technology
0 Comments
12 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,522
On SlideShare
0
From Embeds
0
Number of Embeds
80
Actions
Shares
0
Downloads
44
Comments
0
Likes
12
Embeds 0
No embeds

No notes for slide
  • Image source: http://christhopper.deviantart.com/art/Good-Idea-Bad-Idea-148004159
  • Image source: http://www.chwyrvtmns.com/2010/12/if-you-dont-know-now-you-know/ (no license specified)
  • Image sources:http://www.clker.com/clipart-red-x-icon.html (public domain)http://sims.wikia.com/wiki/File:Icon_yes_check_v.svg (public domain)
  • Sample code taken from thescalaz Applicative example: http://scalaz.github.com/scalaz/scalaz-2.9.1-6.0.2/doc.sxr/scalaz/example/ExampleApplicative.scala.html
  • Image source: http://pumpercake.com/2011/04/22/seven-layer-cake/ (license unknown)Such “gems”: IterableLike.sliding, TraversableLike.groupBy, a Map is also a function!
  • DevCon³: Scala Best Practices

    1. 1. Scala Best PracticesTomer Gabel @ DevCon³ February 2013
    2. 2. • Scala is awesome• But it’s new• … and misunderstood
    3. 3. We’re gonna focus on… DO’S AND DON’TS
    4. 4. Don’t
    5. 5. … overuse tuples
    6. 6. Do
    7. 7. Also
    8. 8. … did you know you can do this?
    9. 9. Don’t
    10. 10. … use null
    11. 11. Do
    12. 12. … use Option!
    13. 13. Don’t
    14. 14. … overload operatorsWhat the hell does this mean? s(7) <*> (s(8) <*> (s(9) ∘ add3))
    15. 15. Don’t
    16. 16. … abuse implicit parametersdef lookup( id: Int )( implicit jdbcUrl: String ) • Danger, Will Robinson! • Primitives may be reused elsewhere • Wrong semantics
    17. 17. Don’t
    18. 18. … abuse implicit methods, eitherimplicit def stringToInt( x: String ) = x.toInt Implicit conversion considered harmful • Performance • Ambiguity • Code locality
    19. 19. Don’t
    20. 20. … over-importimport package1._import package2._import package3._ • Namespace pollution • Slow compilation • Unintended implicits
    21. 21. Do
    22. 22. … study the collection framework• It’s a layer cake!• Always qualify mutability – Aim for immutability – But have no fear• Many gems!
    23. 23. Don’t
    24. 24. … abuse the type system• Path-dependent types• Visibility modifiers (e.g. package- private)• Case class inheritance – Not allowed in 2.10
    25. 25. Our time isalmost up!Questions?
    26. 26. Thank you forlistening!Get in touch:• http://tomergabel.com• tomer@tomergabel.com• @tomerg

    ×