Hacker News new | past | comments | ask | show | jobs | submit login

'mut' conveys the same thing you are trying to convey with 'var' in a much better way. The term "variable" in programming languages doesn't carry any connotations of mutability or immutability. All it traditionally means is "named value" or "named memory address".

It's actually entirely reasonable to have an "immutable variable" -- Rust uses this phrase in its error messages and it's perfectly sensible. For example, consider this snippet:

    pub fn is_even(x: int) -> bool {
        let y = (x / 2) * 2 - x;
        if (y == 0) {
            return true;
        } else {
            return false;
        }
    }
Not very idiomatic, forgive me, but would you say that y "varies"? I would say yes, it varies for each invocation of is_even(). If y didn't vary, "if (y == 0)" would be a nonsense statement. y is certainly immutable -- you can't go assigning new values to it -- but it's definitely a variable.

The opposite of "variable" is "a constant," not immutable. 'mut' means "mutable" and "mutable vs. immutable" is the choice here. Rust got this right, I think.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: