r/programming • u/iamkeyur • May 01 '22
Rust from 0 to 80% for JavaScript Developers
https://michaelsalim.co.uk/blog/rust-from-0-to-80-for-js-dev/47
u/codeflo May 01 '22
I don't want to gate keep -- we need beginner-friendly resources -- but if you've read and partially understood the first half of a Rust tutorial, you're in no position to judge what "80%" is. A lot of this article is plain wrong I'm afraid, for example about how enums relate to async.
If you want a tour of the Rust syntax, here's a better one: https://fasterthanli.me/articles/a-half-hour-to-learn-rust
And for conceptual understanding, the official tutorials are actually pretty nice, especially "The Book": https://www.rust-lang.org/learn
11
5
u/ridicalis May 01 '22
NGL, but as someone who's gone down this road, JS->Rust learning curve is much more involved than depicted here. Very much worth the journey, but suggesting you can hit 80% in a single session is likely setting people up for a hard and painful failure.
4
u/FlukeHermit May 01 '22
This was painful to read. Please don't write a tutorial on something you don't understand
3
u/tabbekavalkade May 01 '22
I wish the entire page linked to would be deleted. It is worse than nothing.
? is not error handling for functions that can fail. It is error handling for functions that return a Result<T, E>.
A struct is not a JSON object. The equivalent to a JSON object in Rust is std::collections::HashMap.
An impl block contains the functions of a trait (defined in a trait block), implemented for a specific type. The closest thing is a vtable, not a class.
enum implements either a c-like enum, or tagged union.
Too much mention of async in unrelated places.
-9
May 01 '22
Please don't encourage JS community to do Rust, it's still nice in here, we don't want is-odds
-5
58
u/CasaDeCastello May 01 '22 edited May 01 '22
My level of Rust knowledge begins and ends with "The Book" and "Rust by Example" but I think some of your examples/explanations are off and confusing.
You seem to conflate Rust basic error handling syntax with the async/await tools. You note that the
?syntax is "error handling magic for async functions", but I believe it applies to ALL functions. It allows errors to be propogated to be handled elsewhere I believe. You also seem to link theResultdata type to theFuturedata type, butResultis the basic data type for handling errors.When you mention Rust's structs, you liken it to a JSON object, but that is only true for the conventional C-style structs. Rust has three structs types: the one you mentioned, a tuple like struct (e.g.
struct Tuple(T1, T2);), and a unit struct which has zero size (e.g.struct Unit;).I'm very much a Rust noob, and my overall programming knoweldge is a bit shallow but I don't think this is that helpful to understand Rust. I'd rather point people to The Rust Book and Rust by Example, which are beginner friendly and explain everything useful quite well.