Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Harder? In what way and for whom?

I am suspicious of claims that procedural, imperative programming is “easier” than functional programming: in terms of how quickly one can learn it, how accurately one can predict what a program does by reading it, and how accurately one can make a modification. Assuming two developers both of equal experience in their preferred paradigms and languages I expect the functional programmer will score higher in these cases.

The cost of functional programming is that it does take some training to write programs in this style that many people are not familiar with. And I think it’s that lack of familiarity that people are referring to when they say that it is more “difficult.”

Personally I can’t disagree that it is harder to learn if you are already familiar with procedural programming. It took me quite a few months of dedicated work to get productive with Haskell. It was a painful, as I recall, because I had to throw out all of the accumulated experience I had with a handful of other languages.

Now that I am productive with it though I don’t find it any more “difficult” than programming in C or JavaScript or Python. In fact I find it easier: I can rely on the type system and reason about my programs and how they compose instead of stepping through their execution. Functional programming demands that I debug my thinking rather than my program most of the time. The former takes less time in my experience and becomes less frequent the more experienced you become.



Functional programming is routinely taught to complete beginners. Languages like Scheme or (core) ML are very simple and you can do a lot with surprisingly few constructs.

However, Haskell is in a different league in my opinion. If you want to do anything meaningful, you need monads which add some layers of complexity.

I consider myself a very experienced OCaml programmer, and I've been working casually for more than a year with Haskell, but I'm still much slower in Haskell. It still happens to me that I need one hour to figure out how to use some monad transformers, or specific API, to do something that would take me 10 minutes in another language. Well, probably I still need more practice, but the learning curve is certainly much higher for Haskell than Python.


Sure the learning curve demands more but the payoff is worth it. Monads, despite all the tutorials out there, are not that difficult a concept... once you learn it. It's frustrating to teach because of this. Like most things in mathematics it takes some effort to learn and pays off in spades. There are a ton of abstractions you get with learning monads and the rules of how they compose are consistent. It goes a long, long way. I'm better for having gotten through it.

Most abstractions in other languages though? Ad-hoc mish-mash of half-baked ideas with no laws and poor specifications. Each one you learn is absolutely useless when moving to the next program.

Monads are the same everywhere you go. Just like algebra.




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

Search: