SlideShare a Scribd company logo
1 of 26
Download to read offline
From Python
  to Scala

 Sébastien Pierre, ffunction inc.
@Montréal Python, April 2010

         www.ffctn.com


                                    ffunction
                                    inc.
Stuff I love about Python



●
    Expressive (and compact)
●
    Simple to learn
●
    Lots of smartly designed libraries




                                         ffunction
                                         inc.
Stuff that I miss in Python



●
    Closures (with syntax)
●
    Easy concurrency (model and syntax)
●
    … a compiler !!




                                          ffunction
                                          inc.
Scala - overview




                   ffunction
                   inc.
The language



●
    JVM-based, compiled + « interpreted »
●
    Functional + OO (post-functional)
●
    ~6 years old
●
    used by Twitter, FourSquare




                                            ffunction
                                            inc.
The library



●
    Anything in Java
●
    Immutable types library (safe for concurrent apps)
●
    Concurrency + actor model
●
    Quality community-contributed libraries




                                                    ffunction
                                                    inc.
The feel



●
    Make do with braces
●
    map/filter/apply (and fold)
●
    ~25% more lines than with Python
●
    Very good DSL-ability
●
    Fast !


                                       ffunction
                                       inc.
Scala – basics




                 ffunction
                 inc.
Rich types

        Scala               Python


Array   Array(1,2,3,4)      (1,2,3,4]


Tuple   (1,2,3,4)           (1,2,3,4)


List    List(1,2,3,4)       (1,2,3,4)


Map     Map(“a”>1, “b”>2)   {“a”:1, “c”:2}


Set     Set(1,2,3,4)        set(1,2,3,4)


                                             ffunction
                                             inc.
Closures


[1,2,3] map            { i => i + 1 }

{i:Int => i + 1 }                       # 1-param normal

(i:Int) => { i + 1 }                    # n-param normal

[1,2,3] map { _ + 1 }                   # implicit args


val f = { i:Int => i + 1}




                                                           ffunction
                                                           inc.
Classes + traits


class A
 {…}




                   ffunction
                   inc.
Classes + traits


 class A
  {…}




  class B
extends A
   {…}




                   ffunction
                   inc.
Classes + traits


 class A
  {…}




 class B
extends A   trait T
 with T      {…}
  {…}




                      ffunction
                      inc.
Classes + traits


 class A      trait U
  {…}          {…}




 class B
              trait T
extends A
            extends U
  with T
               {…}
  {…}




                        ffunction
                        inc.
Classes + traits


 class A      trait U
  {…}          {…}




 class B
              trait T
extends A
            extends U
  with T
               {…}
  {…}




                        ffunction
                        inc.
Batteries included
scala.xml.XML.load(
     "http://ffunction.posterous.com/rss.xml"
)  "item"  "title" toList

List[scala.xml.Node] = List(<title xmlns:media="http://search.yahoo.com/mrss/" 
xmlns:dc="http://purl.org/dc/elements/1.1/" 
xmlns:posterous="http://posterous.com/help/rss/1.0" 
xmlns:atom="http://www.w3.org/2005/Atom">Notes on creating a multi­touch 
interface</title>, <title xmlns:media="http://search.yahoo.com/mrss/" 
xmlns:dc="http://purl.org/dc/elements/1.1/" 
xmlns:posterous="http://posterous.com/help/rss/1.0" 
xmlns:atom="http://www.w3.org/2005/Atom">Formations en interface &amp; 
visualisation</title>, <title xmlns:media="http://search.yahoo.com/mrss/" 
xmlns:dc="http://purl.org/dc/elements/1.1/" 
xmlns:posterous="http://posterous.com/help/rss/1.0" 
xmlns:atom="http://www.w3.org/2005/Atom">Hello, world !</title>)




                                                                                  ffunction
                                                                                  inc.
Interpreter
scala> println(
  List("Hello","world !") match {
    case head :: tail =>
         tail.foldLeft(head)(
               (a:String,b:String)=>{a+", " +b})})

Hello, world !




                                                     ffunction
                                                     inc.
Scala – the sublime*


*SUBLIME : pleasure + pain, according to the Romantics




                                                         ffunction
                                                         inc.
