SlideShare a Scribd company logo
1 of 21
Download to read offline
whoami

Peter Maas:

   Joined marktplaats in the beginning of 2010 after working in
   outplacement for too many years. Currently part of the
   Migration team.
   Lot's of experience on the Java platform (VPRO, Kennisnet,
   Rabobank, European commission)
   Interested in programming languages in general
What & Why
Scala is:

  A general purpose language
  Runs on the JVM
     statically typed!
  Object Oriented
  A Functional language
  A Scalable language
  Deep: Closures, Currying, Tuples, Implicit conversions,
  Pattern matching, Monads and MUCH more
What could you use it for?

  Scripting
  Web Applications
  Messaging
  Testing
  Graphical User Interfaces
Is used by:

  Twitter
  Siemens
  LinkedIn
  Sony Pictures Imageworks
                             During a meeting in the Community Corner
  The migration team         (java.net booth) with James Gosling, a
                             participant asked an interesting question:

                             "Which Programming Language would you
                             use *now* on top of JVM, except Java?".

                             The answer was surprisingly fast and very
                             clear: - Scala.
Why would you use it?

 Concise / tolerant syntax ==> good for DSLs
 Integrates seamlessly with existing Java libraries/apps
 Makes concurrent programming easier
 Scalable from a language point of view
 Statically typed
 It's from Switzerland!
Syntax
object MyGreeter {
  def main(args:Array[String]) = println("Hello World")
}
object MyGreeter{
  def main(args:Array[String]) = {
    val toGreet = "Marktplaats developers"
    println("Hello %s".format(toGreet))
  }
}
methods & 'operators'




val toGreet = " Marktplaats developers"
"Hello".+(toGreet)
"Hello" + toGreet

"Hello".concat(toGreet)
"Hello" concat toGreet

// methods are objects...
val greetMethod = "hello %s".format(_:String)
greetMethod(toGreet)
methods

def makeGreet(toGreet:String):String = {
  return "Hello " + toGreet
}

def makeGreet(toGreet:String) = { // return type is inferred from returned type
  "Hello " + toGreet // the last result is also returned (like javascript, ruby)
}

// for short methods you can drop the line noise
def makeGreet(toGreet:String) = "Hello " + toGreet
collections

List(1,2,3,4).foreach{ num => println(num) } // 1,2,3,4

List(1,2,3,4).foreach(println(_)) // 1,2,3,4
List(1,2,3,4).map( _ * 2) foreach(println(_)) // 2,4,6,8

List(1,2,3,4).foldLeft(0)(_+_) // ((((0+1)+2)+3)+4) -> 10

1 :: 2 :: 3 :: 4 :: Nil // List(1,2,3,4)

"this is a line of words"
    .split(" ")
    .map(_.reverse)         // call reverse on each item
    .mkString(" ")          // create a string

results in: "siht si a enil fo sdrow"
REPL

Read Eval(uate) Print Loop
Classes & Constructors

class Person(name:String, age:Int) // immutable is default
val p = new Person("Peter", 31)
p.name = "Obama" // compiler error!


class Person(var name:String, age:Int)
val p = new Person("Peter", 31)
p.name = "Obama"



class Person(name:String, age:Int) {
  this(name:String) = this(name, 31)
  this(age:Int) = this("anonymous", age)
}
Companion Objects

class Car() {
    def drive = ...
}

/**
  * similar to a helper with static members in Java but without
  * strange inheritance quircks.
  */
object Car {
     def assemble(e:Engine, c:Chassis, w:List[Wheel]):Car = {
         ... // assemble the car and return it
     }
}
Case Classes

Classes with a lot of useful 'defaults' like hashcode, equals,
toString, simplyfied constructor, copy and support for pattern
matching.
case class Person(firstName:String, lastName:String)

val p1 =   Person("Peter", "Maas")
val p2 =   Person("Peter", "Maas")
p1 == p2   --> true
val p3 =   p1.copy(firstName = "Sjoerd")
p3 == p1   --> false
Traits & Stacking
trait Steer {
  def changeDirection()
}

trait Engine {
  def start()
}

trait Safety extends Engine {
  var locked = true
  abstract override def start() = if(!locked) super.start() else println("locked!")
}


class Car extends Engine with Steer {
  override def changeDirection() = { println("steering") }
  override def start() = { println("starting!") }
}

object TraitTests {
  def main(args: Array[String]) {
    val normal = new Car
    val safe = new Car with Safety

        normal.start   // prints "starting!"
        safe.start     // prints "locked!"
    }
}
Much more

 Implicit conversions (duck typing)
 Actors
 Tuples
 Pattern Matching
 Built-in parser constructs
 Monads
 XML support built into the language
 Regexp support
 ...
DEMO!
Thanks!
Questions?

More Related Content

What's hot

Procedure Typing for Scala
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scala
akuklev
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
jeffz
 

What's hot (20)

Scala jargon cheatsheet
Scala jargon cheatsheetScala jargon cheatsheet
Scala jargon cheatsheet
 
Intro to Functional Programming in Scala
Intro to Functional Programming in ScalaIntro to Functional Programming in Scala
Intro to Functional Programming in Scala
 
Scala test
Scala testScala test
Scala test
 
Procedure Typing for Scala
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scala
 
Metaprogramming in Scala 2.10, Eugene Burmako,
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako,
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: Notes
 
Java for beginners
Java for beginnersJava for beginners
Java for beginners
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basics
 
Swift in SwiftUI
Swift in SwiftUISwift in SwiftUI
Swift in SwiftUI
 
Javascript
JavascriptJavascript
Javascript
 
Scala - brief intro
Scala - brief introScala - brief intro
Scala - brief intro
 
Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010
 
JavaScript Basics
JavaScript BasicsJavaScript Basics
JavaScript Basics
 
Java best practices
Java best practicesJava best practices
Java best practices
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids Applied
 
Few simple-type-tricks in scala
Few simple-type-tricks in scalaFew simple-type-tricks in scala
Few simple-type-tricks in scala
 
SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.
 
Java/Scala Lab 2016. Григорий Кравцов: Реализация и тестирование DAO слоя с н...
Java/Scala Lab 2016. Григорий Кравцов: Реализация и тестирование DAO слоя с н...Java/Scala Lab 2016. Григорий Кравцов: Реализация и тестирование DAO слоя с н...
Java/Scala Lab 2016. Григорий Кравцов: Реализация и тестирование DAO слоя с н...
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 

Viewers also liked

Viewers also liked (9)

Scala vs java 8
Scala vs java 8Scala vs java 8
Scala vs java 8
 
Stairway to scala flyer
Stairway to scala flyerStairway to scala flyer
Stairway to scala flyer
 
Scala for dummies
Scala for dummiesScala for dummies
Scala for dummies
 
Scala Jump Start
Scala Jump StartScala Jump Start
Scala Jump Start
 
Scala for dummies
Scala for dummiesScala for dummies
Scala for dummies
 
Why Scala for Web 2.0?
Why Scala for Web 2.0?Why Scala for Web 2.0?
Why Scala for Web 2.0?
 
Scala dreaded underscore
Scala dreaded underscoreScala dreaded underscore
Scala dreaded underscore
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...
Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...
Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...
 

Similar to Introduction To Scala

BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 

Similar to Introduction To Scala (20)

Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
 
Dart
DartDart
Dart
 
Dax Declarative Api For Xml
Dax   Declarative Api For XmlDax   Declarative Api For Xml
Dax Declarative Api For Xml
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
 
Introduction To Groovy 2005
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005
 
Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to Scala
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
ParaSail
ParaSail  ParaSail
ParaSail
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesChoose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Scala - en bedre Java?
Scala - en bedre Java?Scala - en bedre Java?
Scala - en bedre Java?
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scala
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 

Introduction To Scala

  • 1.
  • 2. whoami Peter Maas: Joined marktplaats in the beginning of 2010 after working in outplacement for too many years. Currently part of the Migration team. Lot's of experience on the Java platform (VPRO, Kennisnet, Rabobank, European commission) Interested in programming languages in general
  • 4. Scala is: A general purpose language Runs on the JVM statically typed! Object Oriented A Functional language A Scalable language Deep: Closures, Currying, Tuples, Implicit conversions, Pattern matching, Monads and MUCH more
  • 5. What could you use it for? Scripting Web Applications Messaging Testing Graphical User Interfaces
  • 6. Is used by: Twitter Siemens LinkedIn Sony Pictures Imageworks During a meeting in the Community Corner The migration team (java.net booth) with James Gosling, a participant asked an interesting question: "Which Programming Language would you use *now* on top of JVM, except Java?". The answer was surprisingly fast and very clear: - Scala.
  • 7. Why would you use it? Concise / tolerant syntax ==> good for DSLs Integrates seamlessly with existing Java libraries/apps Makes concurrent programming easier Scalable from a language point of view Statically typed It's from Switzerland!
  • 9. object MyGreeter { def main(args:Array[String]) = println("Hello World") }
  • 10. object MyGreeter{ def main(args:Array[String]) = { val toGreet = "Marktplaats developers" println("Hello %s".format(toGreet)) } }
  • 11. methods & 'operators' val toGreet = " Marktplaats developers" "Hello".+(toGreet) "Hello" + toGreet "Hello".concat(toGreet) "Hello" concat toGreet // methods are objects... val greetMethod = "hello %s".format(_:String) greetMethod(toGreet)
  • 12. methods def makeGreet(toGreet:String):String = { return "Hello " + toGreet } def makeGreet(toGreet:String) = { // return type is inferred from returned type "Hello " + toGreet // the last result is also returned (like javascript, ruby) } // for short methods you can drop the line noise def makeGreet(toGreet:String) = "Hello " + toGreet
  • 13. collections List(1,2,3,4).foreach{ num => println(num) } // 1,2,3,4 List(1,2,3,4).foreach(println(_)) // 1,2,3,4 List(1,2,3,4).map( _ * 2) foreach(println(_)) // 2,4,6,8 List(1,2,3,4).foldLeft(0)(_+_) // ((((0+1)+2)+3)+4) -> 10 1 :: 2 :: 3 :: 4 :: Nil // List(1,2,3,4) "this is a line of words" .split(" ") .map(_.reverse) // call reverse on each item .mkString(" ") // create a string results in: "siht si a enil fo sdrow"
  • 15. Classes & Constructors class Person(name:String, age:Int) // immutable is default val p = new Person("Peter", 31) p.name = "Obama" // compiler error! class Person(var name:String, age:Int) val p = new Person("Peter", 31) p.name = "Obama" class Person(name:String, age:Int) { this(name:String) = this(name, 31) this(age:Int) = this("anonymous", age) }
  • 16. Companion Objects class Car() { def drive = ... } /** * similar to a helper with static members in Java but without * strange inheritance quircks. */ object Car { def assemble(e:Engine, c:Chassis, w:List[Wheel]):Car = { ... // assemble the car and return it } }
  • 17. Case Classes Classes with a lot of useful 'defaults' like hashcode, equals, toString, simplyfied constructor, copy and support for pattern matching. case class Person(firstName:String, lastName:String) val p1 = Person("Peter", "Maas") val p2 = Person("Peter", "Maas") p1 == p2 --> true val p3 = p1.copy(firstName = "Sjoerd") p3 == p1 --> false
  • 18. Traits & Stacking trait Steer { def changeDirection() } trait Engine { def start() } trait Safety extends Engine { var locked = true abstract override def start() = if(!locked) super.start() else println("locked!") } class Car extends Engine with Steer { override def changeDirection() = { println("steering") } override def start() = { println("starting!") } } object TraitTests { def main(args: Array[String]) { val normal = new Car val safe = new Car with Safety normal.start // prints "starting!" safe.start // prints "locked!" } }
  • 19. Much more Implicit conversions (duck typing) Actors Tuples Pattern Matching Built-in parser constructs Monads XML support built into the language Regexp support ...
  • 20. DEMO!