Fwd: [dojo-contributors] [feedback wanted] Preferred Iteration forms

Tom Trenka ttrenka at gmail.com
Mon Apr 3 17:26:41 EDT 2006


Including the dojo.lang dependency will add 327 lines of code plus the
overhead of the dojo.require statements (if not used as part of a build
package).  So adding dojo.lang.forEach may *seem* like a convenience but it
adds a bit of overhead.

Once again, there's no reason why you couldn't use dojo.lang.forEach on your
own if you wanted to use that in conjunction with the Collections code.

On 4/3/06, Sandro Magi <smagi at naasking.homeip.net> wrote:
>
> Tom Trenka wrote:
> > Right now the collections code has no dependencies whatsoever, and I'd
> > prefer to keep it that way.  I also feel that writing a function to
> > encompass something that's accomplished in two lines in other code is
> kind
> > of a waste of time.
> >
>
> 1. Dictionary.contains, Dictionary.clone, Dictionary.entry are all a
> single line of code. More lines of code does not imply usefulness. The
> question is: how often are those 3 lines of code likely to be repeated,
> and thus, how much typing will we be saving, not to mention download size.
>
> 2. Looking at the Dojo code at the moment, I see:
>   a) DictionaryIterator (object with 2 methods & 5 properties: 33 lines
> of code)
>   b) Dictionary.getValueList()  (8 lines of code)
>   c) Dictionary.getKeyList()  (8 lines of code)
>   d) Dictionary.getIterator()  (3 lines of code)
> Total: 52 LOC
>
> Implementation of forEach for Dictionary:
>
> this.forEach = function (callback) {
>   dojo.lang.forEach(items, callback, true);
> };
>
> That's 52-3=49 lines of less code. If you still want getValueList() and
> getKeyList():
>
> this.getKeyList = function(){
>   var arr = [];
>   this.forEach(function(key) { arr.push(key); } );
>   return arr;
> };
> this.getValueList = function(){
>   var arr = [];
>   this.forEach(function(key) { arr.push(items[key]); } );
>   return arr;
> };
>
> 52-13 = 39 lines of less code for this one object. Same deal with
> ArrayList and Iterator (though the savings are slightly less). A similar
> savings is available for all of the other collections if you adopt the
> same pattern. I'm not really seeing the downside of leveraging your
> existing code. Unless a dependency on dojo.lang.forEach is somehow a
> downside...?
>
> Sandro
>
> > I'm also not talking about adding new, untested functions; I'm asking
> > because the iterator code in the Collections has been somewhat borken
> for a
> > while, and I need to fix it (two or three bugs filed against it).  The
> > imperative Iterator code has been there from the beginning, and the
> reason
> > why it got borken in the first place is because I wrote it following one
> > style, and someone tried to correct it to follow another.
> >
> > trt
>
> _______________________________________________
> dojo-contributors mailing list
> dojo-contributors at dojotoolkit.org
> http://dojotoolkit.org/mailman/listinfo/dojo-contributors
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.dojotoolkit.org/pipermail/dojo-contributors/attachments/20060403/812da6ef/attachment.htm 


More information about the dojo-contributors mailing list