Skip to content

Mut syntax for record fields #2133

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

Closed
jamorton opened this issue Apr 5, 2012 · 5 comments
Closed

Mut syntax for record fields #2133

jamorton opened this issue Apr 5, 2012 · 5 comments

Comments

@jamorton
Copy link
Contributor

jamorton commented Apr 5, 2012

Just a random comment, not sure if anything can be done about this.

I think the mutability syntax for records is a bit unreadable.

type cpu_state = {
    regs: [mut u16],
    mut pc: u16,
    mut sp: u16,
    mut o: u16,
    mem: [mut u16],
    mut cycles: uint,
    mut stop: bool
};
fn new_cpu_state() -> cpu_state {
    {
        regs: vec::to_mut(vec::from_elem(8u, 0u16)),
        mut pc: 0u16,
        mut sp: 0u16,
        mut o: 0u16,
        mem: vec::to_mut(vec::from_elem(0x10000u, 0u16)),
        mut cycles: 0u,
        mut stop: false
    }
}

Because the mut comes before the field name, it's quite hard to figure out what the actual fields are called. IMO, name should be on the left and the information associated with it on the right, that seems like a universal thing for structs, dictionaries, etc.

@nikomatsakis
Copy link
Contributor

I guess we could do {x mut: T}? But I think we won't, so I'm just gonna' close. (Feel free to re-open)

@jdm
Copy link
Contributor

jdm commented Apr 5, 2012

Personally, x: mut T feels far more readable to me.

@nikomatsakis
Copy link
Contributor

@jdm it's true that this looks nice, though I think it confuses mut being a part of the type... (which I kind of like, but I haven't figured out a way to make it work)

Maybe I was too hasty to close, but I'd rather see an e-mail to the list to hash out some kind of proposal before opening a bug. That is, I think issues ought to have specific suggestions, not just an indication of what you dislike.

@nikomatsakis
Copy link
Contributor

(The you there is meant generically, not to address the "OP" nor @jdm)

@jamorton
Copy link
Contributor Author

jamorton commented Apr 5, 2012

That's fair. I might make an email about it then.

Thanks!

Kobzol pushed a commit to Kobzol/rust that referenced this issue Dec 30, 2024
bors pushed a commit to rust-lang-ci/rust that referenced this issue Jan 2, 2025
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

No branches or pull requests

3 participants