SlideShare a Scribd company logo
1 of 43
Download to read offline
© Equal Experts UK Ltd 2015 ‹#›
Why should I bother with functional
programming?
▪ Nuno Marques
▪ nmarques@equalexperts.com
▪ @nfma
© Equal Experts UK Ltd 2015 ‹#›
gone insane
back to sanity
conclusion
q&a
summary
© Equal Experts UK Ltd 2015 ‹#›
complexity
side-effects
state
composition
expression problem
compilation
apis
tools
concurrency
distributed systems
gone insane
© Equal Experts UK Ltd 2015 ‹#›
http://emergentuniverse.wikia.com/wiki/Rube_Goldberg_Machine
complexity
© Equal Experts UK Ltd 2015 ‹#›
http://www.chinadaily.com.cn/opinion/2013-08/12/
side-effects
© Equal Experts UK Ltd 2015 ‹#›
http://s2.quickmeme.com/img/
state
© Equal Experts UK Ltd 2015 ‹#›
composition
© Equal Experts UK Ltd 2015 ‹#›
http://pictures.jokofy.com/cutest-mechanic/
expression problem
© Equal Experts UK Ltd 2015 ‹#›
https://pbs.twimg.com/media/B25NsvQCMAA1Ihd.jpg
compilation
© Equal Experts UK Ltd 2015 ‹#›
http://www.johnlund.com/page/1486/drooping-limp-hammer-bad-tools.asp
tools
© Equal Experts UK Ltd 2015 ‹#›
http://idm-thoughtplace.blogspot.se/
concurrency
© Equal Experts UK Ltd 2015 ‹#›
http://www.azquotes.com/author/28839-Leslie_Lamport
distributed systems
© Equal Experts UK Ltd 2015 ‹#›
▪composition
▪immutability
▪identity and state
▪referential transparency
▪parametricity
▪type classes
▪taming side-effects
▪concurrency
▪parallelism
back to sanity
© Equal Experts UK Ltd 2015 ‹#›
https://jordankasper.com/js-testing/#/
composition
© Equal Experts UK Ltd 2015 ‹#›
scala> val double: Int => Int = 2 * _
scala> val inc: Int => Int = _ + 1
scala> val incAndDouble = double compose inc
scala> incAndDouble(5)
res0: Int = 12
function composition example
© Equal Experts UK Ltd 2015 ‹#›
http://memegenerator.net/instance/55120894
immutability
© Equal Experts UK Ltd 2015 ‹#›
▪https://en.wikipedia.org/wiki/Persistent_data_structure
persistent data-structure
© Equal Experts UK Ltd 2015 ‹#›
http://www.railslove.com/stories/my-way-into-clojure-building-a-card-game-with-om-part-1
identity and state
© Equal Experts UK Ltd 2015 ‹#›
▪ http://www.javiersaldana.com/tech/2014/10/15/mental-models-for-concurrency.html
epochal time model
© Equal Experts UK Ltd 2015 ‹#›
http://teachers.henrico.k12.va.us/math/Newsletter/May14Newsletter.html
referential transparency
© Equal Experts UK Ltd 2015 ‹#›
scala> val double: Int => Int = 2 * _
scala> val inc: Int => Int = num => {
/* fire the missiles */
println("missiles fired”)
num + 1
}
scala> inc(5)
missiles fired
referencial transparency example
© Equal Experts UK Ltd 2015 ‹#›
http://memegenerator.net/instance/55195574
parametricity
© Equal Experts UK Ltd 2015 ‹#›
val unknown: Int => Int = ???
parametricity example
© Equal Experts UK Ltd 2015 ‹#›
val unknown: Int => Int = ???
val unknown: Boolean => Boolean = ???
parametricity example
© Equal Experts UK Ltd 2015 ‹#›
val unknown: Int => Int = ???
val unknown: Boolean => Boolean = ???
scala> val returnArgument = (a: Boolean) => a
scala> val returnFalse = (_: Boolean) => false
scala> val returnTrue = (_: Boolean) => true
scala> val returnOppositeOfArgument = (a: Boolean) => !a
parametricity example
© Equal Experts UK Ltd 2015 ‹#›
val unknown: Int => Int = ???
val unknown: Boolean => Boolean = ???
scala> val returnArgument = (a: Boolean) => a
scala> val returnFalse = (_: Boolean) => false
scala> val returnTrue = (_: Boolean) => true
scala> val returnOppositeOfArgument = (a: Boolean) => !a
val unknown: A => A = ???
parametricity example
© Equal Experts UK Ltd 2015 ‹#›
val unknown: Int => Int = ???
val unknown: Boolean => Boolean = ???
scala> val returnArgument = (a: Boolean) => a
scala> val returnFalse = (_: Boolean) => false
scala> val returnTrue = (_: Boolean) => true
scala> val returnOppositeOfArgument = (a: Boolean) => !a
val identity: (a: A) => a
parametricity example
© Equal Experts UK Ltd 2015 ‹#›
null
exceptions
Type-casing (isInstanceOf)
Type-casting (asInstanceOf)
Side-effects
equals/toString/hashCode
notify/wait
classOf/.getClass
General recursion
parametricity assumptions
© Equal Experts UK Ltd 2015 ‹#›
http://cdn.meme.am/instances/400x/49222894.jpg
type classes
© Equal Experts UK Ltd 2015 ‹#›
Prelude> :t (==)
(==) :: Eq a => a -> a -> Bool
Prelude> :t (*)
(*) :: Num a => a -> a -> a
  
type classes example
© Equal Experts UK Ltd 2015 ‹#›
class Eq a where  
(==) :: a -> a -> Bool  
(/=) :: a -> a -> Bool  
x == y = not (x /= y)  
x /= y = not (x == y)
data TrafficLight = Red | Yellow | Green
type classes example
© Equal Experts UK Ltd 2015 ‹#›
class Eq a where  
(==) :: a -> a -> Bool  
(/=) :: a -> a -> Bool  
x == y = not (x /= y)  
x /= y = not (x == y)
data TrafficLight = Red | Yellow | Green
instance Eq TrafficLight where  
    Red == Red = True  
    Green == Green = True  
    Yellow == Yellow = True  
    _ == _ = False
type classes example
© Equal Experts UK Ltd 2015 ‹#›
http://memegenerator.net/instance/54665385
taming side-effects
© Equal Experts UK Ltd 2015 ‹#›
(defn transfer[amount from to]
“atomically transfer amount between two accounts form and
to”
(dosync
(alter from - amount)
(alter to + amount)))
taming side-effects
© Equal Experts UK Ltd 2015 ‹#›
(defn memoize [f]
(let [mem (atom {})]
(fn [& args]
(if-let [e (find @mem args)]
(val e)
(let [ret (apply f args)]
(swap! mem assoc args ret)
ret)))))
(defn fib [n]
(if (<= n 1)
n
(+ (fib (dec n)) (fib (- n 2)))))
(memoize fib)
taming side-effects
© Equal Experts UK Ltd 2015 ‹#›
http://cdn5.raywenderlich.com/wp-content/uploads/2014/01/Thread_All_The_Code_Meme.jpg
concurrency and parallelism
© Equal Experts UK Ltd 2015 ‹#›
no-no: MS-DOS / single core
yes-no: Windows 95/98 / single core
no-yes: pinned cores to processes
yes-yes: today’s applications / multicore
concurrency and parallelism differences
© Equal Experts UK Ltd 2015 ‹#›
http://talks.joneisen.me/presentation-javascript-concurrency-patterns/img/meme-concurrency.jpg
concurrency
© Equal Experts UK Ltd 2015 ‹#›
import
scala.concurrent.ExecutionContext.implicits.global
val f = for {
a <- Future(10 / 2)
b <- Future(a + 1)
c <- Future(a - 1)
if c > 3
} yield b * c
concurrency example
© Equal Experts UK Ltd 2015 ‹#›
class HelloActor extends Actor {
  def receive = {
    case "hello" => println("hello back at you")
    case _       => println("huh?")
  }
}
 
object Main extends App {
  val system = ActorSystem("HelloSystem")
  // default Actor constructor
  val helloActor = system.actorOf(Props[HelloActor], name =
"helloactor")
  helloActor ! "hello"
  helloActor ! "buenos dias"
}
concurrency example
© Equal Experts UK Ltd 2015 ‹#›
(let [c1 (chan)
c2 (chan)]
(go (while true
(let [[v ch] (alts! [c1 c2])]
(println "Read" v "from" ch))))
(go (>! c1 "hi"))
(go (>! c2 "there")))
concurrency example
© Equal Experts UK Ltd 2015 ‹#›
me
conclusion
© Equal Experts UK Ltd 2015 ‹#›
http://www.troll.me/images/first-world-problems/done-with-my-presentation-now-i-have-to-answer-questions.jpg
q&a

More Related Content

Similar to Nuno

Build the Right Product Right: Transitioning Test from Critiquing to Defining
Build the Right Product Right: Transitioning Test from Critiquing to DefiningBuild the Right Product Right: Transitioning Test from Critiquing to Defining
Build the Right Product Right: Transitioning Test from Critiquing to DefiningTechWell
 
What’s new in VS 2015 and ALM 2015
What’s new in VS 2015 and ALM 2015What’s new in VS 2015 and ALM 2015
What’s new in VS 2015 and ALM 2015SSW
 
Brand New JavaScript - ECMAScript 2015
Brand New JavaScript - ECMAScript 2015Brand New JavaScript - ECMAScript 2015
Brand New JavaScript - ECMAScript 2015Gil Fink
 
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]David Buck
 
