Download - Challenges of moving a java team to scala
Challenges of moving a Java team to Scala
João Cavalheiro [email protected]
About me
• 10 years professional experience as a developer in multiple languages (from C to Java).
• Working at E.near, as a Systems Architect and managing 3 Scala development teams.
Outline
• Why move a Java team to Scala?
• The challenges
• The good things
This is not about
• An introduction to Scala language.
• Convincing Java fans to move to Scala.
• Migrating Java code to Scala.
The motivation• A customer asked us to take control of a big
Scala project (+200k lines of code), already in production at the time.
• Time was short.
• We said we would do it!
• We needed the right team and a plan…
The right team• Not every Java developer can be “converted” to
Scala.
• Although professional Scala experience is not required, functional programming concepts are a “must have”.
• Team members must embrace Scala - happy engineers are essential.
Scala features that sometimes scare Java
developersAnd how to deal with them
Infix and Postfix operations
• object.operation(k) can be written as “object operation k”
• object.operation can be written as “object operation”.
• Try not to mix them with traditional object-oriented programming language syntax.
High order functions
• These are functions that take other functions as parameters, or whose result is a function.
• def hof(f: Int => String, v: Int) = f(v)
• Use them whenever it makes sense (and once you feel comfortable with the concept).
Implicit conversions
• Given the declaration “implicit convert(a:A):B”.
• “convert” will be called behind the scenes whenever you have an “A” and need a “B”.
• Don’t use it before you understand the consequences.
How to startOnce you have the right people aboard
First steps
• Start by writing tests.
• Don’t feel guilty for using OO design in your first days in Scala.
• You don't have to understand all the possibilities when starting.
Build tools• You can use Maven, but…
• SBT basics are easy to learn.
• Although not as mature as Maven, works better with Scala.
• SBT supports incremental compilation out of the box.
Scala ecosystem• Typesafe activator
• The play framework
• Lots of online documentation:
• http://www.scala-lang.org/
• Stack overflow
Express yourself
• Simply express your intent.
• Write readable code. Shorter code is not always a best option.
• There are lots of toys, try to use only the right ones.
Things we loved about Scala since the first day
And that made things easier
REPL!
!
!
• REPL is an interactive Scala command line interpreter.
• Awesome for doing experiments!
Tools, libs & runtime environment
• Compiled Scala is like compiled Java - Bytecode that runs on JVM.
• We can use all our favourite Java libs.
• We can use our favourite IDE (Scala / IntelliJ), and the debugger works!
Class constructors!
!
!
!
Pattern matching!
!
!
!
Conclusions• Myth: We don’t need frameworks.
• Myth: Java sucks, and Java coders aren’t as smart as us.
• More concise code.
• Less time coding.
• Less bugs, if you do it right.