Skip to content

Just a few minor updates to guide.md #17754

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

Merged
merged 8 commits into from
Oct 4, 2014
Merged

Conversation

O-I
Copy link
Contributor

@O-I O-I commented Oct 3, 2014

Hi,

These are a few small edits to the Guide that I made while reading online. Really well done and approachable.

I have a few questions below, but I don't know if this is the proper place to ask them, so feel free to ignore the below.

  1. Trailing commas seem to be a convention in Rust and are used quite a bit throughout the Guide, but are never explicitly mentioned. Maybe adding a short mention about them when they first appear in the Structs section might be helpful to those who are unfamiliar with or don't use them in other languages.
  2. In the Iterators section, there is a block of code like this:
let mut range = range(0i, 10i);

loop {
    match range.next() {
        Some(x) => {
            println!("{}", x);
        }  // no comma needed?
        None => { break }
    }
}

My inclination would be to put a comma where the comment is to separate the two arms to get this to compile, but it runs fine either way. Is there a convention on commas for scenarios like this where each arm is enclosed in {}?

All the best,
O-I

O-I added 8 commits October 3, 2014 13:37
See issue rust-lang#17672. This was started in commit ee1cbb9, but there were a few more lines to update.
Oddly (to me), this code runs fine without the comma separating the `Some` and `None` arms of the `match` construct. It seems like Rust doesn't require you to separate arms with commas if all the expressions are enclosed in braces.
@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (or someone else) soon.

@aturon
Copy link
Member

aturon commented Oct 3, 2014

r? @steveklabnik

@aturon aturon assigned steveklabnik and unassigned aturon Oct 3, 2014
@steveklabnik
Copy link
Member

I don't know if there's a convention, but I always include commas. Are trailing commas rare enough to be called out specifically? The only thing I use on a regular basis that doesnt have trailing commas is JSON.

Regardless is the questions, these changes are all good. Aaron, what do you think re convention?

@steveklabnik
Copy link
Member

(I'm on mobile and so it's not easy to see the correct commit. If someone wants to r=me before I can get to it, feel free.)

@aturon
Copy link
Member

aturon commented Oct 3, 2014

@steveklabnik There's a proposed convention to use trailing commas whenever the thing in question spans multiple lines, but it hasn't gone through the RFC process yet. Most of the basic style questions (that don't involve APIs) are not completely "approved" yet; we plan to sit down and write them all up at once in the near future.

I'll send it to bors on your behalf.

@O-I
Copy link
Contributor Author

O-I commented Oct 3, 2014

Thanks for the feedback. I agree that always explicitly including commas is a good practice. I guess I just had the (false) inclination that something like the contrived example below wouldn't compile.

let x = 5i;

    match x {
        1 => { println!("one");
               println!("{:d}", 1i); }
        2 => { println!("two");
               println!("{:d}", 2i); }
        3 => { println!("three");
               println!("{:d}", 3i); }
        4 => { println!("four");
               println!("{:d}", 4i); }
        5 => { println!("five");
               println!("{:d}", 5i); }
        _ => { println!("something else");
               println!("{:d}", 42i); }
    }

As for trailing commas, I can definitely see the benefits. I didn't realize they were so prevalent.

bors added a commit that referenced this pull request Oct 4, 2014
Hi,

These are a few small edits to the Guide that I made while reading online. Really well done and approachable.

I have a few questions below, but I don't know if this is the proper place to ask them, so feel free to ignore the below.

1. Trailing commas seem to be a convention in Rust and are used quite a bit throughout the Guide, but are never explicitly mentioned. Maybe adding a short mention about them when they first appear in the Structs section might be helpful to those who are unfamiliar with or don't use them in other languages.

2. In the Iterators section, there is a block of code like this:

```rust
let mut range = range(0i, 10i);

loop {
    match range.next() {
        Some(x) => {
            println!("{}", x);
        }  // no comma needed?
        None => { break }
    }
}
```

My inclination would be to put a comma where the comment is to separate the two arms to get this to compile, but it runs fine either way. Is there a convention on commas for scenarios like this where each arm is enclosed in `{}`?

All the best,
O-I
@bors bors closed this Oct 4, 2014
@bors bors merged commit 9040948 into rust-lang:master Oct 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants