I wouldn't agree that either if(this.length == 0) or iterating over
object keys is sloppy practice, for standard application development.
When creating a class library that needs to be bulletproof, as they are
doing with these Array extensions, you should be more careful.
Specifically, checking if(!this.length) is good if length may be
undefined, but what about if some crazy person sets length to a string?
Iterating over object/array keys is fine, throwing an error because you
find an unexpected key is not (particularly in core library code, not
application code).
I too would like to commend you guys for sharing this code - it will
certainly be quite useful in future projects.
Regards,
Grant Cox
js wrote:
As a relative newcomer to Actionscript, I have found the entirety of
this thread very useful. I want to thank all of you for sharing this
code, as well as providing a considerable amount of insight to those
of us lurking in the shadows.
I was fairly surprised to see that if(this.length == 0) is considered
sloppy opposed to (!this.length); conjointly, I had no idea that
iterating through an array in the way you described was bad practice
either. I'm sure I've done it quite a few times myself, unaware of the
consequences.
It would be very beneficial for those of us who are not up to such
(relatively) meticulous levels of coding practice if there was some
sort of resource which enumerated a list of best coding practices when
optimizing for speed--something along the lines of the similarly
titled article in the flash documentation but aimed at the
"middle-class" coder.
I don't think I would be the only individual to appreciate such a
resource; if anyone knows of something similar, do share!
Joseph
Steven Sacks | BLITZ wrote:
DataProvider is not secretly decorating things, BUT something
somewhere
in the V2 stuff is iterating over the array object itself, and is
silently blowing up when it finds these extra functions. I've had a
similar problem when some third party code was adding a function to
object.prototype, and the WebService object took a dump (it iterates
over a hash object and sees something weird and throws an error).
This is an example of poor coding by MM's component writers. You
shouldn't be iterating through enumerable arrays using for (var a in
this) because you're going to pick up all the methods of the Array
object, as well. It's just sloppy coding due to how loose Flash is with
its typing. I always try to write as careful code as possible to avoid
the oh so enticing opportunities flash provides for sloppy coding.
Things like if (!this.length) versus if (this.length == 0)...
However, using ASSetPropFlags is the best solution to hide functions so
they don't appear when you iterate through an Array object.
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com