-
Notifications
You must be signed in to change notification settings - Fork 204
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
The Style/AndOr rule autofix prevents using "and" and "or" as control-flow modifiers #73
Comments
I had a tough time understanding what's happening in the first example, which leads me to think keeping this cop is a good idea. I've become less of a fan of My suggestion is to keep standard as-is, and suggest you turn off that cop in your config. Just my 2¢. |
Yes, I agree with @danielmorrison. I appreciate the thought put into the OP, but I don't see very many defenders of |
FWIW, I really appreciate the use of The different precedence is a feature. If there was no difference, the existence of these different operators wouldn't make sense. Compare the difference between the different block delimiters. The different precedence is what allows for code like foo = bar(baz, qux) or raise 'No bar found' Blanket disallowing foo = bar(baz, qux)
raise 'No bar found' unless foo # Too much emphasis on an error condition foo = bar(baz, qux)
# Way too many lines for an error condition
unless foo
raise 'No bar found'
end |
@danielmorrison do you find any of the 'corrections' easier to understand? Or how would you write it otherwise? |
I prefer either of your alternatives to the original I've been bit (recently even) by code where changing I get that |
I still agree with Daniel. The precedence changes in |
I have some code like this:
Standard changes it to this:
Does anyone write code like that? I think using
||
and&&
for control flow is a bad idea because you need to pay close attention to how things are parenthesized. Maybe the idea is that you'd get used to your code being autocorrected this way and choose to write it a different way in the future.Here are a couple of other ways to write it:
I guess that's OK; it just chops up one line into two without a good reason.
This requires two blocks:
I frequently use
and
andor
for control flow, and I'd miss them if I weren't able to use them. Maybe their misuse in boolean expressions is bad enough to outweigh their succinctness and expressiveness in control flow.I appreciate what you're doing with this project!
The text was updated successfully, but these errors were encountered: