Upload
ansvialab
View
79
Download
3
Embed Size (px)
Citation preview
SCALA : language of the future
by Robin SyihabMindtalk: @robin
Twitter: @anvieEmail: [email protected]
Scala is
a Modern Programming language.Created by Martin Odersky.Static TypingOOP + FPCompiled into bytecode and run on top of JVM.Java compatible binaries.a better Java.
“If I were to pick a language to use today other than Java, it would be Scala”
~ James Gosling (father of Java).
Scala is
JVM Language
Java & Scala timeline
JVM Languages available today
ScalaGroovyFantomClojureJRubyJythonKotlin
Java & JVML timeline
“The legacy of Java will be the platform, not the language.”~ Martin Fowler (OOP programming expert)
Scala is
Scalable Language
“No other language on the JVM seems as capable of being a
"replacement for Java" as Scala.”~ Charlies Nutter (JRuby lead)
Scala in production
Scala Job Trends
Java vs Scala (syntax)
Java
Scala
Scala
Java
Singleton
Scala
Java
Singleton Use
Scala
Java
Regex
Scala is powerful for functional
programming
Scala
Java
Partitioning
Scala
Java
Calculating average
Scala is more than“syntactic sugar language”
Scala OOP
Object inheritanceObject and method accessibility (public, protected, private).Static method.Mutable & Immutable variable.
Scala OOP
Everything return value
Traits
Like interfaces in java, butcan have implementationscan have fieldscan mix-in
Scala is Functional
XML LiteralsScala support XML literals inside of code
XML literals
Lazy variable evaluation
Lazy Variable Evaluation
// Use case
Pattern Matching
animal match { case cat:Cat => cat.meow()
case tiger:Tiger => tiger.hoa()
}
Pattern Matching
Pattern Matching: data extraction
Pattern Matching: data extraction + guardian
Implicit definition: View bounds
robin say “hello”
robin.say(“hello”)
Lenient Invocation Syntax
object method parameter
Lenient Invocation Syntax
h(x) = y f(x, y)⟼
Currying Function
We need this simple code run robustly:+ no crash when exception happen.+ handle unicode UTF-8 correctly.+ no memory leak.
Currying Function
Currying Function
Partial Function
PipeliningPattern Matching
Partial Function: Pipelining
Execution
Partial Function: Pipelining
Partial Function: Pattern Matching
Parameter
Partial Function: Pattern Matching
ActorConcurrent Programming
When to use Actor?
If we want to build distributed system.Handle massive concurrent request.Needs for build event-driven asynchronous application.High performance lightweight than Thread.
Scala Actor Local
Akka Actor: Distributed
100.10.10.1
Actor A
100.10.10.2
Actor B
100.10.10.3
Actor C
100.10.10.4
Actor D
event stream
http://akka.io/
Akka Actor
Support local & remote actorSelf-healing using supervisorDecentralized
Adaptive load balancing Configuration-driven
ExtensibleSmall memory footprint ~2.5 million actors per GB of HeapEvent stream easy to handle cluster state
Akka Actor in production
TDD in Scalahttp://lostechies.com
Scala testing framework
ScalatestJUnitSpec2Gatling (performance test)
Specs2 Unit test
Specs2 Acceptance test
Specs2
Ok thats sound interesting,but wait...
how with the development tools?
http://www.thetinylife.com
Development tools
IDE
Scala-IDE (eclipse based)
NetBeans
IntellijIdea
Emacs (ENSIME)
Build System
Maven
SBT (Simple Build Tools)
Project generator
Giter8
JRebel (incremental development)
giter8
Build Scala “hello world”application in minute
Thank you