challenges of moving a java team to scala

21
Challenges of moving a Java team to Scala João Cavalheiro [email protected]

Upload: joao-cavalheiro

Post on 18-Jul-2015

133 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Challenges of moving a java team to scala

Challenges of moving a Java team to Scala

João Cavalheiro [email protected]

Page 2: Challenges of moving a java team to scala

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.

Page 3: Challenges of moving a java team to scala

Outline

• Why move a Java team to Scala?

• The challenges

• The good things

Page 4: Challenges of moving a java team to scala

This is not about

• An introduction to Scala language.

• Convincing Java fans to move to Scala.

• Migrating Java code to Scala.

Page 5: Challenges of moving a java team 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…

Page 6: Challenges of moving a java team to scala

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.

Page 7: Challenges of moving a java team to scala

Scala features that sometimes scare Java

developersAnd how to deal with them

Page 8: Challenges of moving a java team to scala

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.

Page 9: Challenges of moving a java team to scala

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

Page 10: Challenges of moving a java team to scala

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.

Page 11: Challenges of moving a java team to scala

How to startOnce you have the right people aboard

Page 12: Challenges of moving a java team to scala

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.

Page 13: Challenges of moving a java team to scala

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.

Page 14: Challenges of moving a java team to scala

Scala ecosystem• Typesafe activator

• The play framework

• Lots of online documentation:

• http://www.scala-lang.org/

• Stack overflow

Page 15: Challenges of moving a java team to scala

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.

Page 16: Challenges of moving a java team to scala

Things we loved about Scala since the first day

And that made things easier

Page 17: Challenges of moving a java team to scala

REPL!

!

!

• REPL is an interactive Scala command line interpreter.

• Awesome for doing experiments!

Page 18: Challenges of moving a java team to scala

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!

Page 19: Challenges of moving a java team to scala

Class constructors!

!

!

!

Page 20: Challenges of moving a java team to scala

Pattern matching!

!

!

!

Page 21: Challenges of moving a java team to scala

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.