4 ms·
> 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
by 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.