Why is Rust being used to replace parts of the JavaScript web ecosystem like minification (Terser), transpilation (Babel), formatting (Prettier), bundling (webpack), linting (ESLint), and more?
I think once you get into rust you just have a hard time going back, and it doesn’t feel “hard” anymore. I can practically rust as easily as I can python for scripting and for API servers.
Rust really only gets hard when doing library development IMO. That’s when you need lifetimes and well chosen types. But that’s also why Rust libraries are superb.
I had the impression Rust doesn’t handle concurrency particularly well, at least no better than Python, which does it badly (i.e. with colored functions). Golang, Erlang/Elixir, and GHC (Haskell) are way better in that regard, though they each have their own unrelated issues. I had believed for a while that Purescript targeting the Erlang VM and with all the JS tooling extirpated might be the answer, but that was just a pipe dream and I don’t know if it was really workable.
Rust makes multi threading very easy you can just use
thread::spawn();
But rust makes Async difficult because it’s naturally stackless so you need to create your own scheduler or use someone else’s like Tokio. Also, people have a bad habit of conflating async with concurrency which makes it more confusing.
Sure you can spawn threads but now you have all the hazards of shared memory and locks, giving the 2.0 version of aliasing errors and use-after-free bugs. Also, those are POSIX threads, which are quite heavyweight compared to the in-process multitasking of Golang etc. So I would say that’s not really an answer.
What exactly are the hazards of shared memory and locks? The ownership system and the borrow checker do a pretty good job at enforcing correct usage, and if you are clever you can even guarantee no deadlocks (talk at rustconf 2024 about the fuchsia network stack).
But I think if you manage to use-after-free or other memory error in safe Rust it’s a compiler bug. Or you used unsafe and have a soundness issue in the code you did.
Note : as I understand it, unsafe is a way to tell the compiler you can check its safety guarantees yourself. But you may fail and get back other languages inexistent guarantees.
Go routines are certainly special and hard to match, but rust has all the normal abstractions of a language like C, just with a borrow checker so you can avoid memory leaks, write after read, etc.
I don’t know but I don’t think rust has that problem. In fact I’ve always thought its data ownership paradigm is literally the most optimal approach to concurrency and parallelism. I really love using rayon in rust for instance.
True, but of course it’s always a trade-off. At a certain point I have to defer to your judgment, at least until I’ve written some Rust code. But I’ve written a fair amount of C++ and a little bit of Ada and don’t find them all that convenient compared to Python or Haskell or whatever. We’ll see. ;)
I think once you get into rust you just have a hard time going back, and it doesn’t feel “hard” anymore. I can practically rust as easily as I can python for scripting and for API servers.
Rust really only gets hard when doing library development IMO. That’s when you need lifetimes and well chosen types. But that’s also why Rust libraries are superb.
I had the impression Rust doesn’t handle concurrency particularly well, at least no better than Python, which does it badly (i.e. with colored functions). Golang, Erlang/Elixir, and GHC (Haskell) are way better in that regard, though they each have their own unrelated issues. I had believed for a while that Purescript targeting the Erlang VM and with all the JS tooling extirpated might be the answer, but that was just a pipe dream and I don’t know if it was really workable.
Rust makes multi threading very easy you can just use
thread::spawn();
But rust makes Async difficult because it’s naturally stackless so you need to create your own scheduler or use someone else’s like Tokio. Also, people have a bad habit of conflating async with concurrency which makes it more confusing.
Sure you can spawn threads but now you have all the hazards of shared memory and locks, giving the 2.0 version of aliasing errors and use-after-free bugs. Also, those are POSIX threads, which are quite heavyweight compared to the in-process multitasking of Golang etc. So I would say that’s not really an answer.
What exactly are the hazards of shared memory and locks? The ownership system and the borrow checker do a pretty good job at enforcing correct usage, and if you are clever you can even guarantee no deadlocks (talk at rustconf 2024 about the fuchsia network stack).
They are OS threads (so yes heavy).
But I think if you manage to use-after-free or other memory error in safe Rust it’s a compiler bug. Or you used
unsafe
and have a soundness issue in the code you did.Note : as I understand it, unsafe is a way to tell the compiler you can check its safety guarantees yourself. But you may fail and get back other languages inexistent guarantees.
Go routines are certainly special and hard to match, but rust has all the normal abstractions of a language like C, just with a borrow checker so you can avoid memory leaks, write after read, etc.
Have you tried Gleam?
No I haven’t, I’ll take a look at it, though I felt suspicious of “task.async” as shown on the front page of gleam.run.
I don’t know but I don’t think rust has that problem. In fact I’ve always thought its data ownership paradigm is literally the most optimal approach to concurrency and parallelism. I really love using rayon in rust for instance.
True, but of course it’s always a trade-off. At a certain point I have to defer to your judgment, at least until I’ve written some Rust code. But I’ve written a fair amount of C++ and a little bit of Ada and don’t find them all that convenient compared to Python or Haskell or whatever. We’ll see. ;)
IME a language is as good as its package manager and libraries, and cargo is great.