Ryan Gahl wrote:
[...]
> Using "for property in object" with an Array completely forgoes any
> advantages of even using the Array object.

I think you've overstated your case.  The fact that for..in is used has
no effect on the array itself, how can it *completely* forgo (as in
remove the benefit of) an array's advantages?

For example, for..in is used in mathematical operations for sparse
arrays - it can be significantly faster (depending on how sparse the
array is) than iterating over all the elements using the length
property.


> In fact, you might as well just
> use an Object then. I've said it before, and I'll keep screaming it... don't
> use an Array like a hash! Use indexes and push(), splice(), etc... or just
> don't use Array.

A good suggestion, but there are circumstances where using for..in with
an array makes sense.


> On 11/2/06, Christophe Porteneuve <[EMAIL PROTECTED]> wrote:
[...]
> > Well, for/in is not exactly intended for array looping.  It's a property
> > iteration mechanism.  Codes that use it for array looping are relying on
> > the fact that arrays are not extended in any way, which isn't very
> > clean, because prototype-extension-based frameworks are gaining major
> > foothold in the web client-side world.

If you are using multiple libraries, you should have a strong
preference for those that don't modify built-in objects.

[...]
> > The for/in code for array iteration does something inadequate, inasmuch
> > as this doesn't play well with "programming in the large" (in this
> > context, playing nicely with large amounts of external code and possible
> > object extensions).

I think you have that backwards - libraries that modify built-in
objects don't play well with code that expects those objects to be
unadulterated.


-- 
Fred


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs
-~----------~----~----~----~------~----~------~--~---

Reply via email to