SlideShare uma empresa Scribd logo
1 de 26
Baixar para ler 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.

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDELiveplex
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 

Último (20)

COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 

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.