Hacker News new | past | comments | ask | show | jobs | submit login

For 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.



You 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.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: