DevCon³: Scala Best Practices

Tomer Gabel
Tomer GabelConsulting Engineer at Substrate Software Services
Scala Best Practices

Tomer 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
DevCon³: Scala Best Practices
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
… over-import
import package1._
import package2._
import package3._

   • Namespace pollution
   • Slow compilation
   • Unintended implicits
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
• tomer@tomergabel.com
• @tomerg
1 of 27

More Related Content

Similar to DevCon³: Scala Best Practices(20)

Scala in the WildScala in the Wild
Scala in the Wild
Tomer Gabel2.8K views
Can you TDD Rails?Can you TDD Rails?
Can you TDD Rails?
Andrzej Krzywda2.8K views
Clean code, Feb 2012Clean code, Feb 2012
Clean code, Feb 2012
cobyst1.3K views
Beginning Java for .NET developersBeginning Java for .NET developers
Beginning Java for .NET developers
Andrei Rinea18.4K views
Writing clean code with Java 9+Writing clean code with Java 9+
Writing clean code with Java 9+
Miro Cupak1.3K views
Moving from C++ to RubyMoving from C++ to Ruby
Moving from C++ to Ruby
Leslie Brown3.2K views
Ruby for C#-ers (ScanDevConf 2010)Ruby for C#-ers (ScanDevConf 2010)
Ruby for C#-ers (ScanDevConf 2010)
Thomas Lundström888 views
Writing Readable CodeWriting Readable Code
Writing Readable Code
eddiehaber1.7K views
Ruby Presentation - ArticleRuby Presentation - Article
Ruby Presentation - Article
Christopher Giroir263 views
Lua pitfallsLua pitfalls
Lua pitfalls
Dmitriy Kotelnikov613 views
Rails trapsRails traps
Rails traps
Reuven Lerner4.4K views
AllyourbaseAllyourbase
Allyourbase
Alex Scotti3.1K views

More from Tomer Gabel(20)

DevCon³: Scala Best Practices

Editor's Notes

  1. Image source: http://christhopper.deviantart.com/art/Good-Idea-Bad-Idea-148004159
  2. Image source: http://www.chwyrvtmns.com/2010/12/if-you-dont-know-now-you-know/ (no license specified)
  3. 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)
  4. 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
  5. 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!