Programming Languages Have Social Mores Not Idioms
71–80 of 179 posts
Re: Programming Languages Have Social Mores Not Idioms
#72Earlier quoted context omitted.
I see your concern, if I was a beginner and I googled around I might be inclined to learn the supposedly good looping which might be difficult.
Oh, no concern at all about the ruby style guide. I even point people at it in the book so they can start grasping and writing code with other people. My mention of the guide is not intended as a knock on the guide at all.
Re: Programming Languages Have Social Mores Not Idioms
#73Re: Programming Languages Have Social Mores Not Idioms
#74Re: Programming Languages Have Social Mores Not Idioms
#75Earlier quoted context omitted.
Ruby for-loops have unusual scoping of loop variables, and if you're not familiar with this it can prove to be a source of bugs. I was bitten by this some years ago when I was first learning Ruby, and it took me a while to track down the problem. An "each" block has the scoping you'd expect, and is more consistent with the rest of the Ruby looping constructs (like select/filter or collect/map). It's not a huge deal,…
for-loops and .each had weird scoping rules until Ruby 1.9. In Ruby 1.9 for some weird reason they fixed .each but not for-loops. No idea why. So, if you're saying use .each for technical solution to a problem in Ruby, then your proposed solution only works in some versions of Ruby.
Re: Programming Languages Have Social Mores Not Idioms
#76Re: Programming Languages Have Social Mores Not Idioms
#77Re: Programming Languages Have Social Mores Not Idioms
#78I think I would rather teach that #each is a method that iterates over the elements of the array calling the code block for every element.
This only requires you to teach variables, arrays, the if statement, goto/jumps and objects with their methods.
And frankly it being ruby, I don't think it's bad at all to teach objects and their methods, before teaching iterations.
Maybe it's not in line with your hard way philosophy, but explaining for loops with goto/jumps seems a bit abstract to me. Don't you need to explain how instructions are mapped to memory addresses and the instruction register to really do so?
An each method can be explained with a simple recursive function, no need to dive into hocus pocus CPU details.
Re: Programming Languages Have Social Mores Not Idioms
#79The useful content of the article is overshadowed by the vainglorious hyperbole.
Re: Programming Languages Have Social Mores Not Idioms
#80Earlier quoted context omitted.
You are right, and once again I am not against using functional programming, OOP, message passing, or any of the things I mention about .each. I'm against using .each as a first looping construct. In fact, go look at your supposedly better last line of code and tell me if you think a newbie would even begin to comprehend that? Hell I'm a programming veteran and Ruby veteran and I want to metaphorically punch you in t…
To clarify, I don't think my original post implied that you were against teaching people how to learn each. Nor do I want to start out teaching beginning rubyists everything all at once. It was more to point out how important the mindset of each is. That's the mindset that you want to reach. And I'm not sure that teaching a construct that you'll never end up using is helpful. I think it just creates a mental construc…
But that was precisely Zed's point! You will certainly end up using it, though you may never use it in Ruby. .each is not transferable, and for-loops are. Zed's teaching Ruby as an introduction to programming, not just to Ruby in itself.