Skip to content
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

for...in loop nitpicks #92

Closed
KaoruDev opened this issue Mar 3, 2015 · 7 comments
Closed

for...in loop nitpicks #92

KaoruDev opened this issue Mar 3, 2015 · 7 comments

Comments

@KaoruDev
Copy link

KaoruDev commented Mar 3, 2015

Not sure if this is the right place to make this issue but I'm see a lot of automated nitpicks with:

Rubyists tend to prefer enumerable methods over for loops. This isn't
a rule, it's more of a strong cultural preference.

Which isn't a 100% true, there is a reason why most don't use for...in and it's because it does not create a closure. i.e.

x = 0
for x in (0..4)
end
x #=> 4

Which can cause some weird bugs.

@kotp
Copy link
Member

kotp commented Mar 3, 2015

So how would you suggest changing the wording? It may be able to be improved.

I would say that most do not use it because they aren't solving problems where the last iterated value is not needed to be kept. Or because of the same reason that people don't tend to use 'or' and 'and' as opposed to || and && especially early on in their development as Rubyists.

I have noticed that as people become more experienced with Ruby they start to use each of these things as intended and where appropriate, because they do see the features and nuances given by each.

And though it can be the source of some weird bugs, I don't think it is the cause of those bugs. The cause is simply not keeping track of your variables.

@KaoruDev
Copy link
Author

KaoruDev commented Mar 3, 2015

ah yes i forgot to put my suggestion!

Perhaps pointing out the behavior of for..in along with your comment:

And though it can be the source of some weird bugs, I don't think it is the cause of those bugs. The
cause is simply not keeping track of your variables.

would suffice. I suppose another good way is to make a concrete example. i.e.

x = 0
for x in 0..4
end
x #=> 4

vs.

x = 0
(0..4).each do |x|
end
x #=> 0

I argue the reason we don't use for..in is it can change the state of our variables without us realizing it. It's not so obvious.

@kytrinyx
Copy link
Member

kytrinyx commented Mar 3, 2015

This is a really great distinction. The comment lives here: https://github.com/exercism/rikki/blob/master/comments/ruby/for_loop/for_loop.md

Do you want to take a stab at improving it?

@KaoruDev
Copy link
Author

KaoruDev commented Mar 3, 2015

ah you found my kryptonite: English! haha I'll take a stab sometime today, thanks for the link =)

@kytrinyx
Copy link
Member

kytrinyx commented Mar 3, 2015

LOL, I'm happy to tweak once you've given it a first pass :)

@KaoruDev
Copy link
Author

KaoruDev commented Mar 5, 2015

Closing, address in: exercism/DEPRECATED.rikki#8

@KaoruDev KaoruDev closed this as completed Mar 5, 2015
@kytrinyx
Copy link
Member

kytrinyx commented Mar 5, 2015

Yepp, thanks! Also: deployed.

gchan pushed a commit to gchan/xruby that referenced this issue Oct 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants