upvote
Each to their own I guess, by personally I really don't like closures (at least ones that as per their namesake, close over objects with nontrivial lifetimes).

I think it was the right call by the C++ people to explicitly list what objects are captured and how, even if the syntax's not the best.

RAII is a fact of life unfortunately, not just in C++ or Rust, but if you talk over some high level protocol over the internet you go TCP socket->HTTP connection->your stream protocol; and have to do the exact reverse.

Closures break RAII hard.

Incidentally, you don't even need closures for nice looking UI code. Immediate mode GUIs like Dear Imgui or Clay allow for super-simple looking code in basic C

reply
> Immediate mode GUIs like Dear Imgui or Clay allow for super-simple looking code in basic C

Layout computation is always awkward in immediate guis. You have to do an extra pass or throw away a frame.

reply
Clay's algorithm actually does many passes, that doesn't mean it invokes the UI function multiple times. You are allowed to retain state during computation.

Here's a cool explainer video:

https://www.youtube.com/watch?v=by9lQvpvMIc

reply
> I think it was the right call by the C++ people to explicitly list what objects are captured and how

Having recently worked a lot with Rust, which does this implicitly - I find the explicit notation entirely unnecessary. There's only one choice - are captures moved into closure or passed by reference? - and everything else is inferred. It does lead to some verbose cloning when there are many refcounting pointers at play, but other than that it works flawlessly; I've never been in a situation I couldn't do something I wanted to.

I'm confused by the point about RAII. Why are you saying that closures break it? Personally, I found that closures complement RAII very well - the closure owns its resources, and when it goes out of scope they're all cleaned up automatically. Or do you mean situations where resources outlive the closures? This is no different than any other object that needs a reference to something that lives longer.

reply
It was a missed opportunity for a mature language like Scheme which had at the time all the good parts, none of the bad parts and the only issue was slightly unfamiliar syntax.
reply
I like Scheme syntax but someone coming from a C-syntax background can easily understand this in the first look:

const add = (a, b) => a + b;

And may need to read this a couple of times because of the lone "+" and the parentheses:

(define (add a b) (+ a b))

... and this is the simplest of examples. It's not slightly unfamiliar syntax. Perhaps Rust is slightly unfamiliar syntax, if we mean really just the syntax - as in, you can tell where the functions start and end.

You could also say that Scheme has very little syntax, for example, no distinction between statements and expressions, no operator precedence, and nearly zero reserved punctuation. So I'd argue that it needs more adaptation because it is less.

reply
> the only issue was slightly unfamiliar syntax

I was banished from golang communities when I said that a language should deviate from already established standards only when it has a good reason to do so. I remember it being quite ironic that golang took pride in not overloading names, and then... overloaded the English word "go". It's really unreadable unless you specifically study golang.

I could go on very long how much I hate golang for its stupid syntax alone, even before we dive deeper into its broken features.

Regarding Scheme itself, functional languages never gain traction because both humans and machines think imperatively. Yes, functional languages are a beauty for someone who understands them well, and in some specific use cases, but I still remember that as a student I finished my project, I just needed to add a few prints... oh fuck I need to rewrite the entire thing just to add "print". Never touched functional programming again, except for functional elements in imperative languages.

reply
https://news.ycombinator.com/item?id=44885169 [flagged] [dead]

> "Once on 4chan I read an opinion about golang that isn't suitable for this website and I fully agree." -anal_reactor

Maybe your shouldn't get your opinions about goland from 4chan, or your online personality and ideology either.

Or your opinions about women and masculinity either:

https://news.ycombinator.com/item?id=50599656

> "Some time ago I've seen a comment on 4chan that simplifies things, but has a decent grain of truth in it. [...self loathing misogynistic transphobic incel rationaliztions redacted...]" -anal_reactor

reply
I really like closures, except when you need to debug them because the callstack looks like the leaning tower of Piza.
reply
True. I mean yes, so long as you weren't writing JS for Internet Explorer.
reply
> garbage-collected closures

A feature existed since 1960s...

reply