couple of really noob questions (ranges, toString)

spir denis.spir at gmail.com
Mon Nov 1 19:21:27 PDT 2010


On Mon, 1 Nov 2010 18:47:38 -0700
Jonathan M Davis <jmdavisProg at gmx.com> wrote:

> The best place to start learning about ranges is probably here: 
> http://www.informit.com/articles/article.aspx?p=1407357
> 
> front, popFront(), and empty make perfect sense as they are and work quite well. 
> hasNext() and next() have the serious drawback of mixing iterating through the 
> range and getting an element in it. It's one of the serious flaws in Java's 
> iterators. It's far better to have getting the current or front element be 
> separate from moving or  popping the next one.

Thank for the pointer.
Note That I know exactly nothing of Java. In fact, I used this scheme and those names spontaneously to implement traversal of custom structs in Oberon (that has no such notion).
There's a point I don't understand in your argument: "...the serious drawback of mixing iterating through the range and getting an element in it". Isn't this precisely what popFront() does, stepping and returning an element? Or is "pop" in "popFront" misleading? (I've followed your pointer, but the site is so designed that the article is spread over 15 pages!)
To move forward without popping, you'd need a kind of step() method that just follows the next pointer; really complementary to front(). Or is there something I misunderstand? But since typical use is iteration, does it make sense to separate stepping and reading?
I now realise that my previous comment on the method trio vs my point of view is wrong; the functionality is the same, done the same way, only naming reveals a different pov: next() is popFront() seen differently, hasNext() is !empty().

Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



More information about the Digitalmars-d-learn mailing list