I appreciate all feedback on this Array extension.

> Why do the function names have underscores when "camel-humped" names
are
> the customary syntax in ActionScript

It's how Ruby does it and I'm learning Ruby so I guess it just carried
over.  I've changed them to AS formatting.


> Some of the names could be clearer:

All but two of these method names came from the Array classes in Ruby,
php and Java.  If they're good enough for those, they're good enough for
AS.  :)


> - "nitems" looks like "number of items" (i.e., "length"); why not
> "numSetItems" or "countSetItem"?

Yeah, I didn't think it was very descriptive either, but it returns the
number of non null/undefined items in the array (which, at the moment, I
don't see as very useful, hehe).  Perhaps it could be notNullCount()?
This method actually inspires me to create a more useful method that I
think is missing: count.

// Returns the number of obj found in the Array.
Array.prototype.count = function(obj) {
        var c = 0;
        var a = this.length;
        if (obj instanceof Array) {
                while (--a -(-1)) {
                        if (this[a].eql(obj)) c++;
                }
        } else {
                while (--a -(-1)) {
                        if (this[a] == obj) c++;
                }
        }
        return c;
};


> - "rindex" is a bit confusing

I've renamed it lastIndexOf to match the String method which does the
same thing.


> - "some" -- maybe "forSome", or "exists"? (Also, "every" makes more
> sense to me as "forAll".)

every and some come from php.  But you bringing this up made me think
about it, and I've concluded that 'any' is a more descriptive method
name (and one less character to type!). 'any' and 'every' go together
well (like chocolate and peanut butter).  I've renamed 'some' to 'any'.


> - "eql" -- "equals" is far more standard

eql is what is used in Ruby, while Java uses equals.  I don't know if
there's a clear standard.  I like Ruby.  I think it's a great language.
I have no problem with shaving a few chars off for quicker typing,
especially if "equals" ever enters into the language.  eql is more
likely to not conflict with anything.


> - "include" is pretty close to a reserved word

You're right.  I've renamed it 'has', which I think is perfect, and,
coincidentally, still maintains alphabetical order without having to
move it.  :)


> - the "delete" functions don't so much "delete" (i.e., totally
destroy)
> as "remove" or "strip".

They do delete - from the Array.  This method belongs to the Array
class.  Hence, it's doing exactly what it says and what you expect -
deleting an element from the Array.  Once you delete it from the Array,
it's no longer in the Array.  It's not Object.delete, it's Array.delete.
Delete is the original name of the method in Ruby, but delete is a Flash
native method and cannot be assigned to a function.  So, I've used
deleteAll, deleteAt and deleteIf.


Thanks!

-Steven

_______________________________________________
Flashcoders@chattyfig.figleaf.com
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

Reply via email to