-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Guide: Variable bindings #15229
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
Guide: Variable bindings #15229
Conversation
|
||
## Testing | ||
Let's set up a new project. Go to your projects directory, and make a new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the code is shown after this sentence, it seems a bit confusing at first. One probably doesn't get what "projects directory" means until they see the code. Perhaps something like "Go to where you keep your projects in"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the very beginning of the tutorial, we created a projects directory, and talked about it explicitly. It was created at this location.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. That makes more sense.
I'm a rust novice and my perspective on It wasn't until I saw huonw's example below that I realized what I had missed: let x;
x = 2; |
You don't necessarily have to print out the error messages verbatim. People aren't likely to read them entirely anyway. fn main() {
let x: int; // Warning: unused variable
} The above is perhaps better than the entire warning anyway. Warnings could also change subtly between versions (I have no idea how likely though). If the playpen is embedded like in Rust by Example, error messages aren't needed because compiling will provide them. This really helps keep examples compact. It would also allow you to suggest changes like Japaric: fn main() {
return;
// ^ Try commenting out this line
println!("Hello world!");
} Also, you don't have to break up code by text (just pointing it out; what you do is up to you). Japaric gets a lot of mileage out of inline commenting in RustbyExample. The essentials of your example is below yet it takes 10 times the space: fn main() {
// Compiles:
// Read as: `x` is a binding with the type `int` and the value `five`
let x: int = 5;
// Compiles
let y: int;
println!("Hello world!");
// Error
let z: int;
println!("The value of y is: {}", z);
} Keeping them together makes lines easier to compare. It also gives you opportunity for more contrasting examples. |
@mdinger thanks for the suggestions. I do want to link to the sandbox eventually, but first, I'd prefer to just write everything inline. Eventually all of the examples, everywhere, should go to the sandbox. |
If @huonw likes my updates, I think this is ready for a r? |
(I like the updates.) |
Cool. @brson, r? |
|
||
If you include two curly braces (`{}`, some call them moustaches...) in your | ||
string to print, Rust will interpret this as a request to **interpolate** some | ||
sort of value. Interpolation is a fancy computer science word that means "stick |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- You should use the term "String interpolation", not just "Interpolation", to distinguish this from e.g. linear interpolation.
- The latter is what I get when I google for "interpolation" today; I had to add "string" to get usable links.
- So, use of the full term will make it easier for the reader to get the right result when searching for more information.
- (It would probably be a good exercise to go through and make sure every similar vocab word that is introduced or pseudo-defined in the guide currently gets a plausible result from google.)
- In particular, in this case I would say `"String interpolation is a programming term that means ..."
- Further explanation for the latter suggestion: I read the use of "fancy" here as carrying an "aww shucks" tone, which I dislike, as it brings with it underlying theme of "don't worry your little head about big words like "Interpolation." I see the latter as dismissive of the reader, rather than respectful. But I suspect that others may think that an "aww shucks" tone it makes the text more approachable, so I will not push hard for this latter change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the latter as dismissive of the reader, rather than respectful. But I suspect that others may think that an "aww shucks" tone it makes the text more approachable,
This is a constant issue, which I'm not sure how to resolve. I had a really interesting, lengthy discussion with someone about "basically," the other day: I read it as synonymous with 'essentially,' and others read it as super condescending.
Gimme a quick moment and I'll fix both of these. I do think that searching on google for terms is a good idea, but I'd rather do that as part of a final editing pass than as I go, that's the kind of work that's nice to just do all at once.
@steveklabnik okay, if you address the nit I noted, I think the whole thing will be ready to be squashed and then r-plussed |
I'm going to move testing to be right AFTER the guessing game. I wanted it to be borderline TDD, but I think that, since the first example is just one file, it might be a bit overkill. I'm doing this in its own commit to hopefully avoid merge conflicts.
This is ready. |
This is re-r+ ready. I just dropped the graves, which rustdoc had issue with. |
Whew! Who knew there was so much to say about variables. We probably want to move the guessing game to the rust-lang org, rather than just having it on my GitHub. Or, I could put the code inline. I think it'd be neat to have it as a project, so people can pull it down with Cargo. Until we make that decision, I'll just leave this here.
Whew. So much here! Feedback very welcome. This is the first part where we actually start learning things. I'd like to think I struck a good balance of explaining enough details, without getting too bogged down, and without being confusing... but of course I'd think that. 😉 As I mention in the commit comment, We probably want to move the guessing game to the rust-lang org, rather than just having it on my GitHub. Or, I could put the code inline. I think it'd be neat to have it as a project, so people can pull it down with Cargo. Until we make that decision, I'll just leave this here.
Whew. So much here! Feedback very welcome.
This is the first part where we actually start learning things. I'd like to think I struck a good balance of explaining enough details, without getting too bogged down, and without being confusing... but of course I'd think that. 😉
As I mention in the commit comment, We probably want to move the guessing game to the rust-lang org, rather than just having it on my GitHub. Or, I could put the code inline. I think it'd be neat to have it as a project, so people can pull it down with Cargo. Until we make that decision, I'll just leave this here.