On 18 February 2011 15:12, Mark McDonnell <[email protected]> wrote:

> Have a read of this
> http://blog.getify.com/2011/02/pre-maturely-optimize-revisited/ by @Getify
> where he talks about 'im/mature' optimisation and his thoughts on this
> discussion.
>
> Personally, I think that it's such a minor tweak that I will always cache
> the array length. Why wouldn't you? It doesn't make the code un-readable,
> it's obvious to any level developer what's happening (i.e. it's not some of
> the more cryptic 'micro-optimisations' that you can see sometimes), and it
> does have a testable impact on performance if you don't do it. So (to me) it
> seems like an easy choice to just go with caching the length.
>
> Kind regards,
> Mark
>
>
Thanks Mark, all good points, and a good read. However, in that blog, he
does specifically say:

 Also, notice: I am *not* focusing on esoteric and minute micro-performance
details (as some do, and many assumed I was). I made no mention of things
like array.push() vs. array[array.length], or str += "..." vs. str =
arr.join(), or ++i vs. i++, or for (i=0; i < arr.length; i++) {...}vs. for
(i=0, len=arr.length; i<len; i++) {...}, etc etc etc.


My feeling is that it does reduce the readability slightly, and I'm not sure
whether that's worth it when i *know* it's not going to affect performance.

Then again, if I got used to using it consistently, the readability issue
wouldn't be so big a deal.

-- 
Nick Morgan
http://skilldrick.co.uk
@skilldrick <http://twitter.com/skilldrick>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to