Get Functional

Sorry for the absence, it’s been a long road getting back here.

I hope you enjoy the ride.

Recently I’ve become fascinated with the concept of functional programming. For several years, I’ve had friends jump from language to language, but they all seem to settle on the functional side of the fence. “Why?” was the inevitable conundrum. For the longest time I couldn’t understand what it had to offer that you couldn’t do in other languages. Like most programming phenomena, it was an epiphanic moment that changed the way I looked at programming for the better forever.

Code is Data; Data is Code

Ok, omgwthbbq does this mean? How is code parseable data? How is data trustable code? For this, I had to rethink my stance on what makes a program an executable, not where the program comes from; it’s a cart-before-the-horse thing. So what makes a program? A program is executed lines of human-readable text compiled or interpreted but just the same converted into machine code before the processor reads the 1′s and 0′s from one stream and pushes a different set of 1′s and 0′s into another stream. Who cares how those lines got there. Could be from hand-entry, or it could be from a variable.
Epiphany the First: Who cares where we get code as long as it’s the right code we need?
PHP has this: variable function names, eval(), call_user_func(). After you start coding using these patterns, it becomes nearly impossible to think otherwise. All of a sudden, “Gee, it would be so much easier if we could just tell functionY about functionX without having to teach classB about classA.” We stop thinking in terms of step-by-grudging-step and into segmented solutions to problems. When we can just pass a function into functionY of classB, this problem disappears. classB doesn’t have to give one darn about classA, just that when it needs to, it can use functionX and the world will keep on spinning.
Epiphany the Second: What data can I trust?
Well, you can trust mine, silly! After all, I wrote it. Ah, so data doesn’t have to come from the user, it’s just a way of saying the A’s and underscores I put into the program can be used to reference other parts of the program without explicitly teaching them about each other. Data can come from anywhere, even code; and code can be executed from anything (with the right compiler/interpreter) including data.

Hopefully, this will spawn my first Git repository. Stay tuned for the linky!

[Edit July 7] Instead of a full-fledged repo, I just threw the PHP code up on gist.github.


About this entry