Ten reasons not to use a statically typed functional programming language
A rant against something I don't get
Last updated
Was this helpful?
A rant against something I don't get
Last updated
Was this helpful?
Are you fed up with all the hype about functional programming? Me too! I thought I'd rant about some reasons why sensible people like us should stay away from it.
Just to be clear, when I say "statically typed functional programming language", I mean languages that also include things such as type inference, immutability by default, and so on. In practice, this means Haskell and the ML-family (including OCaml and F#).
Like most programmers, I'm naturally conservative and I dislike learning new things. That's why I picked a career in IT.
I don't jump on the latest bandwagon just because all the "cool kids" are doing it -- I wait until things have matured and I can get some perspective.
To me, functional programming just hasn't been around long enough to convince me that it is here to stay.
Yes, I suppose some pedants will claim that and have been around almost as long as old favorites like Java and PHP, but I only heard of Haskell recently, so that argument doesn't wash with me.
And look at the baby of the bunch, . It's only seven years old, for Pete's sake! Sure, that may be a long time to a geologist, but in internet time, seven years is just the blink of an eye.
So, all told, I would definitely take the cautious approach and wait a few decades to see if this functional programming thing sticks around or whether it is just a flash in the pan.
I don't know about you, but the more lines of code I write, the more productive I feel. If I can churn out 500 lines of code in a day, that's a job well done. My commits are big, and my boss can see that I've been busy.
But when I written in a functional language with a good old C-like language, there's so much less code that it scares me.
I mean, just look at this code written in a familiar language:
and compare it with this:
If I did use this approach, my productivity would drop drastically. I'm sorry -- I just can't afford it.
And that's another thing. What's up with all these languages that get rid of curly braces. How can they call themselves real programming languages?
I'll show you what I mean. Here's a code sample with familiar curly braces.
And here's some similar code, but without curly braces.
Look at the difference! I don't know about you, but I find the second example a bit disturbing, as if something important is missing.
To be honest, I feel a bit lost without the guidance that curly braces give me.
Proponents of functional languages claim that type inference makes the code cleaner because you don't have to clutter your code with type declarations all the time.
Here's a function signature for some ML-ish code. There are no type declarations needed and all types are inferred automatically.
And here's the function signature for similar code in C#, with explicit type declarations.
I may be in the minority here, but I like the second version much better. It's important to me to know that the return is of type IEnumerable<IGrouping<TKey, TSource>>
.
Sure, the compiler will type check this for you and warn you if there is a type mismatch. But why let the compiler do the work when your brain can do it instead?
Ok, I admit that if you do use generics, and lambdas, and functions that return functions, and all the other newfangled stuff, then yes, your type declarations can get really hairy and complex. And it gets really hard to type them properly.
But I have an easy fix for that -- don't use generics and don't pass around functions. Your signatures will be much simpler.
To me, there's nothing quite like the thrill of the hunt -- finding and killing a nasty bug. And if the bug is in a production system, even better, because I'll be a hero as well.
That's a bummer.
And talking of bug fixing, I spend most of my day in the debugger, stepping through code. Yes, I know I should be using unit tests, but easier said than done, OK?
I'm told that you do have to spend a lot of time up front getting the types to match up, but once that is done and it compiles successfully, there is nothing to debug. Where's the fun in that?
Which brings me to...
All this matching up types and making sure everything is perfect sounds tiring to me.
In fact, I hear that you are forced to think about all the possible edge cases, and all the possible error conditions, and every other thing that could go wrong. And you have to do this at the beginning -- you can't be lazy and postpone it till later.
I'd much rather get everything (mostly) working for the happy path, and then fix bugs as they come up.
Haha! Just kidding! Of course I can't be bothered to put null-checking code everywhere. I'd never get any real work done.
But I don't see any mention of patterns in functional design. How can you get useful stuff done without Strategy, AbstractFactory, Decorator, Proxy, and so on?
Perhaps the functional programmers are not aware of them?
Here's some more code for calculating the sum of squares. This is way too hard to understand because of all the weird symbols in it.
But I do hear that functional programs use strange symbols like <*>
and >>=
and obscure concepts called "monads" and "functors".
I don't know why the functional people couldn't stick with things I already know -- obvious symbols like ++
and !=
and easy concepts such as "inheritance" and "polymorphism".
You know what. I don't get it. I don't get why functional programming is useful.
UPDATE: So now I've read the "everything you need to know on one page" page. But it's too short and simplistic for me.
That's 17 lines vs. only 2 lines.
Well, as it happens, I like to see type declarations. I feel uncomfortable if I don't know the exact type of every parameter. That's why is my favorite language.
But that in statically typed functional languages, it is much harder to introduce bugs.
Anyway, apparently with these statically typed functional languages, .
I'm very conscientious about on every method. It gives me great satisfaction to know that my code is completely bulletproof as a result.
But I've only ever had to deal with one bad crash caused by a NPE. And the business didn't lose too much money during the few weeks I spent looking for the problem. So I'm not sure why this is such a .
I first read about design patterns in the (for some reason it's referred to as the Gang of Four book, but I'm not sure why), and since then I have been diligent in using them at all times for all problems. It certainly makes my code look serious and "enterprise-y", and it impresses my boss.
Oops, sorry! My mistake. That was .
What I'd really like is for someone to just show me some , instead of giving me too much information.
I'm really looking for something with a bit more depth -- I can my teeth .
And no, don't say that I should read , and , and write my own code. I just want to grok it without doing all of that work.
I don't want to have to just to learn a new paradigm.