Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Functional Programming

Functional Programming

Ionuț G. Stan

November 14, 2011
Tweet

More Decks by Ionuț G. Stan

Other Decks in Programming

Transcript

  1. What is FP a programming style conceptually derived from lambda

    calculus (1930s) not procedural programming
  2. What is FP a programming style conceptually derived from lambda

    calculus (1930s) not procedural programming functions as in mathematical functions
  3. What is FP a programming style conceptually derived from lambda

    calculus (1930s) not procedural programming functions as in mathematical functions math function: input completely determines the output
  4. Imperative Programming programming: telling a computer what to do imperative

    languages are leaky abstractions also called von Neumann languages
  5. Imperative Programming programming: telling a computer what to do imperative

    languages are leaky abstractions also called von Neumann languages von Neumann architecture is about modifying the state of the computer
  6. Imperative Programming programming: telling a computer what to do imperative

    languages are leaky abstractions also called von Neumann languages von Neumann architecture is about modifying the state of the computer computation model in imperative languages reflects von Neumann architecture
  7. Imperative Programming programming: telling a computer what to do imperative

    languages are leaky abstractions also called von Neumann languages von Neumann architecture is about modifying the state of the computer computation model in imperative languages reflects von Neumann architecture imperative programming: what and how to do
  8. What is FP a programming style conceptually derived from lambda

    calculus (1930s) not procedural programming functions as in mathematical functions trying to plug the abstraction leak
  9. What is FP a programming style conceptually derived from lambda

    calculus (1930s) not procedural programming functions as in mathematical functions trying to plug the abstraction leak tell the computer what to do, not how
  10. What is FP a programming style conceptually derived from lambda

    calculus (1930s) not procedural programming functions as in mathematical functions trying to plug the abstraction leak tell the computer what to do, not how mutations not allowed (no variables, just identifiers)
  11. What is FP a programming style conceptually derived from lambda

    calculus (1930s) not procedural programming functions as in mathematical functions trying to plug the abstraction leak tell the computer what to do, not how mutations not allowed (no variables, just identifiers) no statements, just expressions (if/then/else is expression)
  12. What is FP a programming style conceptually derived from lambda

    calculus (1930s) not procedural programming functions as in mathematical functions trying to plug the abstraction leak tell the computer what to do, not how mutations not allowed (no variables, just identifiers) no statements, just expressions (if/then/else is expression) functions are deterministic and side-effect free
  13. What is FP a programming style conceptually derived from lambda

    calculus (1930s) not procedural programming functions as in mathematical functions trying to plug the abstraction leak tell the computer what to do, not how mutations not allowed (no variables, just identifiers) no statements, just expressions (if/then/else is expression) functions are deterministic and side-effect free functions are all we need to model computation
  14. What is FP a programming style conceptually derived from lambda

    calculus (1930s) not procedural programming functions as in mathematical functions trying to plug the abstraction leak tell the computer what to do, not how mutations not allowed (no variables, just identifiers) no statements, just expressions (if/then/else is expression) functions are deterministic and side-effect free functions are all we need to model computation execution order is not guaranteed
  15. Why FP easier to reason about programs heisenbugs race conditions

    off by one errors objects trashing another object's internal state
  16. Why FP easier to reason about programs easier to parallelize

    program correctness proving composability results in greater and easier reuse
  17. Just for fun - reuse in OO languages "You wanted

    a banana but what you got was a gorilla holding the banana and the entire jungle." Joe Armstrong, creator of Erlang
  18. Why FP easier to reason about programs easier to parallelize

    program correctness proving composability results in greater and easier reuse try out new perspectives
  19. How to FP avoid side-effects/mutation as much as possible at

    least keep them as private as possible in OO
  20. How to FP avoid side-effects/mutation as much as possible at

    least keep them as private as possible in OO treat variables as immutable (constants/final)
  21. How to FP avoid side-effects/mutation as much as possible at

    least keep them as private as possible in OO treat variables as immutable (constants/final) return values (output) based on params (input) only
  22. How to FP avoid side-effects/mutation as much as possible at

    least keep them as private as possible in OO treat variables as immutable (constants/final) return values (output) based on params (input) only play with a functional language
  23. "Conventional programming languages are growing ever more enormous, but not

    stronger. Inherent defects at the most basic level cause them to be both fat and weak: their primitive word- at-a-time style of programming inherited from their common ancestor -- the von Neumann computer, their close coupling of semantics to state transitions, their division of programming into a world of expressions and a world of statements, their inability to effectively use powerful combining forms for building new programs from existing ones, and their lack of useful mathematical properties for reasoning about programs." John Backus, known for Fortran, Algol and BNF