krainboltgreene Kurtis R.G.
My nephew is learning the wrong Ruby practices via Learn Ruby The Hard Way by @zedshaw…And yet still grateful for it's existence.

August 18, 2012 #

zedshaw zedshaw
@krainboltgreene <sigh> Let me guess, .each instead of for-loop?

August 18, 2012 #

krainboltgreene Kurtis R.G.
@zedshaw Nah, minor things that Rubyists just don't do. Although in 1.9 there is a difference between those two.

August 18, 2012 #

zedshaw zedshaw
@krainboltgreene Like what? If it's not masturbatory "idioms" that can be explained then I'll change it.

August 18, 2012 #

krainboltgreene Kurtis R.G.
@zedshaw What do you mean by masturbatory idioms? I mean, to be honest I'm fine just pointing out the difference.

August 18, 2012 #

zedshaw zedshaw
@krainboltgreene .each rather than for-loop. Excessive blocks. knee-jerk "OMG" when really only a few chars differ. That kind of stuff.

August 18, 2012 #

krainboltgreene Kurtis R.G.
@zedshaw None of that so far, but I wonder if you realize there is an actual real difference (that can catch newbies) between #each and for?

August 18, 2012 #

zedshaw zedshaw
@krainboltgreene So it was .each vs. for-loops. Enlighten me. What's the difference that is so important?

August 18, 2012 #

krainboltgreene Kurtis R.G.
@zedshaw He's not at loops yet, so no. I'm only talking about it because you brought it up. Here's the diff: gist.github.com/3385139

August 18, 2012 #

zedshaw zedshaw
@krainboltgreene Huh? Those aren't exercise ex18.rb and ex19.rb. What is that?

August 18, 2012 #

krainboltgreene Kurtis R.G.
@zedshaw No no, the file name is in reference to Ruby version 1.8 and 1.9

August 18, 2012 #

krainboltgreene Kurtis R.G.
@zedshaw I'm sure you'll figure out the reason, but just in case: for-loops stay in same scope, in 1.9 blocks have their own scope.

August 18, 2012 #

krainboltgreene Kurtis R.G.
@zedshaw Since Ruby is a language with mutable variables, for-loop (and 1.8 #each) will rewrite the variable reference.

August 18, 2012 #

zedshaw zedshaw
@krainboltgreene Oh, ok 18.rb is for Ruby 1.8. Alright, so now why does that matter? Is there an exercise that trips people up with that?

August 18, 2012 #

avdi Avdi Grimm
@zedshaw @krainboltgreene probably the kind of feedback you hate, but it's a bad habit that may bite them eventually.

August 18, 2012 #

zedshaw zedshaw
@avdi @krainboltgreene What's a bad habit? Using a for-loop or reusing variable names?

August 18, 2012 #

steveklabnik スティーブ クラブ肉
@zedshaw @avdi @krainboltgreene it’s that they have different scoping rules, more than ‘re-writing’

August 18, 2012 #

steveklabnik スティーブ クラブ肉
@zedshaw @avdi @krainboltgreene it’s one of those things that you will sometimes get a ‘bug’ and you don’t know what’s wrong

August 18, 2012 #

zedshaw zedshaw
@steveklabnik @avdi @krainboltgreene Yes, but even .each is only fixed in later versions, so "never use for-loop" is a stupid edict.

August 18, 2012 #

steveklabnik スティーブ クラブ肉
@zedshaw @avdi @krainboltgreene we already had a RL discussion about this so you know my feelings :)

August 18, 2012 #

avdi Avdi Grimm
@zedshaw @steveklabnik @avdi @krainboltgreene wait, it's stupid advice just because an older version of Ruby behaved differently?

August 18, 2012 #

zedshaw zedshaw
@avdi It's stupid advice because it doesn't work in all versions, and the *real* problem is reusing variable names when you shouldn't.

August 18, 2012 #

avdi Avdi Grimm
@zedshaw it works fine in all versions of Ruby. It has less potential for surprise in newer versions. Where is the downside?

August 19, 2012 #

zedshaw zedshaw
@steveklabnik @avdi @krainboltgreene I think it's more "don't reuse variable names" and "Ruby's just broke here" are better.

August 18, 2012 #

zedshaw zedshaw
@krainboltgreene So what you're saying is, Ruby has a broken for-loop scope and they only fixed .each in 1.9. Sounds like Ruby being Ruby.

August 18, 2012 #

krainboltgreene Kurtis R.G.
@zedshaw They fixed blocks, not specifically each, and yeah, it sucks. That said apparently because of this for-loops are "faster" (heh)

August 18, 2012 #

zedshaw zedshaw
@krainboltgreene Ok, so not a big deal then. Just a quirk and nothing to really worry about.

August 18, 2012 #

zedshaw zedshaw
@krainboltgreene But, take an exercise code, and rewrite it the way you think it should be, or show me something "bad" so I can fix it.

August 18, 2012 #

krainboltgreene Kurtis R.G.
@zedshaw Sure, I'll give it a shot, but I want to reiterate it's mostly minor things that I've been able to point out to him.

August 18, 2012 #

zedshaw zedshaw
@krainboltgreene Ok, like what? If it's just little things then "wrong Ruby practices" is the wrong wording. If they're huge then tell me.

August 18, 2012 #