4 ms·
What's the advantage of using Rust for web development vs. JavaScript (for example) and using Rust for specific tasks as necessary? The Node/Rust interop is dec
by endisneigh 6y ago
What's the advantage of using Rust for web development vs. JavaScript (for example) and using Rust for specific tasks as necessary? The Node/Rust interop is decent enough.
- loloquwowndueo 6y agoOnly a troglodyte would use JavaScript for server-side programming. And you can’t use rust for front end work. So you’re kind of asking for what the advantage is of an apple over a backhoe - the comparison makes little sense.
- frenchy 6y ago> Only a troglodyte would use JavaScript for server-side programming. As a troglodyte myself, I don't disagree with you, but you're being unnecessarily demeaning. > And you can’t use rust for front end work. You certainly can (for example https://yew.rs/ https://yew.rs/), but as usual there are certain caveats and limitations.
- nicoburns 6y agoIt's much simpler to use one language rather than two. And Rust code isn't much harder to write than JavaScript (especially if you're using TypeScript). Rust also gets you: 1. Better performance 2. More importantly: much better safety guarantees. Rust web services tend to be set it and forget it. They don't break. they don't crash. They only rarely have bugs.
- afavour 6y ago> Rust code isn't much harder to write than JavaScript As someone that's coded in both... eeeehhhhhhh Memory management in Rust can be a real bear. Just, for example, creating a closure that references a variable outside of its scope is not simple. You can make your life a lot easier by wrapping everything you reuse in Rc<> to make it reference counted, but then you're eating into the performance gains that are the initial selling point, and after a certain point you're just manually implementing the things that JavaScript does for you. Don't get me wrong, I love Rust. But I wouldn't want to use it everywhere I use JS/TS today.
- nicoburns 6y ago> creating a closure that references a variable outside of its scope is not simple Well sure, but how often do you need to do that in a web API endpoint handler? In my experience: not often at all. Rust can be hard, but generally isn't for this use case. > You can make your life a lot easier by wrapping everything you reuse in Rc<> to make it reference counted, but then you're eating into the performance gains that are the initial selling point Frameworks like Rocket or Actix-web will handle this for you. In my experience it doesn't tend to affect performance that much. Remember: Node is single-threaded. Multi-threaded + atomics + optimised compiled code is still significantly faster.
- zozbot234 6y ago> Just, for example, creating a closure that references a variable outside of its scope is not simple. It's a lot simpler and more performant than in other languages. Rust will tell you if the closure might outlive the variable you're referencing, and it's easy to pick the best option for addressing the issue (move semantics, Rc<>/Arc<>, lifetime specifiers etc.) while keeping best-in-class performance. This is a big part of what Rust is best at, and it's hard to get these advantages any other way.
- nicoburns 6y agoYeah, I've definitely had hard to find memory leak issues in JS code due to things like this, which rust prevents with a compiler error.
- adamnemecek 6y agonpm ironically also uses Rust https://www.rust-lang.org/static/pdfs/Rust-npm-Whitepaper.pdf https://www.rust-lang.org/static/pdfs/Rust-npm-Whitepaper.pd....