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

Intro to Functional Programming in Scala
Intro to Functional Programming in ScalaIntro to Functional Programming in Scala
Intro to Functional Programming in ScalaShai Yallin
 
Procedure Typing for Scala
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scalaakuklev
 
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, Vasil Remeniuk
 
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
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: NotesRoberto Casadei
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basicsmsemenistyi
 
Swift in SwiftUI
Swift in SwiftUISwift in SwiftUI
Swift in SwiftUIBongwon Lee
 
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 2010Derek Chen-Becker
 
Java best practices
Java best practicesJava best practices
Java best practicesRay Toal
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedSusan Potter
 
Few simple-type-tricks in scala
Few simple-type-tricks in scalaFew simple-type-tricks in scala
Few simple-type-tricks in scalaRuslan Shevchenko
 
SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.Ruslan Shevchenko
 
Java/Scala Lab 2016. Григорий Кравцов: Реализация и тестирование DAO слоя с н...
Java/Scala Lab 2016. Григорий Кравцов: Реализация и тестирование DAO слоя с н...Java/Scala Lab 2016. Григорий Кравцов: Реализация и тестирование DAO слоя с н...
Java/Scala Lab 2016. Григорий Кравцов: Реализация и тестирование DAO слоя с н...GeeksLab Odessa
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An IntroductionManvendra Singh
 

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

Stairway to scala flyer
Stairway to scala flyerStairway to scala flyer
Stairway to scala flyerdickwall
 
Why Scala for Web 2.0?
Why Scala for Web 2.0?Why Scala for Web 2.0?
Why Scala for Web 2.0?Alex Payne
 
Scala dreaded underscore
Scala dreaded underscoreScala dreaded underscore
Scala dreaded underscoreRUDDER
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to ScalaRahul Jain
 
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...Helena Edelson
 

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

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 Wsloffenauer
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalMichael Stal
 
Dax Declarative Api For Xml
Dax   Declarative Api For XmlDax   Declarative Api For Xml
Dax Declarative Api For XmlLars Trieloff
 
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?Jesper Kamstrup Linnet
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java ProgrammersEric Pederson
 
Introduction To Groovy 2005
Introduction To Groovy 2005Introduction To Groovy 2005
Introduction To Groovy 2005Tugdual Grall
 
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 ScalaDerek Chen-Becker
 
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 DevelopersMiles Sabin
 
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 DevelopersMiles Sabin
 
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)Pavlo Baron
 
ParaSail
ParaSail  ParaSail
ParaSail AdaCore
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 
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 TonguesCHOOSE
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghStuart Roebuck
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecLoïc Descotte
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaMichael Stal
 

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

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Recently uploaded (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

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!