Advertisement

The 3 levels of functional thinking

The 3 levels of functional thinking I've noticed that people go through a certain journey when learning functional programming. I've classified it into three levels: 1) Distinction between Actions, Calculations, and Data; and learning to use them effectively 2) Higher-order thinking; and building abstractions from higher-order functions 3) Algebraic thinking; building coherent models with a focus on composition. This is a work in progress and I'd love your input.

►► Audio, Video, and Transcript available:
►► Subscribe on iTunes:

Transcript

What are the three levels of functional thinking?

In this episode, I'm going to talk about my thinking about progress through the skills and thought processes that go into functional programming. My name is Eric Normand, and I help people thrive with functional programming.

I want to say that this is a work-in-progress. It is one way of mapping out the skills and categorizing them as a progression of skills. It's not the only way, and I have no hard evidence about the skills being done in this order.

They are mostly anecdotal. I'm noticing that people might learn a bunch of stuff and then they get stuck or they're in a certain spot, and they're still progressing. They haven't learned this other thing yet. It's just me putting it together.

I'm not creating some model that people are going to have to stick to or anything. It's mostly a way to organize the material that I'm putting into my book.

Here are the three levels. Remember, work-in progress. I'd love to discuss it, but I'm not going to die on this sword or anything.

The first one is the awareness and use of the distinction of actions, calculations, and data. Actions are things that depend on time. They depend on when they're run and how many times they're run. They have effects on the world or are affected by the world.

Calculations are computations from inputs to outputs. They don't depend on time. If you give them the same inputs, they're going to give you the same output. Finally, data is facts about events. It's very inert. It doesn't do anything on its own or requires interpretation.

When you're in this first level, your main challenges are learning, with actions, how to deal with the time, how to manipulate time, to master it, so that you can guarantee the ordering of the actions when you need it guaranteed.

You can guarantee the things aren't running at the same time if they shouldn't be running at the same time, and guarantee that they happen the correct number of times. These are all the challenges that you face when you're dealing with actions.

Calculations, the challenge here is to start modeling your program in terms of things. It can be very difficult for people who are coming from another paradigm to not use mutable state, to model things more as data transformations as opposed to step-by-step instructions like in an algorithm.

You're learning to think about all the stuff that your program does that isn't really necessary to be done as a side effect, as an action. There are some side effects that are necessary. You want your program to send an email, that it's incorrect if it doesn't send an email. That isn't a necessary action.

Do you really need to use that global variable as scratch space for your algorithm? Probably not. If you don't use it, none of your users are going to be upset. It's still a correct program. That's an unnecessary action.

We, as functional programmers, tend to frown upon unnecessary actions, and we want to convert them into calculations. That's the challenge, learning how to do that. Sometimes it is relearning how to program even the simplest things using calculations instead of actions.

With the data, it's about modeling. It's about making sure that your data has the right structure to be able to support the algorithms that you need to do. It's capturing the data you need. All that stuff comes under data modeling. Those are the three things you're distinguishing as a functional programmer at level one. You're learning to work with that.

You keep learning and you eventually get to level two, which is where you have higher-order thinking. You've mastered doing stuff with immutable data and thinking of things as data transformation, and you start to realize that there's a lot of duplicated functionality.

functional programming,software engineering,clojure,java,javascript,haskell,functional programming tutorial,functional programming languages,functional programming course,theory of functional programming,functional programming advantages,functional programming benefits,

Post a Comment

0 Comments