-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Unless/Until RFC #2384
Unless/Until RFC #2384
Conversation
text/0000-unless-until.md
Outdated
} | ||
``` | ||
|
||
evalueates the conditional `COND`, executing the loop if the test failed and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small typo on evalueates
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:headdesk:
thanks
Hi, I'm not (for now at least) a Rust user. I'm mostly a Scala developer these days and I'm a former Java and Ruby developer. As a former Ruby developer, I can say that, IMO, the People tend to write very bad code with this keyword. Adding a lot of double negations where a simple This keyword adds more complexity in the code than producing any good effect on written code. Jules |
At present, I fully agree that
Lastly, in my own work with Ruby, I have found |
Re negative pattern matching, this has been discussed some over in #929 (comment), and I know @petrochenkov has been working on more expressive |
Nominating for triage during the next lang-team meeting on Thursday as we need to deal with any keyword reservations speedily. |
@jonhoo, honestly, I expect that this will wind up being primarily a driver for a full Boolean algebra on patterns. Short of |
This RFC represents a lot of what I was afraid of when epochs/editions were proposed. The only thing worse than a breaking change to support a feature is a breaking change "just in case". While I can't find the exact line (#2052 was a long RFC), there is text in that RFC along the lines of "epochs allowing minor breaking changes should not be used as an excuse to make breaking changes". This RFC feels like the direct antithesis of that. |
} | ||
else { | ||
// do significant work on the positive execution | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if !(execute_machine() is FsmState::Stop) { ... }
if execute_machine() is not FsmState::Stop { ... }
if execute_machine() !is FsmState::Stop { ... }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I knew I'd miss out on existing knowledge, thanks!
"these two concepts are logically equivalent" (`Eq` trait, `==` and `!=` | ||
operators) and "this value is shaped like that pattern" (`let`, `match`). | ||
|
||
Another concept is to introduce a *negative binding*, `!let`, which does not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally would like to go all out and have both if !let ...
and if let ... && ...
work, making let
in a conditional expression basically a matches!
with binding. However, this does make "let-as-expression" more of a thing but it's still this weird kind of expression that's only an expression in certain contexts. So idk.
Let's start from this example (from the rfc):
Is unless a while not, or a if not? Skimming over the code can confuse newbies, or even seasoned developers that didn't get a chance to see this construct before. Now let's imagine the following to be possible and valid code:
The first example already confuses me, but the second being an option is super scary me and probably any newcomers. if/while statements can get really ugly as they are now in programming, negating everything with some keywords and allowing boolean expressions inside them but reversing the meaning of the blocks executed is something that may not be worth for the benefits it brings. Probably a better option would like to make |
In some (human) languages there is no direct one word translation for "unless", e.g. in my native language (hungarian) it is roughly translated to "if not only". Each time when I see "unless" in some code (I had Perl in my past) I have to stop, then negate the whole expression in my head and pretend that it was an "if" statement. It is even more hard and confusing if it has "not" after an "and"/"or". Having the same condition with "if" may be more complicated, but at least it is written down. And I heard the same complain from some British people too. "Unless" may look simpler if the condition is simple, but once it has more components, some negated, some not, it just becomes extra complicated to understand. With these in mind, please consider that for me most of the examples demonstrating how "unless" would make code simpler makes it actually harder to understand. Please keep the language simple. "Unless" just complicates it. |
I agree with @sgrif's comment strongly. There seems to be a rush to block things for edition 2018 to allow RFCs to be written on top of these that might themselves not succeed. I also see a high chance that This should either be run as a fully-fledged RFC, with the goal for implementation being edition 2018, or none. Currently, it's only a collection of (advanced) reasoning why such a change could be useful, but at the end only argues for blocking these words, as they could be used for something. This is definitely a weak reasoning for a change that will likely have practical impact when porting over to 2018. Also, an argument for |
I have always found |
I'm really, really against IMHO, just take these keywords and bury them; Ruby and CoffeeScript have them but even in those languages I prefer to not use them because of the above reasons |
If there are places where logical inversion is not readily accessible, let's make it accessible rather than adding new keywords. For instance, if there were a "bool-let-expr" where any let statements act as pattern matches that are true if they succeed and add the bound variables (if true and universal) to both the rest of the expression and the following block, then you would get full boolean algebra with pattern matching, and no extra keywords. |
@skade that came off as way angrier than I intended; I've edited my comment. :) |
I'm definitely opposed to " The version of this I could like, and have articulated before, is for guards. Note, for example, that Edit: As another example, failure's |
I'll join in with the comments against this. I've done perl professionally and, though I eventually trained myself to replace "unless" with "if not" in my head, it's just extra cognitive load that is unnecessary. I do wish rust had gone with keywords for |
We discussed this in the @rust-lang/lang meeting today, and the general consensus was to close. Nobody was particularly enthusiastic about this change, or about seeing the language go in this direction. (There was a little bit of discussion about specific use cases or aspects of matching, related to some of the @rfcbot fcp close |
Team member @joshtriplett has proposed to close this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
the only advantage, I could really see if is that unless and until are used to express negative patterns, adding more ways to do a thing, usually just leads to trouble. the only major reason, you should have multiple ways to do things if that specific that method reduces boiler plate for a common purpose. I have no problem reading many conditions with not in it. many times there is a question of where to put the not but adding one more certainly wont help. |
The final comment period is now complete. |
Thank you @myrrlyn for the RFC! Per review #2384 (comment), this RFC is hereby closed. |
This RFC reserves two keywords for the next available period of keyword reservation. The
unless
anduntil
keywords act as logical inverses ofif
andwhile
, and are intended for use where inversion of the condition being tested is not readily available.Rendered