100-exercises-to-learn-rust
100-exercises-to-learn-rust copied to clipboard
Reconsider as-casting
Very early on in the course, we introduce as casting: https://rust-exercises.com/100-exercises/02_basic_calculator/10_as_casting
A few thoughts on this:
- I'd argue in general converting between different sizes of integers is a much less core part of the language than the early placement of this section suggests - we may want to move it later (where we can also rely on more knowledge such as of traits). I don't think it's required for any of the exercises done before we could reasonably introduce
Into/Fromand friends. - I think we should be default recommending
Into/FromandTryInto/TryFrominstead ofas. In general I thinkasshould only be used where it's strictly required, and if there's a more specific conversion mechanism we should prefer that - we shouldn't train in reaching forasas a default. - When we're talking about how
ascan cause bits to be re-interpreted, I'd recommend we throw in a link to a source on bit representation. I've had novices who only know JS/Python before (so have never encountered signed vs unsigned types) be (reasonably) confused about how to predict/interpret-1_i8 as u8and255_u8 as i8. We talk about how truncation keeps bytes, but without knowing what that byte representation is (i.e. what two's complement is) it can be hard to interpret. I think this can be handled with a simple one-sentence explanation and a link.