With Java 8 adoption skyrocketing, is Scala still relevant? In the opinion of this session’s speaker, the answer is an unequivocal yes. To make his point, he showcases practical examples where Scala's features provide a definitive advantage over Java 8. The session covers
• Effective logging with traits and by-name parameters
• Day to Day Type inference
• Pattern matching for fun and profit
• Type-safe easy generic Class<t> passing
• Concise third party enhancement
Hopefully you’ll leave the session with a better idea of the advantages Scala offers and perhaps a fresh outlook on software design.
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Java 8 and beyond, a scala story
1. Java 8 and Beyond,
a Scala Story
Ittai Zeidman, September 2016
http://searchengineland.com/figz/wp-content/seloads/2015/06/evolution-seo-marketer-ss-1920.jpg
2. Ittai Zeidman
• @ittaiz
• Backend Engineering Lead @
Wix
• Clean Code Fanatic
• Scala lover
• Proud spouse and father of 3
3. Ittai Zeidman
• @ittaiz
• Backend Engineering Lead @
Wix
• Clean Code Fanatic
• Scala lover
• Proud spouse and father of 3
6. Preface
• Java 8 was released
in 2014
• Which begs the
question…
• Is Scala still relevant?
7. Preface
• Java 8 was released
in 2014
• Which begs the
question…
• Is Scala still relevant?
– Yes.
8. Preface
• Java 8 was released
in 2014
• Which begs the
question…
• Is Scala still relevant?
– Yes.
9. Preface
• Java 8 was released
in 2014
• Which begs the
question…
• Is Scala still relevant?
– Yes.
– This talk is about
convincing you!
10. Quick Agenda
• A bit of history
– The Java-Scala gap
– How Java 8 reduces it
– Remaining gaps
• A deeper dive into:
– Traits
– Type Inference
– Pattern matching
– Implicits
11. The Java-Scala gap (pre Java
8)Scala’s big selling
points:
• Lambdas
• Collections library
• Traits
• Type inference
• DSLs
• Implicits
31. And Lazy Evaluation?
• Can be implemented with a lambda:
import java.util.function.Supplier;
default void logDebug(Supplier<String> message) {
if (getLogger().isDebugEnabled())
getLogger().debug(message.get());
}
32. And Lazy Evaluation?
• Can be implemented with a lambda:
import java.util.function.Supplier;
default void logDebug(Supplier<String> message) {
if (getLogger().isDebugEnabled())
getLogger().debug(message.get());
}
• But there’s boilerplate at the call site:
logDebug(() -> "Normalizing " +
person.toString());
33. Scala Traits
trait Logging {
private val logger =
LoggerFactory.getLogger(getClass)
protected def logWarn(msg: => String) =
if (logger.isWarnEnabled)
logger.warn(msg)
protected def logDebug(msg: => String) =
if (logger.isDebugEnabled)
logger.debug(msg)
}
41. Type Inference
• …the analysis of a program to infer the
types of some or all expressions, usually
at compile time…
42. Type Inference
• …the analysis of a program to infer the
types of some or all expressions, usually
at compile time…
• A balance between Compile Time Safety
and Verbosity
53. Java’s Switch Statement
• Switch statement is incredibly limited
– Only supports primitives (and strings)
– No arbitrary expressions (e.g. guards)
– No result values
54. Java’s Switch Statement
• Switch statement is incredibly limited
– Only supports primitives (and strings)
– No arbitrary expressions (e.g. guards)
– No result values
• Workarounds are ugly
– Nested control structures
– Encoding enums instead of using types
64. Passing Class info (generics)
• Java’s idiom is passing Class<T> clazz
around
65. Passing Class info (generics)
• Java’s idiom is passing Class<T> clazz
around
• Scala supports implicit parameters
– These are filled in by the compiler
– Well-defined rules for implicit search