Javascript is actually a great language. Its garbage-collected closures made it easy to do GUI programming.
The C/C++ world where browsers came from didn't have this (closures). So it is actually a miracle we got a language as (relatively) great as Javascript.
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.
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.
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.
I have plenty of issues with how much of a giant leap backward in expressiveness golang represents, but your entire contribution was to troll the golang communities about the language's name. You deserved the ban.
I expressed myself wrongly. At the time I tried to make a sensible argument, and kept the sillyness to myself. Now I don't care, because I stopped having professional contact with it long ago.
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
> 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.
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.
Jetpack Compose splits this into measure and layout passes, and running either pass twice crashes the UI. They can do this because they are faking immediate-mode on top of a retained-mode layout tree, sort of like React.
This matches the case of a lexically scoped variable and no moves. With full RAII, the resources are tracked across their entire dynamic lifetime, not just one lexical block, allowing them to be returned to callers, placed in containers, etc.
In the last few decades the hype around GC kind of faded because GC is literally a complex solution designed to fix only one single class of leaks - memory leaks - which often makes other kinds of leaks (mutex, file descriptors, handles, ..) actually harder to handle unless the language is carefully designed around them. Just look at Java's `try()` or `with` in Python, etc, which are afterthoughts added later. RAII may be rudimental but it can potentially fix all classes of leaks by introducing deterministic lifetimes and scopes which aren't tied with the resource itself. There are other solutions for this? yes of course, but the success of Rust which is literally built over a stronger, deterministic form of RAII kind of makes debatable whether a better system is needed at all. Especially since LLMs are excellent at Rust and kind of make opting for "weird" languages moot. And I say this as a person which _loves_ niche languages and language design.
Nowadays you can probably vibe/slopcode whatever you need with just a bit of Rust, Python/shell scripts as glue and maybe Javascript if it's a webapp (but we'll likely replace that with WASM soon I'm afraid)
Rust, unfortunately, lets you express lower bounds on lifetimes but not upper bounds. There is no way in Rust to express “this object must be released by that point in the program,” a guarantee which is extremely useful.
It kinda does that, by using borrows. If A borrows B, then the upper bound of A's lifetime is the borrow of B. You can control the lifetime of the borrow by creating a new mutable reference to B at a particular point (works regardless of whether the original borrow was mutable or immutable).
In this case you’re really setting a lower bound on the borrow of B, not an upper bound on the lifetime of A.
I assure you this is not pedantry or a nitpick. The classic case here is if you want to borrow a local variable inside a thread… you need to ensure that the thread lifetime is bounded from above by the lifetime of the borrowed variable. This is why we have weird workarounds like std::thread::scope. If we could just express an upper bound on lifetime, it wouldn’t be necessary.
It is perhaps one of the greates languages, and honestly it is more or less a Perl for the web for those who have the eyes to see it. It is the only reason I'm not sad about Perl. But it WAS is more correct, as JS was abominated in many possible ways. But it was also written on the wall perhaps 5-6 years ago when Rust started to target wasm, that the days of JS are numbered. Now with LLMs we should see a very steep decline of it.
The C/C++ world where browsers came from didn't have this (closures). So it is actually a miracle we got a language as (relatively) great as Javascript.
Replies (7)
Replies (2)
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.
Replies (1)
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.
Replies (1)
Replies (1)
A feature existed since 1960s...
Replies (1)
Replies (1)
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
Replies (4)
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.
Layout computation is always awkward in immediate guis. You have to do an extra pass or throw away a frame.
Replies (2)
Here's a cool explainer video:
https://www.youtube.com/watch?v=by9lQvpvMIc
Naturally it works better in FP and LP languages without concept of global variables, where resources could escape the closure.
Replies (1)
Replies (1)
In any case, you have two ways to do something similar, kind of.
Naturally there are multiple variations thereof, on how to handle errors, or which way to parameterise how to close resources.Then we have the C# inspired way,
And if open_resouce doesn't support using declaration, an helper builder function can be used to wrap it in such a type.Yes it isn't as automatic as pure RAII, but it gets close enough for most practical purposes.
Replies (2)
Continue this thread (1 replies) →
Continue this thread (1 replies) →
Nowadays you can probably vibe/slopcode whatever you need with just a bit of Rust, Python/shell scripts as glue and maybe Javascript if it's a webapp (but we'll likely replace that with WASM soon I'm afraid)
Replies (1)
Replies (1)
Replies (1)
I assure you this is not pedantry or a nitpick. The classic case here is if you want to borrow a local variable inside a thread… you need to ensure that the thread lifetime is bounded from above by the lifetime of the borrowed variable. This is why we have weird workarounds like std::thread::scope. If we could just express an upper bound on lifetime, it wouldn’t be necessary.
Continue this thread (1 replies) →
Replies (1)
Replies (1)