Agile Java Testing With Open Source Frameworks
Agile Java Testing With Open Source FrameworksAgile Java Testing With Open Source Frameworks
Agile Java Testing With Open Source FrameworksViraf Karai
 
Knockout in SharePoint: A Real-World Example of Components and Datatables
Knockout in SharePoint: A Real-World Example of Components and DatatablesKnockout in SharePoint: A Real-World Example of Components and Datatables
Knockout in SharePoint: A Real-World Example of Components and DatatablesSam Larko
 
Prioritizing Your Product Backlog
Prioritizing Your Product BacklogPrioritizing Your Product Backlog
Prioritizing Your Product BacklogMike Cohn
 
Web Performance Culture and Tools at Etsy
Web Performance Culture and Tools at EtsyWeb Performance Culture and Tools at Etsy
Web Performance Culture and Tools at EtsyMike Brittain
 
Essential Test-Driven Development
Essential Test-Driven DevelopmentEssential Test-Driven Development
Essential Test-Driven DevelopmentTechWell
 
Intermediate Microeconomics chapter 8 slides
Intermediate Microeconomics chapter 8 slidesIntermediate Microeconomics chapter 8 slides
Intermediate Microeconomics chapter 8 slidesjpvmdv4vg4
 
Prevent Test Automation Shelfware: A Selenium-WebDriver Case Study
Prevent Test Automation Shelfware: A Selenium-WebDriver Case StudyPrevent Test Automation Shelfware: A Selenium-WebDriver Case Study
Prevent Test Automation Shelfware: A Selenium-WebDriver Case StudyTechWell
 