The almost ML-grade type system

val f:List[Int] = List[1,2,3]

val m:Map[String,List[Int]] = Map(
    “a” → [1,2,3],
    “b” → [4,5,6]
)

type JSONable = { def toJSON():String }


                      > ensure constraints at compile-type, speed up programs




                                                                  ffunction
                                                                  inc.
Multiple method dispatch



def merge(                       def merge(

   a:Map[String,Object],             a:List[Object],
   b:Map[String,Object]              b:List[Object]

):Map[String,Object]             ):List[Object]


                           > makes it easy to specialize (existing) libraries




                                                                 ffunction
                                                                 inc.
Pattern-matching


val sum = {
   _ match {
      case head :: tail >
         head + sum (tail)
      case Nil >
         0
   }
}
          > amazing for message-based communication and list manipulation




                                                               ffunction
                                                               inc.
Actors
import scala.actors.Actor._

actor {
 while (true) {println ("Hello from A") ; Thread.sleep(1)}
}
actor {
 while (true) {println ("Hello from B") ; Thread.sleep(1)}
}
Hello from A   Hello from A   Hello from A   Hello from A   Hello from A   Hello from A
Hello from A   Hello from A   Hello from A   Hello from A   Hello from A   Hello from A
Hello from B   Hello from B   Hello from B   Hello from B   Hello from B   Hello from B
Hello from A   Hello from A   Hello from A   Hello from A   Hello from A   Hello from A
Hello from B   Hello from B   Hello from B   Hello from B   Hello from B   Hello from B
Hello from A   Hello from A   Hello from A   Hello from A   Hello from A   Hello from A
Hello from B   Hello from B   Hello from B   Hello from B   Hello from B   Hello from B
Hello from A   Hello from A   Hello from A   Hello from A   Hello from A   Hello from A
Hello from B   Hello from B   Hello from B   Hello from B   Hello from B   Hello from B
Hello from A   Hello from A   Hello from A   Hello from A   Hello from A   Hello from A
Hello from B   Hello from B   Hello from B   Hello from B   Hello from B   Hello from B
Hello from A   Hello from A   Hello from A   Hello from A   Hello from A   Hello from A
Hello from B   Hello from B   Hello from B   Hello from B   Hello from B   Hello from B
Hello from A   Hello from A   Hello from A   Hello from A   Hello from A   Hello from A


                                                                                          ffunction
                                                                                          inc.
Message-passing
import scala.actors.Actor._
val repeater = actor {
    while (true) {
       receive {
          case msg:String =>
             println(this + ">" + msg) ; reply (msg)
}}}
actor {
    repeater ! "ping"
    while (true) { receive {
       case msg:String =>
             println(this + ">" + msg) ; reply (msg)
}}}




                                                       ffunction
                                                       inc.
Le mot de la fin




                   ffunction
                   inc.
Scala is cool !



●
    Very powerful
●
    Hard to learn, long time to master
●
    Amazing complement to Python for research &
    performance-critical and scalable projects
●
    Easy to interface with Python !



                                          ffunction
                                          inc.
Merci !

  www.ffctn.com
sebastien@ffctn.com


                      ffunction
                      inc.

More Related Content

What's hot

OOP Intro in Ruby for NHRuby Feb 2010
OOP Intro in Ruby for NHRuby Feb 2010OOP Intro in Ruby for NHRuby Feb 2010
OOP Intro in Ruby for NHRuby Feb 2010bturnbull
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technologyppparthpatel123
 
Protocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayProtocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayAlexis Gallagher
 
Ry pyconjp2015 turtle
Ry pyconjp2015 turtleRy pyconjp2015 turtle
Ry pyconjp2015 turtleRenyuan Lyu
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Twoamiable_indian
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To ScalaInnar Made
 
Fantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOFFantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOFDror Bereznitsky
 
The Great Scala Makeover
The Great Scala MakeoverThe Great Scala Makeover
The Great Scala MakeoverGarth Gilmour
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeKevlin Henney
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like PythonistaChiyoung Song
 
F# delight
F# delightF# delight
F# delightpriort
 
Python-The programming Language
Python-The programming LanguagePython-The programming Language
Python-The programming LanguageRohan Gupta
 
