Skip to content

Instantly share code, notes, and snippets.

@vjeux
Last active January 6, 2024 07:15
Show Gist options
  • Star 33 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vjeux/cc2c4f83a6b60d69b79057b6ef651b56 to your computer and use it in GitHub Desktop.
Save vjeux/cc2c4f83a6b60d69b79057b6ef651b56 to your computer and use it in GitHub Desktop.
Ocaml / functional programming

I'm taking down this post. I just posted this as a side comment to explain a sentence on my latest blog post. This wasn't meant to be #1 on HN to start a huge war on functional programming... The thoughts are not well formed enough to have a huge audience. Sorry for all the people reading this. And please, don't dig through the history...

@tripl3dogdare
Copy link

@AlecBenzer I think you were missing the point of that quote - by far the majority of the problems he raised become non-issues to start with if you have a decent knowledge of functional programming, or are problems regardless of imperative/functional style. The main point of the comment you quoted, was to say (correctly) that many of the issues he raised stem entirely from approaching functional programming with an imperative mindset, rather than approaching functional programming with a functional mindset.

In a lot of cases, more succinct code is more readable code. FP actually wins in this case, as once you're beyond the initial learning curve, you begin to find that recursion, pattern matching, map/filter/reduce, and so on are actually more succinct, readable, and powerful ways to express the same concepts.

You're entirely right that readability, good naming, and so on are not "OOP things". However, that was entirely not the point - most of the issues people have with reading and understanding functional code come not from the code itself, but from viewing the code the same way you would imperative code. The underlying principles and concepts of the two styles are different - while they are similar in a lot of ways, it's nearly impossible to fully understand functional code if you try to look at it purely from an imperative standpoint. An open mind, a willingness to learn, and an understanding that the basic building blocks of the two styles are different; all of those are necessary to truly grokking with FP when transitioning from OOP.

@DrBoolean
Copy link

Pure FP makes code look/act/feel like math. Some believe this is more concise with guarantees, equational reasoning, and a universe of well-studied, ready to use, composable pieces. Others believe that programming is better off reading like a work of fiction, explaining each process in (mostly) english with data modeled as "real world" objects.

With the latter mindset, the above arguments seem obvious to me. But i think it's worth applying the criticisms to mathematics in general if we're thinking in the first mindset.

@vjeux
Copy link
Author

vjeux commented Dec 23, 2017

@tripl3dogdare thanks for the thorough response!

@oojr
Copy link

oojr commented Dec 23, 2017

Lambdas

<MyComponent onClick={(value)=> setNewValue(value)} />
<MyComponent onClick={(value)=> setNewValue(value)} />

Without Lambdas

<MyComponent onClick={this.incrementValue} />
<MyComponent onClick={this.decrementValue} />

less functions with lambdas but less readable too

@GheorgheP
Copy link

@vjeux, I think you are just misleading beginners in FP. As you can see all who know FP are telling you that you just need to practice more on FP to understand the benefits. This article is same thing like a beginner on plane will tell everyone that planes sucks and let's drive on cars only, because planes are not understandable at all (I don't want to compare planes with cars now, that was just a comparation ). Please just practice more, or not, but writing something like this being blind, is not professional. There are a lot of really good articles about FP downsides, even made by FP gurus, and there are very well described technical problems (hashmaps, trees, sorting).

@alecbz
Copy link

alecbz commented Dec 23, 2017

@tripl3dogdare

by far the majority of the problems he raised become non-issues to start with if you have a decent knowledge of functional programming

But the comment didn't point out how this was true, it just asserted that it was. (Unlike your own previous comment)

Like, you can use this argument to defend anything. "X isn't bad, you're just seeing X from a non-X perspective, so it seems bad". Ok.... but you need to explain how from some other sane perspective, X is good. Otherwise you're not ruling out the possibility that X is just a bad perspective to look at things from.

@andrejbauer
Copy link

I will join the crowd of people who say that this is an uninformed opinion by someone who does not know sufficiently well what they are talking about. Certain things take time to understand, and they cannot be explained easily in comments to a gist. People take whole courses in programming to get used to a new way of programming, be it functional, imperative or quantum computing. There's nothing wrong about not knowing functional programming, but I would respectfully advise that the next time around you phrase your objections as questions to the FP community, rather than uninformed criticism. You will get a much better reponse, and you might learn something instead of spend time arguing.

(My background: I do research in programming languages, and I teach theory of programming languages.)

@tinylucid
Copy link

But you missed the point of Functional Programming Paradigm. There were no constructive criticizm just some kind of personal opinion of what you do not like with FP in general. It is even potentially dangerous for newcomers and people that read it "from distance". I could go into detail with everything that I think didn't do the justice to FP, but I see no point in doing so.

@giuliohome
Copy link

Partial reply to the following point from your lists paragraph

you cannot easily go backwards

Here is a suggestion for a parent linked tree in a functional language (F#)

I consider the above point important because it has been mentioned even in the first paragraph of a recent article and because I believe that parent linked trees are really needed in real world e.g. to get the path of node. I guess this use case was missing.

@frankandrobot
Copy link

"passing values around (reduce)". so the alternative is the go style where everything is explicit. in practice the first problem is that it can be tedious to write. reduce/map are geared for increasing velocity because you can do the same with less. the second problem is that the explicitness can encourage bad practises. imagine mutating the first variable at the end of a long sequence of for loops... I'd argue that that can be just as bad if not worse.

the bottom line is that writing good code takes practice because it's an art.

@rwmjones
Copy link

rwmjones commented Dec 23, 2017

I've been programming OCaml for years and I too miss early returns. However there is a good solution. There was a long discussion about this on the OCaml mailing list a few months back, and there are various with_return modules. My contribution to the art is this implementation.

@jonsterling
Copy link

at least now I know it must be pretty easy to get a job at fb, in case i need a backup

@btnwtn
Copy link

btnwtn commented Dec 23, 2017

@jonsterling you seem like a wonderful person to work with.

Copy link

ghost commented Dec 23, 2017

There is a lot of really good reasons why functional programming isn't good for every use-case. It would be meaningless to enumerate them here as they're obvious if you take a bit of time to look for them. This gist (unfortunately) doesn't make any good arguments against using the paradigm :(

@goofballLogic
Copy link

Worth reading the history on this one

@Delaunay
Copy link

He is right, this is exactly how I felt when I first switched to functional programming.
Nevertheless, with time, you start to adapt yourself and get it and FP starts to make sense.

Although, I still dislike the way FP people thinks brevity increase readability... I mean look at APL, it is short.
Furthermore the examples they pick are always too simplistic to make a point.

Finally, the performance of FP is something I am very interested in and I was never able to found something about it.
I am also worried about the cache unfriendliness of lists but everybody seems to forget about processor cache when working on distributed systems, on a other side Scala does allow you to use arrays instead of lists and I am mainly using arrays anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment