Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Improve our PHP code with ideas from Functional Programming

794 views

Published on

A short intro to Functional Programming (FP) and how ideas from it could be used to improve your PHP code. These slides contain several links to others (articles, video, book) about FP and PHP.

Published in: Software
  • Be the first to comment

Improve our PHP code with ideas from Functional Programming

  1. 1. Improving our PHP-code with ideas from Functional Programming ΛPHP Herman Peeren 010PHP, June11, 2015
  2. 2. Functional Programming • Non OOP (von Neumann) • no state, just functions (without side effects) • g(f(x)), etc.
  3. 3. No value-assignment needed • everything is a function (input - output - processing) • no mutable data Robert C Martin - “Uncle Bob”: Functional Programming; What? Why? When? https://www.youtube.com/watch?v=7Zlp9rKHGD4 Patkos Csaba: Functional Programming in PHP http://code.tutsplus.com/tutorials/functional-programming-in-php--net-35043
  4. 4. Imperative: HOW to do it $sum = 0; for($i = 1; $i <= 10; $i++) { $sum += $i; } // $sum = 55 Declarative: WHAT do I want array_sum(range(1, 10)); // 55
  5. 5. Advantages • data in - data out (testable) • no mutable data • functions = behaviour = first class citizens (modularity) • declarative style (readable, expressive) • modularity, reuse of code • lazy evaluation Jessica Kerr - @jessitron: Functional Principles for Object Oriented Development • JDD Conference 2013: https://www.youtube.com/watch?v=pMGY9ViIGNU • GOTO Chicago 2014: https://www.youtube.com/watch?v=GpXsQ-NIKXY
  6. 6. Some libraries • https://github.com/lstrojny/functional-php • https://github.com/reactphp/partial • http://brianhaveri.github.io/Underscore.php/ • https://github.com/nicmart/Functionals
  7. 7. Book • Simon Holywell • 122 pages • ed. php[architect] http://www.phparch.com/books/functional-programming-in-php/
  8. 8. Some more links on FP • C9 Lectures: Dr. Erik Meijer - Functional Programming Fundamentals Chapter 1 of 13 https://www.youtube.com/watch?v=UIUlFQH4Cvo • http://www.php5dp.com/php-functional-programming-part-i-an-introduction/ • http://www.php5dp.com/php-functional-programming-part-ii-oop-immutable-objects/

×