JRuby, Not Just For Hard-Headed Pragmatists Anymore
JRuby, Not Just For Hard-Headed Pragmatists AnymoreJRuby, Not Just For Hard-Headed Pragmatists Anymore
JRuby, Not Just For Hard-Headed Pragmatists AnymoreErin Dees
 
The Sincerest Form of Flattery
The Sincerest Form of FlatteryThe Sincerest Form of Flattery
The Sincerest Form of FlatteryJosé Paumard
 
DEFUN 2008 - Real World Haskell
DEFUN 2008 - Real World HaskellDEFUN 2008 - Real World Haskell
DEFUN 2008 - Real World HaskellBryan O'Sullivan
 
Introduction to Python and TensorFlow
Introduction to Python and TensorFlowIntroduction to Python and TensorFlow
Introduction to Python and TensorFlowBayu Aldi Yansyah
 
Playfulness at Work
Playfulness at WorkPlayfulness at Work
Playfulness at WorkErin Dees
 

What's hot (20)

Template Haskell
Template HaskellTemplate Haskell
Template Haskell
 
OOP Intro in Ruby for NHRuby Feb 2010
OOP Intro in Ruby for NHRuby Feb 2010OOP Intro in Ruby for NHRuby Feb 2010
OOP Intro in Ruby for NHRuby Feb 2010
 
Ruby -the wheel Technology
Ruby -the wheel TechnologyRuby -the wheel Technology
Ruby -the wheel Technology
 
Cheatsheet
CheatsheetCheatsheet
Cheatsheet
 
Protocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayProtocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That Way
 
Ry pyconjp2015 turtle
Ry pyconjp2015 turtleRy pyconjp2015 turtle
Ry pyconjp2015 turtle
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
 
Fantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOFFantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOF
 
The Great Scala Makeover
The Great Scala MakeoverThe Great Scala Makeover
The Great Scala Makeover
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
 
Code Like Pythonista
Code Like PythonistaCode Like Pythonista
Code Like Pythonista
 
F# delight
F# delightF# delight
F# delight
 
Python-The programming Language
Python-The programming LanguagePython-The programming Language
Python-The programming Language
 
JRuby, Not Just For Hard-Headed Pragmatists Anymore
JRuby, Not Just For Hard-Headed Pragmatists AnymoreJRuby, Not Just For Hard-Headed Pragmatists Anymore
JRuby, Not Just For Hard-Headed Pragmatists Anymore
 
The Sincerest Form of Flattery
The Sincerest Form of FlatteryThe Sincerest Form of Flattery
The Sincerest Form of Flattery
 
Python ppt
Python pptPython ppt
Python ppt
 
DEFUN 2008 - Real World Haskell
DEFUN 2008 - Real World HaskellDEFUN 2008 - Real World Haskell
DEFUN 2008 - Real World Haskell
 
Introduction to Python and TensorFlow
Introduction to Python and TensorFlowIntroduction to Python and TensorFlow
Introduction to Python and TensorFlow
 
Playfulness at Work
Playfulness at WorkPlayfulness at Work
Playfulness at Work
 

Similar to From Python to Scala

Kotlin coroutines and spring framework
Kotlin coroutines and spring frameworkKotlin coroutines and spring framework
Kotlin coroutines and spring frameworkSunghyouk Bae
 
Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospectivechenge2k
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scalapramode_ce
 
app4.pptx
app4.pptxapp4.pptx
app4.pptxsg4795
 
Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Bryan O'Sullivan
 
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
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard LibrarySantosh Rajan
 
Hadoop Summit Europe 2014: Apache Storm Architecture
Hadoop Summit Europe 2014: Apache Storm ArchitectureHadoop Summit Europe 2014: Apache Storm Architecture
Hadoop Summit Europe 2014: Apache Storm ArchitectureP. Taylor Goetz
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongMario Fusco
 
Testing for share
Testing for share Testing for share
Testing for share Rajeev Mehta
 
Macros and reflection in scala 2.10
Macros and reflection in scala 2.10Macros and reflection in scala 2.10
Macros and reflection in scala 2.10Johan Andrén
 
