3 ms·
I want to be interested in Rust, but then I see a line of code like this in the post: let decrement = move |_| set_value.update(|value| *value -= 1); Maybe I'
by willio58 4y ago
I want to be interested in Rust, but then I see a line of code like this in the post:
let decrement = move |_| set_value.update(|value| *value -= 1);
Maybe I've lost that interest I once had in learning language syntax.. I just don't really understand this intuitively and the barrier to understanding this line feels unnecessary. When I compare Rust with JS/TS, Python, or even Swift I feel like those other languages are created in a way that's easy to pick up and transfer knowledge from other languages, then the deeper parts of the language are easily accessible once you're introduced to the basics.
- duped 4y agoI mean compare to using arrow functions and it's almost identical let decrement = () => set_value.update((value) => value -1); The difference is that Rust isn't garbage collected and has reference value semantics, which is where the *value -= 1 comes in.
- willio58 4y agoIt's funny, I almost noted that arrow functions are a definite oddity of JS that I could see people thrown off by.
- marcosdumay 4y ago> oddity of JS I can't think on any modern language that lacks some short syntax for lambdas. Hell, it's very easy to make a point that lacking short syntax for lambdas make a language not modern and unusable for our current standards.
- willio58 4y agoI'm a little confused what you mean by JS lacking a short syntax for lambdas. let multiply = (a, b) => a * b; Is this not a lambda?
- kaba0 4y agoParent means that basically every language has lambdas, so it could hardly be an odd thing.
- willio58 4y agoOhh! Thanks for clarifying
- earthling8118 4y agoYou've missed their point entirely. It was never stated that JS was lacking this, rather than most languages DON'T lack it.
- ansc 4y agoI like how you skipped the hardest part that requires most Rust knowledge; the `move`
- duped 4y agoOk fine, "Rust doesn't have a garbage collector and has reference value semantics and ownership semantics." My point is that the syntax isn't a problem, it's that Rust has very different semantics from the GC'd languages in the original comment and it all has to do with memory management.
- supportlocal4h 4y agoCompare your Rust with my JS: let decrement = _=>set_value.update(value => value -= 1) I don't understand your complaint about syntax. The real difference here is the concept of a move and a dereference. JS lacks these concepts and naturally has no syntax for them.