Wai Aria - An Intro
Wai Aria - An IntroWai Aria - An Intro
Wai Aria - An IntroMatt Machell
 
Vertical Recommendation Using Collaborative Filtering
Vertical Recommendation Using Collaborative FilteringVertical Recommendation Using Collaborative Filtering
Vertical Recommendation Using Collaborative Filteringgorass
 
Asp.Net Mvc Internals &amp; Extensibility
Asp.Net Mvc Internals &amp; ExtensibilityAsp.Net Mvc Internals &amp; Extensibility
Asp.Net Mvc Internals &amp; ExtensibilityEyal Vardi
 
Drupal Govcon 2017 Polymer workshop slides
Drupal Govcon 2017 Polymer workshop slidesDrupal Govcon 2017 Polymer workshop slides
Drupal Govcon 2017 Polymer workshop slidesBryan Ollendyke
 
Swift: Apple's New Programming Language for iOS and OS X
Swift: Apple's New Programming Language for iOS and OS XSwift: Apple's New Programming Language for iOS and OS X
Swift: Apple's New Programming Language for iOS and OS XSasha Goldshtein
 
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Andrzej Jóźwiak
 
Paul Hofmann - Recruiting with Jenkins - How engineers can recruit engineers ...
Paul Hofmann - Recruiting with Jenkins - How engineers can recruit engineers ...Paul Hofmann - Recruiting with Jenkins - How engineers can recruit engineers ...
Paul Hofmann - Recruiting with Jenkins - How engineers can recruit engineers ...Codemotion
 

Similar to Nuno (20)

