-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Make the compiler report 'and'/'or' operators as obsolete #9115
base: master
Are you sure you want to change the base?
Conversation
CT Test Results 22 files 851 suites 6h 28m 20s ⏱️ For more details on these failures, see this check. Results for commit af25af7. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
f87ae5a
to
b20ddac
Compare
b20ddac
to
aa1be07
Compare
Should |
Nah, I thought I'd try to introduce && and || instead. Honestly I'm not sure. I think there's a bit of pedagogical value and visibility in the andalso/orelse keywords. (These names go back to Standard ML, if anyone wonders.) As I was replacing the occurrences of and/or in the code, I saw that a tiny 'or' or 'and' was easy to miss, but 'orelse' and 'andalso' stood out much better. So it might not even be worth doing, even if it saves horizontal space. We can submit a followup EEP in 2030 and see what people think then. 😜 Btw, replacing existing uses showed mainly two categories: 1) valid ways of writing more complex guards or other nested logical expressions (not all that common, in comparison to the total size of the codebase), and 2) as a personal style thing, where you could just as well have used comma and semicolon in a guard instead (only found in a few isolated modules) , possibly due to a lack of understanding of guard syntax. Also, a some of these occurrences probably go back to before semicolon was added to guards. |
Indeed. I just tried finding them in RabbitMQ to fix them and it is clearly non-obvious. The other two have this advantage. |
aa1be07
to
a7f60e4
Compare
@essen I did however come up with another use for 'or' (doesn't strictly require removing the original). Here's a very small proof of concept: master...richcarl:otp:or-patterns - e.g. |
That would definitely remove a frequent pain point with regard to case clauses! 👍 |
Yes. It might be technically possible to use |
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.
Personally, I think that ,
and ;
should be used if possible. I know that everyone does not agree with that.
As a compromise, if a guard only uses and
, replace all and
operators with commas. I think that is reasonable because ,
has been there since the beginning.
I strongly suggest that you remove the unnecessary parentheses on either side of andalso
/orelse
; not having to add those parentheses is one of the advantages over the older operators.
a7f60e4
to
af25af7
Compare
Updated like @bjorng suggested. Definitely yields nicer code, but a bit harder to review. |
The strict 'and'/'or' operators are mostly useless, confusing for newcomers, rarely used in practice, and when used they can always be replaced with andalso/orelse. I think they should be obsoleted and subsequently dropped from the language.