SlideShare a Scribd company logo
The Imminent Threat
   of Functional Programming
Dimitry Solovyov
‣   Haskell enthusiast and FP proponent
‣   Heavy user of Underscore (FP library for JavaScript)
‣   Former assistant teacher of FP course at TTI
‣   Developer at Amber Games and Livesheets
dresdencodak.com
FUNCTIONAL
PROGRAMMING
In programming land,
there are two kinds of problems
In programming land,
there are two kinds of problems




                   memory
                 management
In programming land,
      there are two kinds of problems




sequencing                     memory
(aka do it in what order?)   management
In programming land,
      there are two kinds of problems




sequencing                     memory
                                    E D
                                  LV
                             management
(aka do it in what order?)
                               SO
In programming land,
      there are two kinds of problems




                                    memory D                *
sequencing                              VE
(aka do it in what order?)
                                     O L
                                  management
                                    S
                             * Except for null pointer exceptions ;-)
In programming land,
      there are two kinds of problems


           ?
                                    memory D                *
sequencing                              VE
(aka do it in what order?)
                                     O L
                                  management
                                    S
                             * Except for null pointer exceptions ;-)
Sequencing in Java

   while cond stmt
  do stmt while cond
for init cond step stmt
   for x : xs stmt
Sequencing in Ruby
       loop stmt
   while cond stmt
   until cond stmt
   stmt while cond
   stmt until cond
   for x in xs stmt
     xs each stmt
     n times stmt
    n upto m stmt
   n downto m stmt
          ...
Sequencing in Ruby
                   loop stmt
               while cond stmt
How elegant!   until cond stmt
               stmt while cond
               stmt until cond
               for x in xs stmt
                 xs each stmt
                 n times stmt
                n upto m stmt
               n downto m stmt
                      ...
Imperative programming in a nutshell


10   BEGIN
20   DO SOMETHING
30
40
     DO THAT OTHER THING
     GOTO 20                       ✔
INSTRUCTIONS                     RESULT
Declarative programming in a nutshell



Dear computer,
I want a pony.
                    MAGIC         ✔
DESCRIPTION                     RESULT
INSTANT
SUCCESS
“        OO makes code understandable by
                encapsulating moving parts.

              FP makes code understandable by
                  minimizing moving parts.
                                                   ”
                                  -- Michael Feathers

“Functional Programming in C++”
      http://goo.gl/aVSXX
Abstraction and reusability in FP


Absolutely abstract
                               Category theory *
            ly reu sable
       High
 Exciting
            ly comp
                   osable
                             Mathematically proven
   Ex tremely fun              to be composable


                            * Check out Scalaz for CT in Scala
                              Guava for other FP patterns in Java
+
                  Some GoF pattern analogs
                  provided at semantic level


“Design Patterns in Haskell”
    http://goo.gl/T0Evt
You can get away without
      encapsulating in objects


                   Data types




                                 fo
                                 rm
               r
             fo




                                  ed
             d
          ne




                                      in
                                      to
        ig
         s
      de




                    operate on      Immutable
Combinators
                                  data structures
You can get away without
      encapsulating in objects


                   Data types




                                 fo
                                 rm
               r
             fo




                                  ed
             d
          ne




                                      in
                                      to
        ig
         s
      de




                    operate on      Immutable
Combinators
                                  data structures
You can get away without
      encapsulating in objects


                   Data types
              Ready for the
             age of multicore


                                 fo
                                 rm
               r
             fo




                                  ed
             d
          ne




                                      in
                                      to
        ig
         s
      de




                    operate on      Immutable
Combinators
                                  data structures
Traits instead of inheritance

        Thesis: Inheriting state creates brittle software.
                     Inheriting implementation tends to
                     become useless over time.




“Life without Objects”
 http://goo.gl/wlOyq
Traits instead of inheritance

        Thesis: Inheriting state creates brittle software.
                     Inheriting implementation tends to
                     become useless over time.


                              A
                          B                      Data type

“Life without Objects”
                              C                 Expected to behave
                                                  like A, B, and C
 http://goo.gl/wlOyq
“         In the exclusive sense, functional
                     means no side-effects.

               In the inclusive sense it means a
             programming style which composes
                 functions in interesting ways.
                                                     ”
                                     -- Martin Odersky

“In Defense of Pattern Matching”
      http://goo.gl/HaKQD
Origin of the “functional style”


  LISP                      ML
Common Lisp            Standard ML
  Scheme                  OCaml
   Dylan                    F#
  Racket                 Haskell
  Closure JVM              Frege JVM
                          Scala * JVM


                    * (cough) Close enough.
LISP                     ML

 Dynamic               Strong types
Code = data           Type inference
Metaproggin'               ADTs

       First-class functions
      Higher-order functions
        Pattern matching
LISP                     ML

 Dynamic               Strong types
Code = data           Type inference
Metaproggin'               ADTs

       First-class functions
      Higher-order functions
        Pattern matching
Linus says:
 “Words are cheap,
  show me the code.”
Fake first-class functions in Java

interface Func<A, B> {
    B apply(A x);
}



static <A, B, C> Func<A, C> compose(final Func<A, B> f,
                                    final Func<B, C> g) {
    return new Func<A, C>() {
        public C apply(A x) {
            return g.apply(f.apply(x));
        }
    };
}
Fake higher-order functions in Java



 static <A, B> List<B> map(final Iterable<A> xs,
                           final Func<A, B> f) {
     List<B> ys = new ArrayList<B>();
     for (A x : xs) {
         B y = f.apply(x);
         ys.add(y);
     }
     return ys;
 }
                                    map
Fake higher-order functions in Java



 static <A, B> B fold(final Iterable<A> xs,
                      final B init,
                      final Func2<A, B, B> f) {
     B acc = init;
     for (A x : xs) {
         acc = f.apply(x, acc);
     }
     return acc;
 }
                                     fold
REFERENTIAL
TRANSPARENCY
How logic works


  x=1
  y=2
  x+y=3
in languages
     How logic works with side-effects


         x=1
         y=2
         x + y = 3*


* But only if the moon is still young!
  Otherwise the answer is 5.
Functional programming on the JVM




                                   en l


                                 fe d
                               tio ss



                               ar ia


                              ef le



                              ch n
                            c o cy


                                       s
                           nc cla



                           sp nt
                  es




                           at er
                           e- rol
                                    ct
                                   ns




                                     g
                         an re




                                  in
              ur




                         m att
                         fu st-




                        sid nt
                       tr efe
             os




                              p
                            fir
             cl




                            r
   Clojure    ✔          ✔   ✔   ✘   ✘
   Fantom     ✔          ✔   ✔   ✘   ✘
    Frege     ✔          ✔   ✔   ✔   ✔
     Java     ✔          ✘   ✘   ✘   ✘
    JRuby     ✔          ✘   ✘   ✘   ✘
    Kotlin    ✔          ✔   ✔   ✘   ✔
    Scala     ✔          ✔   ✔   ✘   ✔
FP exploration checklist

❏ Start learning a functional language:
   Scala, Clojure, or even Haskell
❏ Get together @ Latvian FP Group:
   look for it on LinkedIn      http://goo.gl/YhlJl


❏ Talk to me!   dimituri@gmail.com

More Related Content

Similar to Dimitry Solovyov - The imminent threat of functional programming (20)

PPT
Course1
Constantin Nicolae
 
PPTX
Introduction to Clojure and why it's hot for Sart-Ups
edlich
 
PPTX
unsplitted slideshare
Daniel Gomez-Prado
 
PDF
Why we cannot ignore Functional Programming
Mario Fusco
 
KEY
Five Languages in a Moment
Sergio Gil
 
PDF
Functional Programming 之二三事
Leeheng Ma
 
PDF
Data Structures and Algorithms
Pierre Vigneras
 
PPTX
Good functional programming is good programming
kenbot
 
PDF
From programming to software engineering: ICSE keynote slides available
Celso Martins
 
PPTX
a brief explanation on the topic of Imperative Programming Paradigm.pptx
sajit20
 
PDF
Functional Concepts for OOP Developers
brweber2
 
PDF
Peyton jones-2011-type classes
Takayuki Muranushi
 
PDF
Scala Functional Patterns
league
 
PPT
Unit 2 Principles of Programming Languages
Vasavi College of Engg
 
PPTX
Data structures using C
Pdr Patnaik
 
PPTX
Ds12 140715025807-phpapp02
Salman Qamar
 
PDF
Ti1220 Lecture 7: Polymorphism
Eelco Visser
 
PDF
Clojure values
Christophe Grand
 
PDF
The Next Great Functional Programming Language
John De Goes
 
PDF
Algorithm chapter 1
chidabdu
 
Introduction to Clojure and why it's hot for Sart-Ups
edlich
 
unsplitted slideshare
Daniel Gomez-Prado
 
Why we cannot ignore Functional Programming
Mario Fusco
 
Five Languages in a Moment
Sergio Gil
 
Functional Programming 之二三事
Leeheng Ma
 
Data Structures and Algorithms
Pierre Vigneras
 
Good functional programming is good programming
kenbot
 
From programming to software engineering: ICSE keynote slides available
Celso Martins
 
a brief explanation on the topic of Imperative Programming Paradigm.pptx
sajit20
 
Functional Concepts for OOP Developers
brweber2
 
Peyton jones-2011-type classes
Takayuki Muranushi
 
Scala Functional Patterns
league
 
Unit 2 Principles of Programming Languages
Vasavi College of Engg
 
Data structures using C
Pdr Patnaik
 
Ds12 140715025807-phpapp02
Salman Qamar
 
Ti1220 Lecture 7: Polymorphism
Eelco Visser
 
Clojure values
Christophe Grand
 
The Next Great Functional Programming Language
John De Goes
 
Algorithm chapter 1
chidabdu
 

More from Dmitry Buzdin (20)

PDF
How Payment Cards Really Work?
Dmitry Buzdin
 
PDF
Как построить свой фреймворк для автотестов?
Dmitry Buzdin
 
PDF
How to grow your own Microservice?
Dmitry Buzdin
 
PDF
How to Build Your Own Test Automation Framework?
Dmitry Buzdin
 
PDF
Delivery Pipeline for Windows Machines
Dmitry Buzdin
 
PPTX
Big Data Processing Using Hadoop Infrastructure
Dmitry Buzdin
 
PDF
Developing Useful APIs
Dmitry Buzdin
 
PPTX
Whats New in Java 8
Dmitry Buzdin
 
PPTX
Архитектура Ленты на Одноклассниках
Dmitry Buzdin
 
PDF
Dart Workshop
Dmitry Buzdin
 
PDF
Riding Redis @ask.fm
Dmitry Buzdin
 
PDF
Rubylight JUG Contest Results Part II
Dmitry Buzdin
 
PDF
Rubylight Pattern-Matching Solutions
Dmitry Buzdin
 
PDF
Refactoring to Macros with Clojure
Dmitry Buzdin
 
PPTX
Poor Man's Functional Programming
Dmitry Buzdin
 
PDF
Rubylight programming contest
Dmitry Buzdin
 
PPTX
Continuous Delivery
Dmitry Buzdin
 
PPTX
Introduction to DevOps
Dmitry Buzdin
 
PDF
Thread Dump Analysis
Dmitry Buzdin
 
PDF
Pragmatic Java Test Automation
Dmitry Buzdin
 
How Payment Cards Really Work?
Dmitry Buzdin
 
Как построить свой фреймворк для автотестов?
Dmitry Buzdin
 
How to grow your own Microservice?
Dmitry Buzdin
 
How to Build Your Own Test Automation Framework?
Dmitry Buzdin
 
Delivery Pipeline for Windows Machines
Dmitry Buzdin
 
Big Data Processing Using Hadoop Infrastructure
Dmitry Buzdin
 
Developing Useful APIs
Dmitry Buzdin
 
Whats New in Java 8
Dmitry Buzdin
 
Архитектура Ленты на Одноклассниках
Dmitry Buzdin
 
Dart Workshop
Dmitry Buzdin
 
Riding Redis @ask.fm
Dmitry Buzdin
 
Rubylight JUG Contest Results Part II
Dmitry Buzdin
 
Rubylight Pattern-Matching Solutions
Dmitry Buzdin
 
Refactoring to Macros with Clojure
Dmitry Buzdin
 
Poor Man's Functional Programming
Dmitry Buzdin
 
Rubylight programming contest
Dmitry Buzdin
 
Continuous Delivery
Dmitry Buzdin
 
Introduction to DevOps
Dmitry Buzdin
 
Thread Dump Analysis
Dmitry Buzdin
 
Pragmatic Java Test Automation
Dmitry Buzdin
 
Ad

Recently uploaded (20)

PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PDF
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Ad

Dimitry Solovyov - The imminent threat of functional programming

  • 1. The Imminent Threat of Functional Programming
  • 2. Dimitry Solovyov ‣ Haskell enthusiast and FP proponent ‣ Heavy user of Underscore (FP library for JavaScript) ‣ Former assistant teacher of FP course at TTI ‣ Developer at Amber Games and Livesheets
  • 5. In programming land, there are two kinds of problems
  • 6. In programming land, there are two kinds of problems memory management
  • 7. In programming land, there are two kinds of problems sequencing memory (aka do it in what order?) management
  • 8. In programming land, there are two kinds of problems sequencing memory E D LV management (aka do it in what order?) SO
  • 9. In programming land, there are two kinds of problems memory D * sequencing VE (aka do it in what order?) O L management S * Except for null pointer exceptions ;-)
  • 10. In programming land, there are two kinds of problems ? memory D * sequencing VE (aka do it in what order?) O L management S * Except for null pointer exceptions ;-)
  • 11. Sequencing in Java while cond stmt do stmt while cond for init cond step stmt for x : xs stmt
  • 12. Sequencing in Ruby loop stmt while cond stmt until cond stmt stmt while cond stmt until cond for x in xs stmt xs each stmt n times stmt n upto m stmt n downto m stmt ...
  • 13. Sequencing in Ruby loop stmt while cond stmt How elegant! until cond stmt stmt while cond stmt until cond for x in xs stmt xs each stmt n times stmt n upto m stmt n downto m stmt ...
  • 14. Imperative programming in a nutshell 10 BEGIN 20 DO SOMETHING 30 40 DO THAT OTHER THING GOTO 20 ✔ INSTRUCTIONS RESULT
  • 15. Declarative programming in a nutshell Dear computer, I want a pony. MAGIC ✔ DESCRIPTION RESULT
  • 17. OO makes code understandable by encapsulating moving parts. FP makes code understandable by minimizing moving parts. ” -- Michael Feathers “Functional Programming in C++” http://goo.gl/aVSXX
  • 18. Abstraction and reusability in FP Absolutely abstract Category theory * ly reu sable High Exciting ly comp osable Mathematically proven Ex tremely fun to be composable * Check out Scalaz for CT in Scala Guava for other FP patterns in Java
  • 19. + Some GoF pattern analogs provided at semantic level “Design Patterns in Haskell” http://goo.gl/T0Evt
  • 20. You can get away without encapsulating in objects Data types fo rm r fo ed d ne in to ig s de operate on Immutable Combinators data structures
  • 21. You can get away without encapsulating in objects Data types fo rm r fo ed d ne in to ig s de operate on Immutable Combinators data structures
  • 22. You can get away without encapsulating in objects Data types Ready for the age of multicore fo rm r fo ed d ne in to ig s de operate on Immutable Combinators data structures
  • 23. Traits instead of inheritance Thesis: Inheriting state creates brittle software. Inheriting implementation tends to become useless over time. “Life without Objects” http://goo.gl/wlOyq
  • 24. Traits instead of inheritance Thesis: Inheriting state creates brittle software. Inheriting implementation tends to become useless over time. A B Data type “Life without Objects” C Expected to behave like A, B, and C http://goo.gl/wlOyq
  • 25. In the exclusive sense, functional means no side-effects. In the inclusive sense it means a programming style which composes functions in interesting ways. ” -- Martin Odersky “In Defense of Pattern Matching” http://goo.gl/HaKQD
  • 26. Origin of the “functional style” LISP ML Common Lisp Standard ML Scheme OCaml Dylan F# Racket Haskell Closure JVM Frege JVM Scala * JVM * (cough) Close enough.
  • 27. LISP ML Dynamic Strong types Code = data Type inference Metaproggin' ADTs First-class functions Higher-order functions Pattern matching
  • 28. LISP ML Dynamic Strong types Code = data Type inference Metaproggin' ADTs First-class functions Higher-order functions Pattern matching
  • 29. Linus says: “Words are cheap, show me the code.”
  • 30. Fake first-class functions in Java interface Func<A, B> { B apply(A x); } static <A, B, C> Func<A, C> compose(final Func<A, B> f, final Func<B, C> g) { return new Func<A, C>() { public C apply(A x) { return g.apply(f.apply(x)); } }; }
  • 31. Fake higher-order functions in Java static <A, B> List<B> map(final Iterable<A> xs, final Func<A, B> f) { List<B> ys = new ArrayList<B>(); for (A x : xs) { B y = f.apply(x); ys.add(y); } return ys; } map
  • 32. Fake higher-order functions in Java static <A, B> B fold(final Iterable<A> xs, final B init, final Func2<A, B, B> f) { B acc = init; for (A x : xs) { acc = f.apply(x, acc); } return acc; } fold
  • 34. How logic works x=1 y=2 x+y=3
  • 35. in languages How logic works with side-effects x=1 y=2 x + y = 3* * But only if the moon is still young! Otherwise the answer is 5.
  • 36. Functional programming on the JVM en l fe d tio ss ar ia ef le ch n c o cy s nc cla sp nt es at er e- rol ct ns g an re in ur m att fu st- sid nt tr efe os p fir cl r Clojure ✔ ✔ ✔ ✘ ✘ Fantom ✔ ✔ ✔ ✘ ✘ Frege ✔ ✔ ✔ ✔ ✔ Java ✔ ✘ ✘ ✘ ✘ JRuby ✔ ✘ ✘ ✘ ✘ Kotlin ✔ ✔ ✔ ✘ ✔ Scala ✔ ✔ ✔ ✘ ✔
  • 37. FP exploration checklist ❏ Start learning a functional language: Scala, Clojure, or even Haskell ❏ Get together @ Latvian FP Group: look for it on LinkedIn http://goo.gl/YhlJl ❏ Talk to me! [email protected]