Build the Right Product Right: Transitioning Test from Critiquing to Defining
Build the Right Product Right: Transitioning Test from Critiquing to DefiningBuild the Right Product Right: Transitioning Test from Critiquing to Defining
Build the Right Product Right: Transitioning Test from Critiquing to Defining
 
What’s new in VS 2015 and ALM 2015
What’s new in VS 2015 and ALM 2015What’s new in VS 2015 and ALM 2015
What’s new in VS 2015 and ALM 2015
 
Refactoring
RefactoringRefactoring
Refactoring
 
Brand New JavaScript - ECMAScript 2015
Brand New JavaScript - ECMAScript 2015Brand New JavaScript - ECMAScript 2015
Brand New JavaScript - ECMAScript 2015
 
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
HotSpot Synchronization, A Peek Under the Hood [JavaOne 2015 CON7570]
 
Agile Java Testing With Open Source Frameworks
Agile Java Testing With Open Source FrameworksAgile Java Testing With Open Source Frameworks
Agile Java Testing With Open Source Frameworks
 
Knockout in SharePoint: A Real-World Example of Components and Datatables
Knockout in SharePoint: A Real-World Example of Components and DatatablesKnockout in SharePoint: A Real-World Example of Components and Datatables
Knockout in SharePoint: A Real-World Example of Components and Datatables
 
Prioritizing Your Product Backlog
Prioritizing Your Product BacklogPrioritizing Your Product Backlog
Prioritizing Your Product Backlog
 
Web Performance Culture and Tools at Etsy
Web Performance Culture and Tools at EtsyWeb Performance Culture and Tools at Etsy
Web Performance Culture and Tools at Etsy
 
Essential Test-Driven Development
Essential Test-Driven DevelopmentEssential Test-Driven Development
Essential Test-Driven Development
 
Intermediate Microeconomics chapter 8 slides
Intermediate Microeconomics chapter 8 slidesIntermediate Microeconomics chapter 8 slides
Intermediate Microeconomics chapter 8 slides
 
Prevent Test Automation Shelfware: A Selenium-WebDriver Case Study
Prevent Test Automation Shelfware: A Selenium-WebDriver Case StudyPrevent Test Automation Shelfware: A Selenium-WebDriver Case Study
Prevent Test Automation Shelfware: A Selenium-WebDriver Case Study
 
JavaMicroBenchmarkpptm
JavaMicroBenchmarkpptmJavaMicroBenchmarkpptm
JavaMicroBenchmarkpptm
 
Wai Aria - An Intro
Wai Aria - An IntroWai Aria - An Intro
Wai Aria - An Intro
 
Vertical Recommendation Using Collaborative Filtering
Vertical Recommendation Using Collaborative FilteringVertical Recommendation Using Collaborative Filtering
Vertical Recommendation Using Collaborative Filtering
 
Asp.Net Mvc Internals &amp; Extensibility
Asp.Net Mvc Internals &amp; ExtensibilityAsp.Net Mvc Internals &amp; Extensibility
Asp.Net Mvc Internals &amp; Extensibility
 
Drupal Govcon 2017 Polymer workshop slides
Drupal Govcon 2017 Polymer workshop slidesDrupal Govcon 2017 Polymer workshop slides
Drupal Govcon 2017 Polymer workshop slides
 
Swift: Apple's New Programming Language for iOS and OS X
Swift: Apple's New Programming Language for iOS and OS XSwift: Apple's New Programming Language for iOS and OS X
Swift: Apple's New Programming Language for iOS and OS X
 
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
 
Paul Hofmann - Recruiting with Jenkins - How engineers can recruit engineers ...
Paul Hofmann - Recruiting with Jenkins - How engineers can recruit engineers ...Paul Hofmann - Recruiting with Jenkins - How engineers can recruit engineers ...
Paul Hofmann - Recruiting with Jenkins - How engineers can recruit engineers ...
 

Recently uploaded

Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2
 
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2
 

Recently uploaded (20)

Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration Tooling
 