Pydiomatic
PydiomaticPydiomatic
Pydiomaticrik0
 
Introduction to scala for a c programmer
Introduction to scala for a c programmerIntroduction to scala for a c programmer
Introduction to scala for a c programmerGirish Kumar A L
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojureAbbas Raza
 
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdfAndrey Breslav
 
Os Vanrossum
Os VanrossumOs Vanrossum
Os Vanrossumoscon2007
 

Similar to From Python to Scala (20)

Kotlin coroutines and spring framework
Kotlin coroutines and spring frameworkKotlin coroutines and spring framework
Kotlin coroutines and spring framework
 
Haskell retrospective
Haskell retrospectiveHaskell retrospective
Haskell retrospective
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 
app4.pptx
app4.pptxapp4.pptx
app4.pptx
 
Real World Haskell: Lecture 1
Real World Haskell: Lecture 1Real World Haskell: Lecture 1
Real World Haskell: Lecture 1
 
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)
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
Hadoop Summit Europe 2014: Apache Storm Architecture
Hadoop Summit Europe 2014: Apache Storm ArchitectureHadoop Summit Europe 2014: Apache Storm Architecture
Hadoop Summit Europe 2014: Apache Storm Architecture
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are Wrong
 
Testing for share
Testing for share Testing for share
Testing for share
 
Macros and reflection in scala 2.10
Macros and reflection in scala 2.10Macros and reflection in scala 2.10
Macros and reflection in scala 2.10
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
Introduction to scala for a c programmer
Introduction to scala for a c programmerIntroduction to scala for a c programmer
Introduction to scala for a c programmer
 
C# programming
C# programming C# programming
C# programming
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
Java
JavaJava
Java
 
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
2022 May - Shoulders of Giants - Amsterdam - Kotlin Dev Day.pdf
 
Os Vanrossum
Os VanrossumOs Vanrossum
Os Vanrossum
 
Scala for curious
Scala for curiousScala for curious
Scala for curious
 

Recently uploaded

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
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 TerraformAndrey Devyatkin
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
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 WorkerThousandEyes
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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 DiscoveryTrustArc
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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.pdfsudhanshuwaghmare1
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

From Python to Scala

  • 1. From Python to Scala Sébastien Pierre, ffunction inc. @Montréal Python, April 2010 www.ffctn.com ffunction inc.
  • 2. Stuff I love about Python ● Expressive (and compact) ● Simple to learn ● Lots of smartly designed libraries ffunction inc.
  • 3. Stuff that I miss in Python ● Closures (with syntax) ● Easy concurrency (model and syntax) ● … a compiler !! ffunction inc.
  • 4. Scala - overview ffunction inc.
  • 5. The language ● JVM-based, compiled + « interpreted » ● Functional + OO (post-functional) ● ~6 years old ● used by Twitter, FourSquare ffunction inc.
  • 6. The library ● Anything in Java ● Immutable types library (safe for concurrent apps) ● Concurrency + actor model ● Quality community-contributed libraries ffunction inc.
  • 7. The feel ● Make do with braces ● map/filter/apply (and fold) ● ~25% more lines than with Python ● Very good DSL-ability ● Fast ! ffunction inc.
  • 8. Scala – basics ffunction inc.
  • 9. Rich types Scala Python Array Array(1,2,3,4) (1,2,3,4] Tuple (1,2,3,4) (1,2,3,4) List List(1,2,3,4) (1,2,3,4) Map Map(“a”>1, “b”>2) {“a”:1, “c”:2} Set Set(1,2,3,4) set(1,2,3,4) ffunction inc.
  • 10. Closures [1,2,3] map { i => i + 1 } {i:Int => i + 1 } # 1-param normal (i:Int) => { i + 1 } # n-param normal [1,2,3] map { _ + 1 } # implicit args val f = { i:Int => i + 1} ffunction inc.
  • 11. Classes + traits class A {…} ffunction inc.
  • 12. Classes + traits class A {…} class B extends A {…} ffunction inc.
  • 13. Classes + traits class A {…} class B extends A trait T with T {…} {…} ffunction inc.
  • 14. Classes + traits class A trait U {…} {…} class B trait T extends A extends U with T {…} {…} ffunction inc.
  • 15. Classes + traits class A trait U {…} {…} class B trait T extends A extends U with T {…} {…} ffunction inc.
  • 16. Batteries included scala.xml.XML.load( "http://ffunction.posterous.com/rss.xml" ) "item" "title" toList List[scala.xml.Node] = List(<title xmlns:media="http://search.yahoo.com/mrss/"  xmlns:dc="http://purl.org/dc/elements/1.1/"  xmlns:posterous="http://posterous.com/help/rss/1.0"  xmlns:atom="http://www.w3.org/2005/Atom">Notes on creating a multi­touch  interface</title>, <title xmlns:media="http://search.yahoo.com/mrss/"  xmlns:dc="http://purl.org/dc/elements/1.1/"  xmlns:posterous="http://posterous.com/help/rss/1.0"  xmlns:atom="http://www.w3.org/2005/Atom">Formations en interface &amp;  visualisation</title>, <title xmlns:media="http://search.yahoo.com/mrss/"  xmlns:dc="http://purl.org/dc/elements/1.1/"  xmlns:posterous="http://posterous.com/help/rss/1.0"  xmlns:atom="http://www.w3.org/2005/Atom">Hello, world !</title>) ffunction inc.
  • 17. Interpreter scala> println( List("Hello","world !") match { case head :: tail => tail.foldLeft(head)( (a:String,b:String)=>{a+", " +b})}) Hello, world ! ffunction inc.
  • 18. Scala – the sublime* *SUBLIME : pleasure + pain, according to the Romantics ffunction inc.
  • 19. The almost ML-grade type system val f:List[Int] = List[1,2,3] val m:Map[String,List[Int]] = Map( “a” → [1,2,3], “b” → [4,5,6] ) type JSONable = { def toJSON():String } > ensure constraints at compile-type, speed up programs ffunction inc.
  • 20. Multiple method dispatch def merge( def merge( a:Map[String,Object], a:List[Object], b:Map[String,Object] b:List[Object] ):Map[String,Object] ):List[Object] > makes it easy to specialize (existing) libraries ffunction inc.
  • 21. Pattern-matching val sum = { _ match { case head :: tail > head + sum (tail) case Nil > 0 } } > amazing for message-based communication and list manipulation ffunction inc.
  • 22. Actors import scala.actors.Actor._ actor { while (true) {println ("Hello from A") ; Thread.sleep(1)} } actor { while (true) {println ("Hello from B") ; Thread.sleep(1)} } Hello from A Hello from A Hello from A Hello from A Hello from A Hello from A Hello from A Hello from A Hello from A Hello from A Hello from A Hello from A Hello from B Hello from B Hello from B Hello from B Hello from B Hello from B Hello from A Hello from A Hello from A Hello from A Hello from A Hello from A Hello from B Hello from B Hello from B Hello from B Hello from B Hello from B Hello from A Hello from A Hello from A Hello from A Hello from A Hello from A Hello from B Hello from B Hello from B Hello from B Hello from B Hello from B Hello from A Hello from A Hello from A Hello from A Hello from A Hello from A Hello from B Hello from B Hello from B Hello from B Hello from B Hello from B Hello from A Hello from A Hello from A Hello from A Hello from A Hello from A Hello from B Hello from B Hello from B Hello from B Hello from B Hello from B Hello from A Hello from A Hello from A Hello from A Hello from A Hello from A Hello from B Hello from B Hello from B Hello from B Hello from B Hello from B Hello from A Hello from A Hello from A Hello from A Hello from A Hello from A ffunction inc.
  • 23. Message-passing import scala.actors.Actor._ val repeater = actor { while (true) { receive { case msg:String => println(this + ">" + msg) ; reply (msg) }}} actor { repeater ! "ping" while (true) { receive { case msg:String => println(this + ">" + msg) ; reply (msg) }}} ffunction inc.
  • 24. Le mot de la fin ffunction inc.
  • 25. Scala is cool ! ● Very powerful ● Hard to learn, long time to master ● Amazing complement to Python for research & performance-critical and scalable projects ● Easy to interface with Python ! ffunction inc.
  • 26. Merci ! www.ffctn.com sebastien@ffctn.com ffunction inc.