We look at a metaphor to explain the three domains in functional programming: actions, calculations, and data. I hope the metaphor makes some things clearer and can help people explain fp better to others.
Eric Normand: How is a cook like functional programming? Hi, my name is Eric Normand and these are my thoughts on functional programming.
I’ve been thinking about this superpower of being able to distinguish the different domains of functional programming — the actions, calculations, and data. Often, when you’re teaching, it’s really helpful to have a metaphor to show how these things interrelate. I came up with one.
Imagine a cook in the kitchen, cooking. This cook is doing all three — actions, calculations, and data. The actions are the cook’s hands. They’re what affect the world, hands. It could be other parts of the body, but just whatever the cook is doing in the world.
In the cook’s head are all the calculations. The calculations are, “I need to double this recipe because I’m having twice as many guests over as the recipe calls for,” or the cook needs to make a calculation of what ingredients they need from the fridge when they are planning their next trip to the fridge.
The stuff that is affecting the world is often like the more obvious stuff. It’s the email that got sent. It’s the file we got written to disk. That stuff is obvious. We often forget about all the things that are happening in someone’s head to get to that point so that they can actually be effective.
The stuff that is affecting the world is often like the more obvious stuff. It's the email that got sent. It's the file we got written to disk. That stuff is obvious. We forget about the things that are happening in someone's so that they can be effective.https://t.co/KsGyjrKqqF
— Eric Normand (@ericnormand) August 29, 2018
When you’re programming, if you’re not a functional programmer, you forget that there’s all these little calculations you’re doing all the time to actually have the right effect on the world or to set up the things so that you know what to do. This idea that it’s stuff that’s invisible — because it’s not having an effect on the world, you don’t notice it.
Then there’s the data. The data is the recipe that they’re following. The data is the mental note that I need a carrot to do the next thing. Next time I visit the fridge, I’m going to grab a carrot. There’s all these little bits of data that are just kind of floating around, that are being used in calculations.
Even your plan, the plan for what to cook next, that could be a piece of data. You generated that plan from calculations. You thought, “I’m going to do X, Y, Z, so I’m going to need do X first, and then the Y.” You’re making a plan. The plan might be data, but the planning, the process, is calculation because it’s not having an effect on the world.
Even the plan for what to cook next, that could be a piece of data. You generated that plan from calculations. You thought, “I’m going to do X, Y, Z.” You’re making a plan. The plan might be data, but the process is calculation.https://t.co/IilHrlvdDr
— Eric Normand (@ericnormand) August 20, 2018
All right, I just came up with this metaphor. It’s the first time I’ve really expressed it. I hope to tighten it up and make it a little bit clearer. If you see some cool stuff in there that I’m missing, like other correspondences between the three domains and the metaphor, let me know because this could be really important for helping people understand the distinctions I’m trying to make.
Awesome. If you need to get in touch with me, you can find me on Twitter, @ericnormand with a D. If you want to email me, I love that, too. Please get in touch with me. I’m firstname.lastname@example.org. All right, see you next time.