Improve our PHP code with ideas from Functional Programming
-
Upload
herman-peeren -
Category
Software
-
view
244 -
download
3
Transcript of Improve our PHP code with ideas from Functional Programming
Improving our PHP-code with ideas from
Functional Programming
ΛPHP
Herman Peeren010PHP, June11, 2015
Functional Programming• Non OOP (von Neumann)• no state, just functions (without side effects)
• g(f(x)), etc.
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 PHPhttp://code.tutsplus.com/tutorials/functional-programming-in-php--net-35043
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
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
Some libraries
•https://github.com/lstrojny/functional-php•https://github.com/reactphp/partial•http://brianhaveri.github.io/Underscore.php/•https://github.com/nicmart/Functionals
Book
• Simon Holywell• 122 pages• ed. php[architect]
http://www.phparch.com/books/functional-programming-in-php/
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/