SlideShare une entreprise Scribd logo
1  sur  59
Functional Programming
          on the JVM with
          Scala and Clojure
            What they are and why you should care


      Cristiano Breuel                         Thadeu Russo
Advisory Software Engineer              Advisory Software Engineer
   (cbreuel@br.ibm.com)                   (thadeurc@br.ibm.com)
Y = λf.(λx.f (x x)) (λx.f (x x))
Y = λf.(λx.f (x x)) (λx.f (x x))
What is functional programming
            about?
Lambda calculus (a.k.a λ-calculus)

  function definition

  function application

  recursion
Referential Integrity

  Avoids state and mutable data

Higher-Order functions:

  Functions can receive and return other
  functions

Lazy Evaluation:

  Evaluate an expression only when
  necessary
FP has been around since the 1950’s

   Why it is becoming more important now?
FP has been around since the 1950’s

   Why it is becoming more important now?
FP has been around since the 1950’s

   Why it is becoming more important now?




                Why should I care?
Because of them...
Because of them...



... the multi-core processors
Because of them...



... the multi-core processors

    (also, to become a smarter
             developer!)
On the other side...
On the other side...


 The JVM is cool!
JVM -> Java Language

Huge investment already on the JVM
(libraries, middleware, performance, GC,
remote communication, etc..)

JVM executes byte-code
The question is:
The question is:


    Why not create new (functional)
     languages on top of the JVM?
(not Closure)
Clojure has...
Clojure has...
... tight integration with the JVM and Java
Clojure has...
... tight integration with the JVM and Java

... compilation for performance
Clojure has...
... tight integration with the JVM and Java

... compilation for performance

... dynamic evaluation
Clojure has...
... tight integration with the JVM and Java

... compilation for performance

... dynamic evaluation

... memory-efficient immutable collections
Clojure has...
... tight integration with the JVM and Java

... compilation for performance

... dynamic evaluation

... memory-efficient immutable collections

... lazy sequences
Clojure has...
... tight integration with the JVM and Java

... compilation for performance

... dynamic evaluation

... memory-efficient immutable collections

... lazy sequences

... primitives for concurrency (STM, agents)
Clojure is a LISP
Clojure is a LISP


  (Lots of (Irritating
(Stupid (Parentheses))))
Clojure is a LISP


  (Lots of (Irritating
(Stupid (Parentheses))))



    a.k.a. List Processing
LISP
LISP


Homoiconicity - code is data
LISP


Homoiconicity - code is data

Macros
LISP


Homoiconicity - code is data

Macros

Multiple dispatch (multi-methods)
Syntax
              Operands
Operator     (arguments)


(str "Hello" "World")

           Expression
           delimiters
Syntax

["red" "green" "blue"]               Array

{:color "blue" :length 2}              Map

:color                             Keyword

#(even? %)               Anonymous function
Higher-Order Functions
Efficient Immutable
    Collections
Lazy Sequences
import java.util.HashMap;
import java.util.Map;



public class ColorMapper {

	   private static String[] COLORS = {"white", "blue"};
	
	   public static Map<String, String> mapLineColors(String[] values) {
	   	   Map<String, String> retVal = new HashMap<String, String>();
	   	   int i = 0;
	   	   for (String value: values) {
	   	   	    retVal.put(value, COLORS[i % COLORS.length]);
	   	   	    i++;
	   	   }
	   	   return retVal;
	   }
	
	   public static void main(String[] args) {
	   	
	   	   String[] values = {"Clojure", "Java", "Scala", "Visual Basic"};
	   	
	   	   System.out.println(mapLineColors(values));
	   }
	
}
Java Integration

(def now (new java.util.Date))

(def now (java.util.Date.))

(. now getTime)

(doto (JFrame.)
  (. add (JLabel. "Hello, Clojure!"))
  (. pack)
  (. show))
sample
Scala
Fast

Functional

Expressive

Statically typed (with type inference)

Concurrent
every value is an object

vals / vars

traits

companion objects

currying

closures / high order functions

pattern matching / case classes

XML literals

Lazy evaluation, and much more...
sample
To sum up...
We cannot choose our problems....

  .... but we can choose our tools.

It is our responsibility to figure out
           the “right” tool.
Even if you can't use
these languages in your
  day job yet, learning
 them will make you a
  better programmer!
References



http://clojure.org/

http://www.scala-lang.org/
Scala clojure techday_2011
Scala clojure techday_2011

Contenu connexe

Tendances

Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin Presentation
Andrzej Sitek
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 

Tendances (20)

Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
Functional Programming in Scala
Functional Programming in ScalaFunctional Programming in Scala
Functional Programming in Scala
 
Clojure, Plain and Simple
Clojure, Plain and SimpleClojure, Plain and Simple
Clojure, Plain and Simple
 
Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
 
Oscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simpleOscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simple
 
Scala eXchange opening
Scala eXchange openingScala eXchange opening
Scala eXchange opening
 
Scala: functional programming for the imperative mind
Scala: functional programming for the imperative mindScala: functional programming for the imperative mind
Scala: functional programming for the imperative mind
 
Functional Programming In Practice
Functional Programming In PracticeFunctional Programming In Practice
Functional Programming In Practice
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platform
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin Presentation
 
Aggregate Programming in Scala
Aggregate Programming in ScalaAggregate Programming in Scala
Aggregate Programming in Scala
 
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoWeaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
 
Generics Past, Present and Future
Generics Past, Present and FutureGenerics Past, Present and Future
Generics Past, Present and Future
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
Kotlin presentation
Kotlin presentation Kotlin presentation
Kotlin presentation
 
Intro to Akka Streams
Intro to Akka StreamsIntro to Akka Streams
Intro to Akka Streams
 
Generics Past, Present and Future (Latest)
Generics Past, Present and Future (Latest)Generics Past, Present and Future (Latest)
Generics Past, Present and Future (Latest)
 
Systematic Generation Data and Types in C++
Systematic Generation Data and Types in C++Systematic Generation Data and Types in C++
Systematic Generation Data and Types in C++
 
Collections forceawakens
Collections forceawakensCollections forceawakens
Collections forceawakens
 

Similaire à Scala clojure techday_2011

A Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingA Sceptical Guide to Functional Programming
A Sceptical Guide to Functional Programming
Garth Gilmour
 
Clojure and The Robot Apocalypse
Clojure and The Robot ApocalypseClojure and The Robot Apocalypse
Clojure and The Robot Apocalypse
elliando dias
 
Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lisp
elliando dias
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
David Padbury
 

Similaire à Scala clojure techday_2011 (20)

Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play framework
 
A Sceptical Guide to Functional Programming
A Sceptical Guide to Functional ProgrammingA Sceptical Guide to Functional Programming
A Sceptical Guide to Functional Programming
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
Clojure intro
Clojure introClojure intro
Clojure intro
 
Clojure and The Robot Apocalypse
Clojure and The Robot ApocalypseClojure and The Robot Apocalypse
Clojure and The Robot Apocalypse
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lisp
 
Functional Programming With Scala
Functional Programming With ScalaFunctional Programming With Scala
Functional Programming With Scala
 
Concurrency Constructs Overview
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overview
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.SE 20016 - programming languages landscape.
SE 20016 - programming languages landscape.
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Scala Introduction
Scala IntroductionScala Introduction
Scala Introduction
 
Functional programming with Scala
Functional programming with ScalaFunctional programming with Scala
Functional programming with Scala
 
Devoxx
DevoxxDevoxx
Devoxx
 
Clojure
ClojureClojure
Clojure
 
Hw09 Hadoop + Clojure
Hw09   Hadoop + ClojureHw09   Hadoop + Clojure
Hw09 Hadoop + Clojure
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
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
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

Scala clojure techday_2011

Notes de l'éditeur

  1. \n
  2. Thadeu e Cristiano: Apresenta&amp;#xE7;&amp;#xE3;o dos palestrantes\n
  3. Thadeu: Apenas assustar o pessoal - dizer que precisamos antes entender o combinador Y\n
  4. Thadeu: slide apenas de passagem, sem muitos comentarios.\n
  5. Thadeu: basicamente ler o slide.\n
  6. Thadeu: da wikipedia: is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data.\nenfatiza a aplicacao de funcoes ao contrario da mudanca de estado, como eh feito em linguagens interativas\n
  7. Thadeu: Parar em visual F# - lembrar de chamar aten&amp;#xE7;&amp;#xE3;o para sql e spredsheets\n
  8. Thadeu: Parar em visual F# - lembrar de chamar aten&amp;#xE7;&amp;#xE3;o para sql e spredsheets\n
  9. Thadeu: Parar em visual F# - lembrar de chamar aten&amp;#xE7;&amp;#xE3;o para sql e spredsheets\n
  10. Thadeu: Parar em visual F# - lembrar de chamar aten&amp;#xE7;&amp;#xE3;o para sql e spredsheets\n
  11. Thadeu: Parar em visual F# - lembrar de chamar aten&amp;#xE7;&amp;#xE3;o para sql e spredsheets\n
  12. Thadeu: Parar em visual F# - lembrar de chamar aten&amp;#xE7;&amp;#xE3;o para sql e spredsheets\n
  13. Thadeu: intrigar a plateia - perguntar se alguem sabe e nao deixar responder - comentar que as linguagens sempre foram vistar como muito teoricas para o mundo n&amp;#xE3;o academico\n
  14. Thadeu: intrigar a plateia - perguntar se alguem sabe e nao deixar responder - comentar que as linguagens sempre foram vistar como muito teoricas para o mundo n&amp;#xE3;o academico\n
  15. Thadeu: discutir um pouco os detalhes tecnicos do impacto\n
  16. Thadeu: discutir um pouco os detalhes tecnicos do impacto\n
  17. Thadeu passa para Cristiano.\n
  18. Cristiano:\n
  19. Cristiano:\n
  20. Cristiano:\n
  21. Cristiano:\n
  22. Cristiano:\n
  23. Cristiano:\n
  24. Cristiano:\n
  25. Cristiano:\n
  26. Cristiano:\n
  27. Cristiano:\n
  28. Cristiano:\n
  29. Cristiano:\n
  30. Cristiano:\n
  31. Cristiano:\n
  32. Cristiano:\n
  33. Cristiano:\n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. Thadeu: Comentar cada um dos itens acima (dizer tbm q eh menos verborragica que java) - veremos exemplo\n
  40. Thadeu: ir para o repl e fazer alguns exemplos destes caras\nval\nfunction as objects\nreduceLeft - usar as chaves e fazer o currying\n\n\nsobre a parte de lazy - comentar que nao existem lazy collections assim como em haskell ou closure, porem\nda para criar metodos que fazer conversoes de modo lazy (usando iteradores)\n
  41. Thadeu: Converter codigo java para scala\n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n