-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: moving from int and uint to us for array access in examples #21277
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
I think that as an introduction to Rust that this would actually omit as many suffixes as possible (instead of being explicit), would it be possible to just delete all suffixes? |
I'm conflicted here. I agree that you would want to aim for the intro to be as easy as possible. So there's two commits here... With 4172150, although removing suffixes would be easier for a newbie, it's probably better to drum it in from the start that you probably want to be explicit when indexing by using usize. This way, it's habit forming and a plus if they miss the reasoning in later texts. As for 48a58dd, that was just to silence the compiler warnings when a newbie were to copy-paste the examples and compile them. Having a screen full of warnings on their first attempt to compile some Rust from the official intro may actually scare them off! I'm happy to remove all suffixes, but I just thought you may want to hear my reasoning :) |
In general, as few suffixes as possible.
Right, but a bad habit. 😄 Which warnings does this make? |
Fair enough :) Although I was under the impression that you didn't want the default (no-suffix, signed) for array indexing so wanted to make usize habit forming. If I'm right, should indexing into an array cause a type check in the compiler and complain when it's not usize? As for the warnings, one of the examples "let mut numbers = vec![1i, 2i, 3i];" generates 31 lines of warnings. This could definitely scare off a newbie.
|
So this is now out of date. Can you rebase? I think we removed them since. :) |
That's what I love... Rust moving fast - it's a feature :) |
Can the remaining |
@alexcrichton this was interesting experiment! I ran the following to check who's assumption was right:
I was under the assumption that this was going to be 'is' as 'int' used to be the default but now moved to isize. I was completely off here as integers without a suffix instead default to i32! @alexcrichton expected the output to be 'us' because of the type inference, but this actually outputs the following:
I think what's happening here is that println!() is actually wrong because it's spitting out 'u' and not 'us'! I've submitted edde04b to fix this. Sorry guys, I was completely wrong! This change should be dropped :) |
Thanks for the investigation @Alfie! |
As per rust-lang/rfcs#544