Functional PHP

Click to watch "Functional PHP"

Functional programming. Some see that term and think "functions? You mean procedural programming. I've been doing that for years." Others see it and think "you mean that crazy academic nonsense that no one understands? Pfft!"

In truth, functional programming is fundamentally an approach to software development, not a particular language or syntax. With PHP 5.3, it is an approach that is now more readily available and powerful than ever before. Even if you're not writing in Erlang or ML, there is still much to learn from the principles of functional programming to help write better code.

This session will discuss the history of functional programming and how it compares to other programming paradigms (procedural and object-oriented). We will then delve into how to leverage the concepts and tools in PHP 5.3 to produce more robust code with an "algorithm-first" approach.

Slides here, including useful links: http://www.garfieldtech.com/presentations/dcmunich2012-fp/

Speaker(s): 
Track: 
Coding and Development
Experience level: 
Intermediate
Time slot: 
Tuesday 14:15-15:15
Room: 
Ballsaal A/B

Comments

I was on the "academic nonsense" side. Looking forwar to you convincing me of a different view. :)

I look forward to convincing you. ;-) Teaser: It's about code flow, mental model, and avoiding unnecessary state data, not syntax.

I'm wondering how this session relates to Drupal. Obviously, we all want to write better code. :)

Can you provide an example (or list a couple of topics) of how Functional Programming might be a useful tool for adding or improving functionality in Core (or contrib)?

Well I don't want to give away too many secrets. :-) However, the idea is that you don't need to use a purely functional language to get the benefits of functional thinking. By that I mean focusing on routines (functions, methods) as self-contained atomic machines. No side effects. No persistent state. Isolate your I/O code from your business logic code. The latter should only know "I get X, I return Y", and nothing else. Instead of iterator tracking variables you have to think about, think of your code in map-reduce form: You have a set of data; apply a repeatable operation to every element in it. That makes the code easier to test, makes it easier to write (because there's fewer variables to account for), and easier to "see" as correct.

I don't have specific code examples yet obviously, but would develop some for the session if selected.

I can only say that session by Larry Garfield is going to be well worth our while to attend. I found your London session on "code smell" most memorable and useful. :-)

I remember your session on Code Smells in London and there were hints of functional ideas then in your thinking (namely, that functions should be 'pure'). But I wonder how possible it is to truly apply functional thinking to PHP before the language gets in the way. Functions (in PHP) are not first class, variables cannot be set as immutable, the data structures are pretty limited, etc. etc.

In either case, I think it is important for Drupal and Drupalers to be aware of, and take advantage of other programming styles so this session seems like a good idea.

Thanks for this pure bit of computer science Larry :-) Don't care that much about the academic aspect, the ability to mix and match based on the use case is a huge win.

My right ear loved this session

Is your left ear a die-hard OOP zealot, then? :-)

Why are you still on Drupal?

... sadly the video wouldn't play today. :(

From what you folks (volks?) are saying here, though and the abstract, it would leave me wondering about porting between platforms. I'm less than a week old in Drupal and like what I see, still I see what appears to be some unfinished work; possiblt abandoned.
I do pascal and program for the PC, mostly because I started there and want to master it instead of over-diversification. As a scientist, I write mostly for my own use, so never upgraded beyond Delphi 7, but I see that changing.
D7 allows for quite a bit of cross platform, but it is really obsolete, nonetheless a function is a function. It eventually spirals into an interrupt. Methods inherent to a taxonomy of classes. Currently I'd have to say OOP is up my alley (pun intended), still I can't help but wonder whether this will go by the wayside once AI becomes united with quantum computing and the associated nanotechnology of auto-replication at that quntum level.

Dr. C.