-
Notifications
You must be signed in to change notification settings - Fork 13.3k
RFC: Small closure syntax tweak #2394
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
Comments
I like the current syntax a little better, but I don't have a particularly good reason, thus I won't stand in the way. |
Some more examples:
|
Also
|
I'm ambivilant. I guess I slightly prefer the proposed syntax. |
No strong opinion. I like that it makes this possible: @pcwalton but why do you say your proposal is more familiar to Ruby programmers? As far as I can tell, what we have now is the Ruby syntax. |
Yes, my mistake: what we have now is the Ruby syntax. Ruby house style tends to prefer paired |
If I understand correctly then the Current syntax: Proposed syntax: I therefore suggest that this proposal increases syntactic complexity. |
I actually think that it makes the syntax simpler to understand: the colon indicates to the eye that there's something special going on. It suggests a connection between the lambda and the call before it. With simple juxtaposition, however, the lambda looks separate from the call; it's not immediately obvious that they're connected. |
@pcwalton does the trailing
|
I wish, but that makes stuff like |
@pcwalton ah yes of course. It's always record literals. I prefer |
|
Another thing came to mind when looking at this page: Perl 6's syntax works for us. That's Benefits of this syntax over the current syntax are: (a) one fewer shifted character; (b) keeps braces at the end of the line, like C; (c) avoids the argument list entirely for the zero-argument case; (d) makes function declarations visually resemble their types. Benefits of this syntax over the proposed syntax are: (a) one fewer shifted character, and two for function calls; (b) avoids the colon after the function for Ruby block syntax; (c) avoids the argument list entirely for the zero-argument case; (d) makes function declarations visibly resemble their types. Benefits of this syntax over the earlier "no-sticks" proposal I sent to the mailing list are (a) no colon required for the Ruby block syntax; (b) the arrow draws the eye toward the argument list, making it stand out; (c) makes function declarations visibly resemble their types. Examples:
vs.
vs.
|
I think the colon increases the mental burden.
vs
Currently a colon mostly seperates the type from the variable. With the current proposal one has to add a mental check to many occurances of a colon while reading code "is this a variable declaration or a passing of arguments?" That's also why i am against the
|
Keep in mind that colons are also used in record literals: Also, I agree that the
|
Closing this because I think we have something better as discussed yesterday. |
useless Rc<Rc<T>>, Rc<Box<T>>, Rc<&T>, Box<&T> refers to rust-lang#2394 changelog: Add lints for Rc<Rc<T>> and Rc<Box<T>> and Rc<&T>, Box<&T> this is based on top of another change rust-lang#5310 so probably should go after that one.
Fix bugs where unique_range became invalid And also expand the cache integrity checks to cover this case. I'm going to run this over all the ICEs I've gotten out of Miri recently, could be a bit. Fixes rust-lang/miri#2389
Make run instructions first
Might as well submit this as an RFC. I propose this syntactic tweak:
In other words, keep the closure syntax exactly the same, but move the sticks before the initial curly brace, and add a colon before the sticks in the Ruby-like call notation.
The reason is to keep the brace at the end of the line:
As opposed to (currently):
The former looks more familiar to C programmers (and Ruby/Smalltalk programmers) and looks nicer to me. The reason is that the brace is at the end of the line, allowing the eye to follow control the same way the user does in C.
The other nice things about this syntax are forward-thinking: it might allow us to drop the braces in the future, and it might allow us to use the
Primary '{' ... '}'
syntactic space for other things.The text was updated successfully, but these errors were encountered: