Coefficient of Thermal Expansion and their Importance.pptx
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
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
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
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
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
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
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
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
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
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