logoalt Hacker News

amelius • today at 10:14 AM • 4 replies • view on HN

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.


Replies

torginus • today at 10:36 AM

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

➕ show 2 replies
baq • today at 10:18 AM

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.

➕ show 2 replies
anal_reactor • today at 11:26 AM

I really like closures, except when you need to debug them because the callstack looks like the leaning tower of Piza.

raincole • today at 10:22 AM

> garbage-collected closures

A feature existed since 1960s...