Nuno

  • 1. © Equal Experts UK Ltd 2015 ‹#› Why should I bother with functional programming? ▪ Nuno Marques ▪ nmarques@equalexperts.com ▪ @nfma
  • 2. © Equal Experts UK Ltd 2015 ‹#› gone insane back to sanity conclusion q&a summary
  • 3. © Equal Experts UK Ltd 2015 ‹#› complexity side-effects state composition expression problem compilation apis tools concurrency distributed systems gone insane
  • 4. © Equal Experts UK Ltd 2015 ‹#› http://emergentuniverse.wikia.com/wiki/Rube_Goldberg_Machine complexity
  • 5. © Equal Experts UK Ltd 2015 ‹#› http://www.chinadaily.com.cn/opinion/2013-08/12/ side-effects
  • 6. © Equal Experts UK Ltd 2015 ‹#› http://s2.quickmeme.com/img/ state
  • 7. © Equal Experts UK Ltd 2015 ‹#› composition
  • 8. © Equal Experts UK Ltd 2015 ‹#› http://pictures.jokofy.com/cutest-mechanic/ expression problem
  • 9. © Equal Experts UK Ltd 2015 ‹#› https://pbs.twimg.com/media/B25NsvQCMAA1Ihd.jpg compilation
  • 10. © Equal Experts UK Ltd 2015 ‹#› http://www.johnlund.com/page/1486/drooping-limp-hammer-bad-tools.asp tools
  • 11. © Equal Experts UK Ltd 2015 ‹#› http://idm-thoughtplace.blogspot.se/ concurrency
  • 12. © Equal Experts UK Ltd 2015 ‹#› http://www.azquotes.com/author/28839-Leslie_Lamport distributed systems
  • 13. © Equal Experts UK Ltd 2015 ‹#› ▪composition ▪immutability ▪identity and state ▪referential transparency ▪parametricity ▪type classes ▪taming side-effects ▪concurrency ▪parallelism back to sanity
  • 14. © Equal Experts UK Ltd 2015 ‹#› https://jordankasper.com/js-testing/#/ composition
  • 15. © Equal Experts UK Ltd 2015 ‹#› scala> val double: Int => Int = 2 * _ scala> val inc: Int => Int = _ + 1 scala> val incAndDouble = double compose inc scala> incAndDouble(5) res0: Int = 12 function composition example
  • 16. © Equal Experts UK Ltd 2015 ‹#› http://memegenerator.net/instance/55120894 immutability
  • 17. © Equal Experts UK Ltd 2015 ‹#› ▪https://en.wikipedia.org/wiki/Persistent_data_structure persistent data-structure
  • 18. © Equal Experts UK Ltd 2015 ‹#› http://www.railslove.com/stories/my-way-into-clojure-building-a-card-game-with-om-part-1 identity and state
  • 19. © Equal Experts UK Ltd 2015 ‹#› ▪ http://www.javiersaldana.com/tech/2014/10/15/mental-models-for-concurrency.html epochal time model
  • 20. © Equal Experts UK Ltd 2015 ‹#› http://teachers.henrico.k12.va.us/math/Newsletter/May14Newsletter.html referential transparency
  • 21. © Equal Experts UK Ltd 2015 ‹#› scala> val double: Int => Int = 2 * _ scala> val inc: Int => Int = num => { /* fire the missiles */ println("missiles fired”) num + 1 } scala> inc(5) missiles fired referencial transparency example
  • 22. © Equal Experts UK Ltd 2015 ‹#› http://memegenerator.net/instance/55195574 parametricity
  • 23. © Equal Experts UK Ltd 2015 ‹#› val unknown: Int => Int = ??? parametricity example
  • 24. © Equal Experts UK Ltd 2015 ‹#› val unknown: Int => Int = ??? val unknown: Boolean => Boolean = ??? parametricity example
  • 25. © Equal Experts UK Ltd 2015 ‹#› val unknown: Int => Int = ??? val unknown: Boolean => Boolean = ??? scala> val returnArgument = (a: Boolean) => a scala> val returnFalse = (_: Boolean) => false scala> val returnTrue = (_: Boolean) => true scala> val returnOppositeOfArgument = (a: Boolean) => !a parametricity example
  • 26. © Equal Experts UK Ltd 2015 ‹#› val unknown: Int => Int = ??? val unknown: Boolean => Boolean = ??? scala> val returnArgument = (a: Boolean) => a scala> val returnFalse = (_: Boolean) => false scala> val returnTrue = (_: Boolean) => true scala> val returnOppositeOfArgument = (a: Boolean) => !a val unknown: A => A = ??? parametricity example
  • 27. © Equal Experts UK Ltd 2015 ‹#› val unknown: Int => Int = ??? val unknown: Boolean => Boolean = ??? scala> val returnArgument = (a: Boolean) => a scala> val returnFalse = (_: Boolean) => false scala> val returnTrue = (_: Boolean) => true scala> val returnOppositeOfArgument = (a: Boolean) => !a val identity: (a: A) => a parametricity example
  • 28. © Equal Experts UK Ltd 2015 ‹#› null exceptions Type-casing (isInstanceOf) Type-casting (asInstanceOf) Side-effects equals/toString/hashCode notify/wait classOf/.getClass General recursion parametricity assumptions
  • 29. © Equal Experts UK Ltd 2015 ‹#› http://cdn.meme.am/instances/400x/49222894.jpg type classes
  • 30. © Equal Experts UK Ltd 2015 ‹#› Prelude> :t (==) (==) :: Eq a => a -> a -> Bool Prelude> :t (*) (*) :: Num a => a -> a -> a    type classes example
  • 31. © Equal Experts UK Ltd 2015 ‹#› class Eq a where   (==) :: a -> a -> Bool   (/=) :: a -> a -> Bool   x == y = not (x /= y)   x /= y = not (x == y) data TrafficLight = Red | Yellow | Green type classes example
  • 32. © Equal Experts UK Ltd 2015 ‹#› class Eq a where   (==) :: a -> a -> Bool   (/=) :: a -> a -> Bool   x == y = not (x /= y)   x /= y = not (x == y) data TrafficLight = Red | Yellow | Green instance Eq TrafficLight where       Red == Red = True       Green == Green = True       Yellow == Yellow = True       _ == _ = False type classes example
  • 33. © Equal Experts UK Ltd 2015 ‹#› http://memegenerator.net/instance/54665385 taming side-effects
  • 34. © Equal Experts UK Ltd 2015 ‹#› (defn transfer[amount from to] “atomically transfer amount between two accounts form and to” (dosync (alter from - amount) (alter to + amount))) taming side-effects
  • 35. © Equal Experts UK Ltd 2015 ‹#› (defn memoize [f] (let [mem (atom {})] (fn [& args] (if-let [e (find @mem args)] (val e) (let [ret (apply f args)] (swap! mem assoc args ret) ret))))) (defn fib [n] (if (<= n 1) n (+ (fib (dec n)) (fib (- n 2))))) (memoize fib) taming side-effects
  • 36. © Equal Experts UK Ltd 2015 ‹#› http://cdn5.raywenderlich.com/wp-content/uploads/2014/01/Thread_All_The_Code_Meme.jpg concurrency and parallelism
  • 37. © Equal Experts UK Ltd 2015 ‹#› no-no: MS-DOS / single core yes-no: Windows 95/98 / single core no-yes: pinned cores to processes yes-yes: today’s applications / multicore concurrency and parallelism differences
  • 38. © Equal Experts UK Ltd 2015 ‹#› http://talks.joneisen.me/presentation-javascript-concurrency-patterns/img/meme-concurrency.jpg concurrency
  • 39. © Equal Experts UK Ltd 2015 ‹#› import scala.concurrent.ExecutionContext.implicits.global val f = for { a <- Future(10 / 2) b <- Future(a + 1) c <- Future(a - 1) if c > 3 } yield b * c concurrency example
  • 40. © Equal Experts UK Ltd 2015 ‹#› class HelloActor extends Actor {   def receive = {     case "hello" => println("hello back at you")     case _       => println("huh?")   } }   object Main extends App {   val system = ActorSystem("HelloSystem")   // default Actor constructor   val helloActor = system.actorOf(Props[HelloActor], name = "helloactor")   helloActor ! "hello"   helloActor ! "buenos dias" } concurrency example
  • 41. © Equal Experts UK Ltd 2015 ‹#› (let [c1 (chan) c2 (chan)] (go (while true (let [[v ch] (alts! [c1 c2])] (println "Read" v "from" ch)))) (go (>! c1 "hi")) (go (>! c2 "there"))) concurrency example
  • 42. © Equal Experts UK Ltd 2015 ‹#› me conclusion
  • 43. © Equal Experts UK Ltd 2015 ‹#› http://www.troll.me/images/first-world-problems/done-with-my-presentation-now-i-have-to-answer-questions.jpg q&a