4 ms·
Functional languages are harder to learn than imperative languages, a big factor that I didn't see in this comment thread. With imperative code, you can just s
by cercatrova 6y ago
Functional languages are harder to learn than imperative languages, a big factor that I didn't see in this comment thread.
With imperative code, you can just spell out a for loop which makes intuitive sense. With functional code, you need to do so recursively, so you need at least some understanding of recursion, and perhaps even category theory for more complex examples or languages like Haskell.
Just that kind of complexity over an imperative language alone is why I surmise that functional languages haven't reached as much popularity.
- thewakalix 6y agoYou really don’t need to understand category theory to understand Haskell, or even recursion for simple examples. Recursion is frequently used to implement control structures that are either built-in or missing in imperative languages; users of these control structures don’t need to understand how they work. Which is simpler: for (int i = 0; i < n; i++) array[i]++; or map (+ 1) list Admittedly, most modern languages have something like foreach, but one of Haskell’s major advantages is that foreach can be implemented as a library function.
- cercatrova 6y agoFor most people, the first one is simpler. The second seems simpler to us as we've used functional languages, but there's a lot going on there. What is map? It's a function that acts on a structure using a function, ie a higher order function. What is (+ 1)? An anonymous function that will be used. Contrast this to the more natural idea of, for each item in the list, increment that value.
- Zababa 6y agoYou can argue exactly the same for the first example: what is for? Why is for a special construct and not a function? What is (int i = 0; i < n; i++)? What is array[i]++? What is n here? The functional approach allows you to only care about the what ("add 1 to each element of the list") instead of the how ("create a number that goes from 0 to the size of the list minus one (because our language is 0-indexed, because arrays are in fact directly related to how memory is laid out), then for each value of this number, take the value that's at this index in the array and increment it"). I'd argue that the functional approach is easier to learn, especially if you haven't had prior experience with programming. You also said earlier than functional is harder to learn because you have to use recursion to make for loop. That's not really true, you can just use functions like map which are already here. And when you start tackling recursive data structures like trees, recursion is easier to understand.