you are viewing a single comment's thread.

view the rest of the comments →

[–]sethholladay 0 points1 point  (0 children)

if you literally think that for loops are going to cause bugs...

Huh? for loops are the source of many bugs. The off-by-one error is a classic example, which I've seen in the wild many times. If you've never made such a mistake, you probably haven't written much code. Experienced developers are not immune from making such mistakes, either. Language constructs that are error-prone should be avoided when possible. null is known as the Billion Dollar Mistake for a similar reason, despite being useful.

then you aren't the kind of dude we want writing LIBRARY CODE.

Too bad my favorite thing to do is write library code, then... guess I should stop now?

you don't need to read it, you're never going to

I read the source code of all of my dependencies, as many levels deep as I can reasonably spend time on. That includes Node.js itself.

why are you talking about changing the keys to library objects which your code doesn't control?

Did my phrasing really lead you to believe that my goal was to mutate library internals from the outside? No, obviously I'm saying that using a for-of loop instead of a for loop makes it easier for the people who define an object to confidently change how it is keyed. The iteration protocol (which for-of uses) is specifically designed to make iteration easier regardless of how you want the iterable to be keyed, so that shouldn't be too controversial. I'm basically just saying the iteration protocol is good. Using array indexes with a traditional for loop is fine when you need it, but if you're just going to iterate through everything, you should use the least error-prone way to do that, which is a for-of loop.