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.
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. 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.
6.
7.
8.
9.
10. 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
13. Book
• Simon Holywell
• 122 pages
• ed. php[architect]
http://www.phparch.com/books/functional-programming-in-php/
14. 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/