News for hackers. Stuff that matters.
Re:Why You Should Always Use === and Other Bad Practices by inglor on Sunday February 09, 2014 @06:49PM (#7208064)
Not to mention the anti pattern of doing this in the first place.

When manipulating collections - you almost always want .map .filter .reduce .some .all or a variation of thereof and not a plain old for loop for this sort of thing, doing this a million or a billion times a second theoretically shouldn't matter. (explained in : http://stackoverflow.com/a/17253577/1348195)

Also, checking for instanceof Array is a JS anti pattern to begin with and makes code a lot less generic.

Re:Why You Should Always Use === and Other Bad Practices by kzahel on Sunday February 09, 2014 @08:03PM (#7208424)
I prefer for loops because they have easier to read and debug exception stack traces. And typing for(i=;...) is calming for me.
Re:Why You Should Always Use === and Other Bad Practices by goldenkey on Sunday February 09, 2014 @06:53PM (#7208084)
I agree that the Array methods are extremely useful other than their ugly performance-sacrificing function scope. In this case though, when you need alternate behavior for the first index, it is much clearer to read a standard for loop with some precursor code behind it, than to read a forEach loop with an if-else.
Re:Why You Should Always Use === and Other Bad Practices by inglor on Sunday February 09, 2014 @07:06PM (#7208155)
Really? You find the above loop more readable than:

    if(array.length > 0) doFunction(array[0]);
    array.slice(1).forEach(doOtherFunction);
Re:Why You Should Always Use === and Other Bad Practices by goldenkey on Sunday February 09, 2014 @07:10PM (#7208172)
You're kind of cheating because you're using slice which will create a copy of the Array, and that's not cheap if the array is large.
Re:Why You Should Always Use === and Other Bad Practices by inglor on Sunday February 09, 2014 @07:15PM (#7208197)
People use arrays for things like queues and stacks all the time in JavaScript - they're _much_ slower than hand rolled collection (eg. http://jsperf.com/deque-vs-array-2 ) - why not micro optimize that as well?

If you have a very large array of course optimization can/should be considered but that's simply not the average case.

Re:Why You Should Always Use === and Other Bad Practices by goldenkey on Monday February 10, 2014 @02:12AM (#7209595)
I actually like the slice code for it's ease of readability. Functional methods are extremely nice and I hope they get faster and faster with the optimization of JS JITs.

I never heard of Dequeue [1], that is mighty cool. I agree that premature optimization is not good - but when it can be done cleanly without hurt to the readability of the code, I'd say to keep it in ones' repertoire, to effectively write more performant code, more often, on average.

[1] http://code.stephenmorley.org/javascript/queues/

Re:Why You Should Always Use === and Other Bad Practices by magicalist on Sunday February 09, 2014 @08:46PM (#7208589)
I see your point, but it's a bit of a stretch to call a style preference an anti-pattern. You even caveat it yourself in your stackoverflow response: "it's also a lot more readable (at least to me)".

Agreed on the hideousness of that 'instanceof Array' check.