Hacker News new | past | comments | ask | show | jobs | submit login

How is .each any simpler than a for loop, conceptually they do the same thing.



Read the article.


Yeah, I did...


Not well. It's described for the entire final quarter of the article, in the section marked "Why .each Is A Horrible First Looping Construct".


“for” is the raw loopy stuff out of which other looping constructs are made—it’s fairly arbitrary. If you’re implementing an iteration construct, then by all means “for” is the thing to use. But in normal use it’s best to express your intent through more common, composable constructs such as maps, folds, and zips. There’s certainly less overhead in reading a non-trivial loop written as a composition than one written as a raw “for”.

So I don’t think “each” is any better than “for”—in addition to having uglier syntax in Ruby, neither conveys any more information than the other. It’s the same with std::for_each in C++, present only for consistency with its more meaningful siblings.


I have no dog in this fight, I was just calling out the hyperbole on the ancestor comment.


If you didn't get my intent, the last part of the article which you recommended was highly biased and after reading it I was left questioning the author's motive.


I don't see the bias or any reason to question his motive, so no, your intent was not clear. I think you'll need to spell this one out for me.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: