Fwd: [dojo-contributors] [feedback wanted] Preferred Iterationforms

Bill Keese bill at dojotoolkit.org
Sat Apr 15 21:32:50 EDT 2006


Sorry, I want to ask one more question.

You often talk about the iterator's current object, whereas at least in 
java, there is no such thing.  (The iterator is either positioned before 
the first element, between two elements, or after the last element.) 
What was the reason for have a conceptual "current" element?

Tom Trenka wrote:
> The key here is that you can do either if you want to.
> 
> On 4/15/06, *Scott J. Miles* <sjmiles at turbophp.com 
> <mailto:sjmiles at turbophp.com>> wrote:
> 
>      >> while(var item = it.get()){
> 
>     A lot of people (including me) steer clear of using an assignment
>     inside of
>     a boolean expression like that. It tends to be more confusing than
>     necessary.
> 
>      From the style guide:
> 
>      >> 6. Conditionals
>      >>   3. Executable statements in conditionals MUST be avoided.
> 
>      >> because that's an established pattern from C:
> 
>     Yes, but that's one of the ugly things about C. You can write really
>     gnarly
>     complex expressions with all kinds of side effects. Good for kernal
>     hacking
>     in the old days, not so good today.
> 
>     Regards,
>     Scott J. Miles
>     TurboAjax Group
>     http://www.turboajax.com
> 
>     -----Original Message-----
>     From: dojo-contributors-bounces at dojotoolkit.org
>     <mailto:dojo-contributors-bounces at dojotoolkit.org>
>     [mailto:dojo-contributors-bounces at dojotoolkit.org
>     <mailto:dojo-contributors-bounces at dojotoolkit.org>] On Behalf Of
>     Bill Keese
>     Sent: Saturday, April 15, 2006 9:35 AM
>     To: dojo dev.
>     Subject: Re: Fwd: [dojo-contributors] [feedback wanted] Preferred
>     Iterationforms
> 
>     Wow, I didn't even notice this thread before.  To repeat my
>     suggestion from
>     the dojo-interest list, given that you want to combine two features
>     (reading
>     current value and advancing) into one function, you should call the
>     function
>     get():
> 
>     while(var item = it.get()){
>     ...
>     }
> 
>     because that's an established pattern from C:
> 
>     while( (i=getChar()) != EOF )
>     while( (p=gets()) != NULL )
> 
>     Tom Trenka wrote:
>      > I hate to resurrect this, but...
>      >
>      > Aside from "iterator wars", this is what I'm going to go with:
>      >
>      > var it=col.getIterator ();
>      >
>      > while(!it.atEnd()){
>      >     var item=it.current();
>      >     // do stuff
>      > }
>      >
>      > The idea here is that current() not only returns the current
>     item, but
>      > also advances the internal cursor to the next item in the
>     collection.
>      > atEnd() should be obvious. I will also provide an "item" property,
>      > which will be the current item in the collection. Hopefully this is
>      > the best comprimise I can think of.  It should also be able to
>     support a
>     for form...
>      >
>      > for(it.current();!it.atEnd(); it.current()){
>      >    // do stuff.
>      > }
>      >
>      > (still thinking about that one but it should work as long as the
>      > initializer is called)
>      >
>      > ...and I will try to write it so that calling current() past the end
>      > of the collection returns null, so the do...while form should work as
>     well:
>      >
>      > do{
>      >    // something
>      > } while ( it.current())
>      >
>      > (only issue with this form is that there has to be something in the
>      > collection for it to work, but internally you will be able to test if
>      > item == null).
>      >
>      > Would that cover all the bases?  If I have time, I might try to add
>      > functional iteration to the iterators as well, but that's low on the
>      > priority list (fix the imperative first, then look at the
>     functional).
>      > Also, does anyone see any holes with this?  I haven't coded anything
>      > yet (slamming on a project right now) but I thought I would throw
>     this
>      > out in time for the meeting (without getting into another holy war).
>      >
>      > trt
> 
>     --
>     No virus found in this outgoing message.
>     Checked by AVG Free Edition.
>     Version: 7.1.385 / Virus Database: 268.4.1/312 - Release Date: 4/14/2006
> 
> 
>     _______________________________________________
>     dojo-contributors mailing list
>     dojo-contributors at dojotoolkit.org
>     <mailto:dojo-contributors at dojotoolkit.org>
>     http://dojotoolkit.org/mailman/listinfo/dojo-contributors
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> dojo-contributors mailing list
> dojo-contributors at dojotoolkit.org
> http://dojotoolkit.org/mailman/listinfo/dojo-contributors

-- 

Bill



More information about the dojo-contributors mailing list