-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Allow option for preferring for
loop over each
block
#654
Comments
The scoping of |
@agrimm I have to assume that "more readable" in this case means "more familiar to users of other languages coming to Ruby for the first time". On the other hand, your side-effects argument does hold some merit (though there are a couple other methods specifically for side-effects in |
👍 on @agrimm's suggestion. @lee-dohm The readability of @bbatsov If the surrounding scope is small (we're enforcing 10 line methods by default), then the scoping is no big deal. I still prefer |
@jonas054 I don't mind adding this, if you're willing to implement it :-) |
Yes I think I am. 😄 |
[Fix #654] Add config option EnforcedStyle to For cop.
Currently, the For cop detects any use of
for
, and suggests replacing it witheach
. I'd like a configuration option that makes the cop instead suggest replacing a multi-lineeach
block with afor
loop.Under that configuration, the following would be ok:
but the following would not be ok:
which should be transformed into
As to why some people would prefer
for
loops overeach
?Dave Thomas advocates
for
loops because they're more readable. https://twitter.com/JonRowe/status/306599505967607808I prefer
for
loops because when you're usingeach
, you're doing something for side-effects, rather than to get a value. I may as well make such code look different to functional programming (things likemap
andfind_all
), because I want potentially problematic code to look different from normal code, and I regard side-effects as potentially problematic.This is probably not suitable for auto-correction, because scoping for
for
loops is different to that ofeach
blocks.The text was updated successfully, but these errors were encountered: