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

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - 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.