It seems to me that functional programming is a great thing. It eliminates state and makes it much easier to automatically make code run in parallel.
Many programmers who were first taught imperative programming styles find it very difficult to learn functional programming, because it is so different. I began to wonder if programmers who were taught functional programming first would find it hard to begin imperative programming. It seems like it would not be as hard as the other way around, so I thought it would be a good thing if more programmers were taught functional programming first.
So, my question is, should functional programming be taught in school before imperative, and if so, why is it not more common to start with it?
Actually, some schools already do it this way around. Where I study (University of Copenhagen), they teach SML in the first semester, as an intro to programming. Then they teach Java afterwards, as an intro to OOP.
I think it works extremely well, and I agree with you it’s better than the other way around. Functional programming is fairly intuitive to someone who’s not (yet) a programmer. It maps much better to what we were taught as math in high school or earlier, so people who have not yet been exposed to imperative programming usually pick it up without too much trouble.
In fact, there’s a trend that people who are new to programming when they enroll pick SML up faster than those who’ve already learned Java or C++.
It seems like there’s a big conceptual jump in going from imperative to functional, but the reverse seems much easier to most. Students generally don’t find Java difficult when they’re exposed to that after learning SML. Once you know about the ‘pure’ concepts of programming, gluing on side effects is fairly straightforward. But if your entire understanding of programming is based in side effects, it’s much harder to imagine that anything is possible without them.
I think a big benefit of this approach is that functional programming principles become an essential part of your programming toolbox, rather than some esoteric add-on you might use if you want to show off. Even when programming in imperative languages, I think there’s a benefit in having your background in a functional language. Even when programming in something as low-level as C, there’s a benefit to thinking about minimizing state and side effects, and being used to the concept of higher-order functions (even though they’re not available in the language)