-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
add special syntax for mutable variable declarations #1273
Comments
Reasons to make this change:
|
I noticed that the words "mutable" and "local variable" do not appear in this bug! It took me a while to find it as a result. Therefore, I am adding this comment to make future searches easier. |
Not really. If you close of |
That's true. This is because vectors are unique pointers. I was tacitly assuming that the "no implicit copies" proposal is accepted, in which case (a) vectors would not be unique pointers and (b) unique pointers (and other structures with expensive copies) would require an explicit copy annotation. |
The example I gave did not contain any vector. But I guess it would make sense for mutable structure types to also no longer be implicitly copyable. |
Yes, you are right, it did not. I misread it as |
Why not just use the existing "mutable" keyword? Even requiring an explicit type wouldn't be so bad, but some simple shorthands would help (e.g. "let x : mutable" would constrain the type to be mutable, but would get the rest of its type from inference (e.g. "mutable int" or whatever)). I kind of like that you have to type a few more characters for mutable variables. It adds some slight pressure to avoid them.In my one simple rust app (a raytracer) I found that over 90% of local variables were immutable. Also, IMO, mutable variables are a significant detriment to readability. The more times a variable is changed, the more "what-ifs" you have to consider when interpreting its potential values when reading the code. Making it slightly painful (though not too painful!) to allow mutation could be a good thing. |
Maybe just use mutable in place of let, like |
@brson this was the original proposal. I just wanted to change the |
oh. carry on then |
I'm ok with:
Though |
I like |
I don't have a strong opinion on the choice of keyword, though I'd rather use the same one for all mutable things (i.e., |
+1 for |
wishy-washy on the matter. I kinda like that |
(As an aside, we already distinguish between mutated locals and immutably used ones—the |
My preference would be to make it roughly "twice as ugly" as immutable locals, whatever that means :-).. I'd want it to be pretty damn ugly so people would avoid it if they don't really need it, and so that it stands out better when you read it, but not ugly enough that you'd feel it was clunky for the few cases where you do need it. For me that probably means I'd prefer the full "mutable" keyword instead of "mut" or "var". Easy enough to change the name of a keyword in retrospect though, the important part is making the distinction at all. |
Personally, I disagree with all this mutable bashing. I would prefer |
... even though i understand the proposal, i think i'd have to make a significant effort to come to the mental conclusion "x and y are both variables,
What would you think about having both The first serves consistency with other uses of "mutable", the second would serve the lazy. |
I've been thinking this over and I think I've developed a reasonably strong preference for:
This dovetails nicely with |
I've been thinking that |
Agreed. Consensus? :) |
Yes. |
first step towards issue rust-lang#1273
Fixed in dc07280 |
Use pull instead of push based model for getting dylib symbols in the jit
we just discussed this on irc and everybody on seemed to like this idea:
This ticket serves as a way to track this idea and potentially implement it.
The text was updated successfully, but these errors were encountered: