SlideShare ist ein Scribd-Unternehmen logo
1 von 70
Downloaden Sie, um offline zu lesen
7 years of Scala
and counting
Scala Days Vienna 2017
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
6 years of Scala
and counting
Scala Vienna User Group May 2016
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Agenda
1. Quick introduction to Scala
2. Learning Scala
3. Using Scala
4. Learnings, reflection, observations, impressions
5. Questions
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Manuel Bernhardt
• I help companies getting started
with using reactive applications in
their distributed systems
infrastructure
• http://manuel.bernhardt.io
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Manuel Bernhardt
• I help companies getting started
with using reactive applications in
their distributed systems
infrastructure
• http://manuel.bernhardt.io
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Scala: an introduction
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Scala introduction
• first version released in 2003
• Martin Oderksy, EPFL
• an estimated more than half a
million Scala developers 1
1
http://www.scala-lang.org/blog/2016/03/14/announcing-the-scala-
center.html
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Scala Center
• non-for-profit foundation for Scala
education and community
guidance
• established at EPFL
• founding members: IBM, verizon,
Goldman Sachs, nitro, Lightbend
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Favourite Feature tour
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
case classes
public class User {
private final String name;
private final String surname;
private final Integer age;
public User(String name, String surname, Integer age) {
this.name = name;
this.surname = surname;
this.age = age;
}
public String getName() {
return this.name;
}
public String getSurname() {
return this.surname;
}
public String getAge() {
return this.age;
}
@Override public int hashCode() {
// ...
}
@Override public boolean equals(Object that) {
// ...
}
}
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
case classes
case class User(name: String, surname: String, age: Int)
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
case classes
case class User(name: String, surname: String, age: Int)
val bob = User("Bob", "Marley", 42)
val namedBob = User(name = "Bob", surname = "Marley", age = 22)
val john = bob.copy(name = "John")
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
case class
• perfect example of the terseness Scala provides
• hashcode, equals, toString for free
• serializable by default
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
type inference
val foo = "Bar" // foo: String = Bar
val answer = 42 // answer: Int = 42
val price = 9.99 // price: Double = 9.99
val nums = List(1, 2, 3) // nums: List[Int] = List(1, 2, 3)
val map = Map("abc" -> List(1, 2, 3))
// map: scala.collection.immutable.Map[String,List[Int]] = Map(abc -> List(1, 2, 3))
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
functions and higher-order
functions
def isMajor(user: User): Boolean = user.age > 18
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
functions and higher-order
functions
def isMajor(user: User): Boolean = user.age > 18
class UserGroup {
def filter(predicate: User Boolean): List[User] = ...
}
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
functions and higher-order
functions
def isMajor(user: User): Boolean = user.age > 18
class UserGroup {
def filter(predicate: User Boolean): List[User] = ...
}
userGroup.filter(isMajor) // returns only majors
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Learning Scala
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
How "learnable" is
Scala?
• Shadaj Laddad
• http://shadaj.me
• learned Scala at age 11-12
• talks at Scala Days, OSCON since
2012
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
How "learnable" is
Scala?
• Coursera courses, 400.000+
participants - highest completation
rate in the industry (10%, which is
high for a MOOC 2
)
• Scala as beginner programming
language at Lund University of
Technology 3
3
https://www.lth.se/english/about-lth/news/news/article/scala-will-be-the-
beginner-programming-language-of/
2
Massive Open Online Course
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
My learning path
• 2010: started dabbling with Scala
(books, using it in tests, small
projects)
• 2011: discovering Functional
Programming through Javascript.
Using Play Framework 1 with the
Scala module in my 2nd
startup
• 2012: first large codebase to
migration from Play 1 to Play 2.0.0
(based entirely on Scala)
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
My learning path
• 2013: several client projects using Scala
• 2014-2016: architecture, prototyping, design,
implementation, review of various production systems with
Scala, Akka, Play Framework; writing Reactive Web
Applications
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
My learning path
• estimated 6 months to "click"
• imperative declarative
• mutable, global state immutable, expression-oriented
• longer to grasp or use more advanced concepts
• and how not to shoot myself in the foot with them
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Your learning path?
• new Coursera courses by the Scala Center
• https://scala.epfl.ch
• try to use Scala for something "real"
• and even if it is just tests in a real project
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Using Scala
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
6 years without one of those
pesky NullPointerException-s
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Significantly less
problems at
runtime
• Scala compiler spots a whole
plethora of problems at compile-
time
• leveraged by e.g. Play Framework,
high emphasis on "compiling
everything"
• URLs
• Javascript (Google Clojure
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Less code yields
higher maintainbility
(Less is more)
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
IDE / Editors
• IntelliJ IDEA
• Scala IDE for Eclipse
• ENSIME 5
• emacs, Atom, Sublime Text, vim
5
Enhanced Scala and java Interaction Mode for text Editors
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Compiler
• slower than the Java compiler
• but not a problem (anymore) on modern hardware
• especially with incremental compilation
• unless you deep dive into type-level and generic
programming (e.g. shapeless library)
• much more precise than the Java compiler (type-safe ++)
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Jobs & Developers
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
http://appliedscala.com/blog/2016/scala-popularity/
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
What I've learned
Reflection, Impressions, (Advice)
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
The Dreyfus model of skill
acquisition
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Learning #1
Spend a little time understanding
the language design
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Understand Scala's essence
and your life will be easier
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Learning #2
Understand the purpose of the
language features
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Scala has quite a few language features
because it was designed to be extensible
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Don't be that kid
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Scala language levels 4
• Level A1: Beginning application programmer
• Level A2: Intermediate application programmer
• Level A3: Expert application programmer
4
http://www.scala-lang.org/old/node/8610
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Scala language levels 4
• Level L1: Junior library designer
• Level L2: Senior library designer
• Level L3: Expert library designer
4
http://www.scala-lang.org/old/node/8610
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
The features you need to build
applications
are not the same
as the ones you need to build
librariesScala Vienna May 2016 - manuel.bernhardt.io - @elmanu
SIP 18: Modularizing language
features
import scala.language.implicitConversions
import scala.language.dynamics
import scala.language.postfixOps
import scala.language.reflectiveCalls
import scala.language.higherKinds
import scala.language.existentials
import scala.language.macros
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Incidental complexity
Is this really a problem
specific to Scala?
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
@SuppressWarnings({"unchecked", "rawtypes"})
@Deprecated
@OneToMany(@HowManyDBADoYouNeedToChangeALightBulb)
@OneToManyMore @AnyOne @AnyBody
@YouDoNotTalkAboutOneToMany // Fightclub, LOL
@TweakThisWithThat(
tweak = {
@TweakID(name = "id", preferredValue = 1839),
@TweakID(name = "test", preferredValue = 839),
@TweakID(name = "test.old", preferredValue = 34),
},
inCaseOf = {
@ConditionalXMLFiltering(run = 5),
}
)
@ManyToMany @Many @AnnotationsTotallyRock @DeclarativeProgrammingRules @NoMoreExplicitAlgorithms
@Fetch @FetchMany @FetchWithDiscriminator(name = "no_name")
@SeveralAndThenNothing @MaybeThisDoesSomething
@JoinTable(joinColumns = {
@JoinColumn(name = "customer_id", referencedColumnName = "id")
})
@DoesThisEvenMeanAnything @DoesAnyoneEvenReadThis
@PrefetchJoinWithDiscriminator @JustTrollingYouKnow @LOL
@IfJoiningAvoidHashJoins @ButUseHashJoinsWhenMoreThan(records = 1000)
@XmlDataTransformable @SpringPrefechAdapter
private Collection employees; // http://annotatiomania.com
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Learning #3
Don't forget all about Object
Oriented Programming
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
class SynchronizationService {
private[services] def synchronizeTeeTimes(
suite: Suite,
dataType: SuiteDataType,
eventuallyByteStream: Future[Enumerator[Array[Byte]]],
removeDocsWithOlderTimestamps: Boolean): Future[Int] = ...
private[services] def synchronizeTournaments(
suite: Suite,
dataType: SuiteDataType,
eventuallyByteStream: Future[Enumerator[Array[Byte]]],
removeDocsWithOlderTimestamps: Boolean): Future[Int] = ...
}
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
class SynchronizationService {
private def synchronizeGolf[T, S](suite: Suite,
dataType: SuiteDataType,
eventuallyByteStream: Future[Enumerator[Array[Byte]]],
toIndexDocuments: (Suite, Issuer, GolfClub) => Seq[T] => Iterable[S], // function!
indexDocuments: Iterable[S] => Future[Boolean], // function!
countDocuments: CountRequest => Future[Long], // function!
verify: (Int, Long) => Unit, // function!
removeDocsWithOlderTimestamps: Boolean)(implicit format: Format[T]): Future[Int] = ...
}
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Learning #4
Don't use every feature as a
hammer
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
for comprehension
val bobUser: Option[User] = ...
val carlUser: Option[User] = ...
val bobCarlAge: Option[Int] =
for {
bob <- bobUser
carl <- carlUser
} yield bob.age + carl.age
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
for comprehension from hell
for {
stopWatch <- Future.successful(startedStopWatch)
startTimestampOfSync = DateTime.now()
byteStream <- eventuallyByteStream
suiteDocStream = toDocumentStream[T](byteStream)
chunkedStream = suiteDocStream &> ExtraEnumeratees.chunker(ChunkSize)
indexerSuccessStream = chunkedStream &> indexer
indexerSuccess <- indexerSuccessStream.run(Iteratee.fold(true)(_ && _))
_ <- if (removedDocsWithOlderTimestamps)
waitForElasticSearchToFinishIndexing().map(_ => removeDocsUpsertedBefore(issuer, dataType, startTimestampOfSync))
else
Future.successful(())
count <- waitForElasticSearchToFinishIndexing().flatMap { _ =>
verifyCount(issuer, counter.get(), countDocuments, verify)
}
} yield {
if (!indexerSuccess) error(s"Failed to index $dataType for ${suite.url}")
val duration = scala.concurrent.duration.Duration(stopWatch.getNanoTime, TimeUnit.NANOSECONDS).toSeconds
info(s"Done synchronizing ${counter.get()} $dataType for ${suite.url}, it took $duration s")
count
}
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Learning #5
Transitioning to Scala
(for teams)
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Don't start a Scala project
with a team comprised
of novice and advanced beginners
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Don't start a <XYZ> project
with a team comprised
of novice and advanced beginners
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
It's all about people
The biggest challenges of transitioning to Scala — or anything new 
— are rarely technical. Talented programmers can learn a new
syntax, new concepts, and a new IDE. Rather, change often
brings out the weaknesses in other areas like process and
culture. 6
— Kevin Webber
6
https://medium.com/@kvnwbbr/transitioning-to-scala-d1818f25b2b7#.x1tcfcs58
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Building up Scala knowledge in
your team
• culture that emphasizes learning, create time for learning
• code reviews, discussions
• try to get one "Competent" on your team
• even if it's a "hired gun" helping to bootstrap & ensure
best practices (& avoiding pitfalls)
• invest in training (Fast track to Scala, etc.)
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Conclusion
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Conclusion
case class User(name: String, surname: String, age: Int)
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Conclusion
case class User(name: String, surname: String, age: Int)
embrace Scala's terseness
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Conclusion
case class User(name: String, surname: String, age: Int)
embrace Scala's terseness
don't forget about the language levels
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
Thank you!
Questions & Comments ?
• http://manuel.bernhardt.io
• @elmanu
Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu

Weitere ähnliche Inhalte

Andere mochten auch

Practical Aggregate Programming in Scala
Practical Aggregate Programming in ScalaPractical Aggregate Programming in Scala
Practical Aggregate Programming in Scala
Roberto Casadei
 

Andere mochten auch (13)

Scala Past, Present & Future
Scala Past, Present & FutureScala Past, Present & Future
Scala Past, Present & Future
 
Semana12 oct31 nov2
Semana12 oct31 nov2Semana12 oct31 nov2
Semana12 oct31 nov2
 
Web without framework
Web without frameworkWeb without framework
Web without framework
 
Java 8 and beyond, a scala story
Java 8 and beyond, a scala storyJava 8 and beyond, a scala story
Java 8 and beyond, a scala story
 
Practical Aggregate Programming in Scala
Practical Aggregate Programming in ScalaPractical Aggregate Programming in Scala
Practical Aggregate Programming in Scala
 
Scala in Practice
Scala in PracticeScala in Practice
Scala in Practice
 
Reactive Access to MongoDB from Scala
Reactive Access to MongoDB from ScalaReactive Access to MongoDB from Scala
Reactive Access to MongoDB from Scala
 
Brendan O'Bra Scala By the Schuykill
Brendan O'Bra Scala By the SchuykillBrendan O'Bra Scala By the Schuykill
Brendan O'Bra Scala By the Schuykill
 
Microservices in Java and Scala (sfscala)
Microservices in Java and Scala (sfscala)Microservices in Java and Scala (sfscala)
Microservices in Java and Scala (sfscala)
 
Fun[ctional] spark with scala
Fun[ctional] spark with scalaFun[ctional] spark with scala
Fun[ctional] spark with scala
 
BDX 2016 - Tzach zohar @ kenshoo
BDX 2016 - Tzach zohar  @ kenshooBDX 2016 - Tzach zohar  @ kenshoo
BDX 2016 - Tzach zohar @ kenshoo
 
Macro in Scala
Macro in ScalaMacro in Scala
Macro in Scala
 
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
sbt, history of JSON libraries, microservices, and schema evolution (Tokyo ver)
 

Ähnlich wie Six years of Scala and counting

Sakai newcomer 10 easy questions not so easy
Sakai newcomer   10 easy questions not so easySakai newcomer   10 easy questions not so easy
Sakai newcomer 10 easy questions not so easy
daniel.merino
 
Introducing Scala in your existing Java project
Introducing Scala in your existing Java projectIntroducing Scala in your existing Java project
Introducing Scala in your existing Java project
ING-IT
 

Ähnlich wie Six years of Scala and counting (20)

Sakai newcomer 10 easy questions not so easy
Sakai newcomer   10 easy questions not so easySakai newcomer   10 easy questions not so easy
Sakai newcomer 10 easy questions not so easy
 
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
 
Scala eXchange 2013 Report
Scala eXchange 2013 ReportScala eXchange 2013 Report
Scala eXchange 2013 Report
 
Guidance, Code and Education: ScalaCenter and the Scala Community, Heather Mi...
Guidance, Code and Education: ScalaCenter and the Scala Community, Heather Mi...Guidance, Code and Education: ScalaCenter and the Scala Community, Heather Mi...
Guidance, Code and Education: ScalaCenter and the Scala Community, Heather Mi...
 
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
Sviluppare applicazioni nell'era dei "Big Data" con Scala e Spark - Mario Car...
 
Felix Sasaki - Value beyond content creation - Introducing ITS 2.0; soapconf ...
Felix Sasaki - Value beyond content creation - Introducing ITS 2.0; soapconf ...Felix Sasaki - Value beyond content creation - Introducing ITS 2.0; soapconf ...
Felix Sasaki - Value beyond content creation - Introducing ITS 2.0; soapconf ...
 
Scala for n00bs by a n00b.
Scala for n00bs by a n00b.Scala for n00bs by a n00b.
Scala for n00bs by a n00b.
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Upgrading JavaScript to ES6 and using TypeScript as a shortcut
Upgrading JavaScript to ES6 and using TypeScript as a shortcutUpgrading JavaScript to ES6 and using TypeScript as a shortcut
Upgrading JavaScript to ES6 and using TypeScript as a shortcut
 
Alternatives to SQL - a Laravel Perspective
Alternatives to SQL - a Laravel PerspectiveAlternatives to SQL - a Laravel Perspective
Alternatives to SQL - a Laravel Perspective
 
Introducing Scala in your existing Java project
Introducing Scala in your existing Java projectIntroducing Scala in your existing Java project
Introducing Scala in your existing Java project
 
Making ES6 available to all with ChakraCore and Typescript
Making ES6 available to all with ChakraCore and TypescriptMaking ES6 available to all with ChakraCore and Typescript
Making ES6 available to all with ChakraCore and Typescript
 
SiriusCon2016 - Let's talk about your future sirius project
SiriusCon2016 - Let's talk about your future sirius projectSiriusCon2016 - Let's talk about your future sirius project
SiriusCon2016 - Let's talk about your future sirius project
 
Code Europe Spring 2018 - Mind the Gap
Code Europe Spring 2018 -  Mind the GapCode Europe Spring 2018 -  Mind the Gap
Code Europe Spring 2018 - Mind the Gap
 
Java With The Best Online Conference - Mind the gap: Java, Machine Learning, ...
Java With The Best Online Conference - Mind the gap: Java, Machine Learning, ...Java With The Best Online Conference - Mind the gap: Java, Machine Learning, ...
Java With The Best Online Conference - Mind the gap: Java, Machine Learning, ...
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scala
 
Hadoopsummit16 myui
Hadoopsummit16 myuiHadoopsummit16 myui
Hadoopsummit16 myui
 
From java to scala at crowd mix
From java to scala at crowd mixFrom java to scala at crowd mix
From java to scala at crowd mix
 
Functional programming in scala coursera
Functional programming in scala  courseraFunctional programming in scala  coursera
Functional programming in scala coursera
 

Mehr von Manuel Bernhardt

Mehr von Manuel Bernhardt (14)

Is there anybody out there? Reactive Systems Hamburg
Is there anybody out there? Reactive Systems HamburgIs there anybody out there? Reactive Systems Hamburg
Is there anybody out there? Reactive Systems Hamburg
 
Is there anybody out there? Scala Days Berlin 2018
Is there anybody out there? Scala Days Berlin 2018Is there anybody out there? Scala Days Berlin 2018
Is there anybody out there? Scala Days Berlin 2018
 
Is there anybody out there?
Is there anybody out there?Is there anybody out there?
Is there anybody out there?
 
Is there anybody out there?
Is there anybody out there?Is there anybody out there?
Is there anybody out there?
 
3 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 20153 things you must know to think reactive - Geecon Kraków 2015
3 things you must know to think reactive - Geecon Kraków 2015
 
Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysReactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDays
 
Writing a technical book
Writing a technical bookWriting a technical book
Writing a technical book
 
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMVoxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
 
Back to the futures, actors and pipes: using Akka for large-scale data migration
Back to the futures, actors and pipes: using Akka for large-scale data migrationBack to the futures, actors and pipes: using Akka for large-scale data migration
Back to the futures, actors and pipes: using Akka for large-scale data migration
 
Project Phoenix - From PHP to the Play Framework in 3 months
Project Phoenix - From PHP to the Play Framework in 3 monthsProject Phoenix - From PHP to the Play Framework in 3 months
Project Phoenix - From PHP to the Play Framework in 3 months
 
Scala - Java2Days Sofia
Scala - Java2Days SofiaScala - Java2Days Sofia
Scala - Java2Days Sofia
 
Tips and tricks for setting up a Play 2 project
Tips and tricks for setting up a Play 2 projectTips and tricks for setting up a Play 2 project
Tips and tricks for setting up a Play 2 project
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala pitfalls
Scala pitfallsScala pitfalls
Scala pitfalls
 

Kürzlich hochgeladen

Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 

Kürzlich hochgeladen (20)

Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 

Six years of Scala and counting

  • 1. 7 years of Scala and counting Scala Days Vienna 2017 Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 2. 6 years of Scala and counting Scala Vienna User Group May 2016 Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 3. Agenda 1. Quick introduction to Scala 2. Learning Scala 3. Using Scala 4. Learnings, reflection, observations, impressions 5. Questions Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 4. Manuel Bernhardt • I help companies getting started with using reactive applications in their distributed systems infrastructure • http://manuel.bernhardt.io Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 5. Manuel Bernhardt • I help companies getting started with using reactive applications in their distributed systems infrastructure • http://manuel.bernhardt.io Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 6. Scala: an introduction Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 7. Scala introduction • first version released in 2003 • Martin Oderksy, EPFL • an estimated more than half a million Scala developers 1 1 http://www.scala-lang.org/blog/2016/03/14/announcing-the-scala- center.html Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 8. Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 9. Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 10. Scala Center • non-for-profit foundation for Scala education and community guidance • established at EPFL • founding members: IBM, verizon, Goldman Sachs, nitro, Lightbend Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 11. Favourite Feature tour Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 12. case classes public class User { private final String name; private final String surname; private final Integer age; public User(String name, String surname, Integer age) { this.name = name; this.surname = surname; this.age = age; } public String getName() { return this.name; } public String getSurname() { return this.surname; } public String getAge() { return this.age; } @Override public int hashCode() { // ... } @Override public boolean equals(Object that) { // ... } } Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 13. case classes case class User(name: String, surname: String, age: Int) Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 14. case classes case class User(name: String, surname: String, age: Int) val bob = User("Bob", "Marley", 42) val namedBob = User(name = "Bob", surname = "Marley", age = 22) val john = bob.copy(name = "John") Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 15. case class • perfect example of the terseness Scala provides • hashcode, equals, toString for free • serializable by default Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 16. type inference val foo = "Bar" // foo: String = Bar val answer = 42 // answer: Int = 42 val price = 9.99 // price: Double = 9.99 val nums = List(1, 2, 3) // nums: List[Int] = List(1, 2, 3) val map = Map("abc" -> List(1, 2, 3)) // map: scala.collection.immutable.Map[String,List[Int]] = Map(abc -> List(1, 2, 3)) Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 17. functions and higher-order functions def isMajor(user: User): Boolean = user.age > 18 Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 18. functions and higher-order functions def isMajor(user: User): Boolean = user.age > 18 class UserGroup { def filter(predicate: User Boolean): List[User] = ... } Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 19. functions and higher-order functions def isMajor(user: User): Boolean = user.age > 18 class UserGroup { def filter(predicate: User Boolean): List[User] = ... } userGroup.filter(isMajor) // returns only majors Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 20. Learning Scala Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 21. Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 22. How "learnable" is Scala? • Shadaj Laddad • http://shadaj.me • learned Scala at age 11-12 • talks at Scala Days, OSCON since 2012 Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 23. How "learnable" is Scala? • Coursera courses, 400.000+ participants - highest completation rate in the industry (10%, which is high for a MOOC 2 ) • Scala as beginner programming language at Lund University of Technology 3 3 https://www.lth.se/english/about-lth/news/news/article/scala-will-be-the- beginner-programming-language-of/ 2 Massive Open Online Course Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 24. My learning path • 2010: started dabbling with Scala (books, using it in tests, small projects) • 2011: discovering Functional Programming through Javascript. Using Play Framework 1 with the Scala module in my 2nd startup • 2012: first large codebase to migration from Play 1 to Play 2.0.0 (based entirely on Scala) Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 25. My learning path • 2013: several client projects using Scala • 2014-2016: architecture, prototyping, design, implementation, review of various production systems with Scala, Akka, Play Framework; writing Reactive Web Applications Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 26. My learning path • estimated 6 months to "click" • imperative declarative • mutable, global state immutable, expression-oriented • longer to grasp or use more advanced concepts • and how not to shoot myself in the foot with them Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 27. Your learning path? • new Coursera courses by the Scala Center • https://scala.epfl.ch • try to use Scala for something "real" • and even if it is just tests in a real project Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 28. Using Scala Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 29. 6 years without one of those pesky NullPointerException-s Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 30. Significantly less problems at runtime • Scala compiler spots a whole plethora of problems at compile- time • leveraged by e.g. Play Framework, high emphasis on "compiling everything" • URLs • Javascript (Google Clojure Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 31. Less code yields higher maintainbility (Less is more) Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 32. IDE / Editors • IntelliJ IDEA • Scala IDE for Eclipse • ENSIME 5 • emacs, Atom, Sublime Text, vim 5 Enhanced Scala and java Interaction Mode for text Editors Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 33. Compiler • slower than the Java compiler • but not a problem (anymore) on modern hardware • especially with incremental compilation • unless you deep dive into type-level and generic programming (e.g. shapeless library) • much more precise than the Java compiler (type-safe ++) Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 34. Jobs & Developers Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 36. What I've learned Reflection, Impressions, (Advice) Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 37. The Dreyfus model of skill acquisition Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 38. Learning #1 Spend a little time understanding the language design Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 39. Understand Scala's essence and your life will be easier Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 40. Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 41. Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 42. Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 43. Learning #2 Understand the purpose of the language features Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 44. Scala has quite a few language features because it was designed to be extensible Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 45. Don't be that kid Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 46. Scala language levels 4 • Level A1: Beginning application programmer • Level A2: Intermediate application programmer • Level A3: Expert application programmer 4 http://www.scala-lang.org/old/node/8610 Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 47. Scala language levels 4 • Level L1: Junior library designer • Level L2: Senior library designer • Level L3: Expert library designer 4 http://www.scala-lang.org/old/node/8610 Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 48. The features you need to build applications are not the same as the ones you need to build librariesScala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 49. SIP 18: Modularizing language features import scala.language.implicitConversions import scala.language.dynamics import scala.language.postfixOps import scala.language.reflectiveCalls import scala.language.higherKinds import scala.language.existentials import scala.language.macros Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 50. Incidental complexity Is this really a problem specific to Scala? Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 51. @SuppressWarnings({"unchecked", "rawtypes"}) @Deprecated @OneToMany(@HowManyDBADoYouNeedToChangeALightBulb) @OneToManyMore @AnyOne @AnyBody @YouDoNotTalkAboutOneToMany // Fightclub, LOL @TweakThisWithThat( tweak = { @TweakID(name = "id", preferredValue = 1839), @TweakID(name = "test", preferredValue = 839), @TweakID(name = "test.old", preferredValue = 34), }, inCaseOf = { @ConditionalXMLFiltering(run = 5), } ) @ManyToMany @Many @AnnotationsTotallyRock @DeclarativeProgrammingRules @NoMoreExplicitAlgorithms @Fetch @FetchMany @FetchWithDiscriminator(name = "no_name") @SeveralAndThenNothing @MaybeThisDoesSomething @JoinTable(joinColumns = { @JoinColumn(name = "customer_id", referencedColumnName = "id") }) @DoesThisEvenMeanAnything @DoesAnyoneEvenReadThis @PrefetchJoinWithDiscriminator @JustTrollingYouKnow @LOL @IfJoiningAvoidHashJoins @ButUseHashJoinsWhenMoreThan(records = 1000) @XmlDataTransformable @SpringPrefechAdapter private Collection employees; // http://annotatiomania.com Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 52. Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 53. Learning #3 Don't forget all about Object Oriented Programming Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 54. class SynchronizationService { private[services] def synchronizeTeeTimes( suite: Suite, dataType: SuiteDataType, eventuallyByteStream: Future[Enumerator[Array[Byte]]], removeDocsWithOlderTimestamps: Boolean): Future[Int] = ... private[services] def synchronizeTournaments( suite: Suite, dataType: SuiteDataType, eventuallyByteStream: Future[Enumerator[Array[Byte]]], removeDocsWithOlderTimestamps: Boolean): Future[Int] = ... } Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 55. class SynchronizationService { private def synchronizeGolf[T, S](suite: Suite, dataType: SuiteDataType, eventuallyByteStream: Future[Enumerator[Array[Byte]]], toIndexDocuments: (Suite, Issuer, GolfClub) => Seq[T] => Iterable[S], // function! indexDocuments: Iterable[S] => Future[Boolean], // function! countDocuments: CountRequest => Future[Long], // function! verify: (Int, Long) => Unit, // function! removeDocsWithOlderTimestamps: Boolean)(implicit format: Format[T]): Future[Int] = ... } Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 56. Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 57. Learning #4 Don't use every feature as a hammer Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 58. for comprehension val bobUser: Option[User] = ... val carlUser: Option[User] = ... val bobCarlAge: Option[Int] = for { bob <- bobUser carl <- carlUser } yield bob.age + carl.age Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 59. for comprehension from hell for { stopWatch <- Future.successful(startedStopWatch) startTimestampOfSync = DateTime.now() byteStream <- eventuallyByteStream suiteDocStream = toDocumentStream[T](byteStream) chunkedStream = suiteDocStream &> ExtraEnumeratees.chunker(ChunkSize) indexerSuccessStream = chunkedStream &> indexer indexerSuccess <- indexerSuccessStream.run(Iteratee.fold(true)(_ && _)) _ <- if (removedDocsWithOlderTimestamps) waitForElasticSearchToFinishIndexing().map(_ => removeDocsUpsertedBefore(issuer, dataType, startTimestampOfSync)) else Future.successful(()) count <- waitForElasticSearchToFinishIndexing().flatMap { _ => verifyCount(issuer, counter.get(), countDocuments, verify) } } yield { if (!indexerSuccess) error(s"Failed to index $dataType for ${suite.url}") val duration = scala.concurrent.duration.Duration(stopWatch.getNanoTime, TimeUnit.NANOSECONDS).toSeconds info(s"Done synchronizing ${counter.get()} $dataType for ${suite.url}, it took $duration s") count } Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 60. Learning #5 Transitioning to Scala (for teams) Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 61. Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 62. Don't start a Scala project with a team comprised of novice and advanced beginners Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 63. Don't start a <XYZ> project with a team comprised of novice and advanced beginners Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 64. It's all about people The biggest challenges of transitioning to Scala — or anything new  — are rarely technical. Talented programmers can learn a new syntax, new concepts, and a new IDE. Rather, change often brings out the weaknesses in other areas like process and culture. 6 — Kevin Webber 6 https://medium.com/@kvnwbbr/transitioning-to-scala-d1818f25b2b7#.x1tcfcs58 Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 65. Building up Scala knowledge in your team • culture that emphasizes learning, create time for learning • code reviews, discussions • try to get one "Competent" on your team • even if it's a "hired gun" helping to bootstrap & ensure best practices (& avoiding pitfalls) • invest in training (Fast track to Scala, etc.) Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 66. Conclusion Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 67. Conclusion case class User(name: String, surname: String, age: Int) Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 68. Conclusion case class User(name: String, surname: String, age: Int) embrace Scala's terseness Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 69. Conclusion case class User(name: String, surname: String, age: Int) embrace Scala's terseness don't forget about the language levels Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu
  • 70. Thank you! Questions & Comments ? • http://manuel.bernhardt.io • @elmanu Scala Vienna May 2016 - manuel.bernhardt.io - @elmanu