View mode: basic / threaded / horizontal-split · Log in · Help
October 19, 2006
Re: foreach, an analogy
John Reimer wrote:
> On Wed, 18 Oct 2006 20:43:13 -0700, Bill Baxter 
> <dnewsgroup@billbaxter.com> wrote:
> 
>> Gregor Richards wrote:
>>> Bill Baxter wrote:
>>
>>> The bigger door is 'for'.  'foreach' is nothing but a convenient 
>>> wrapper around 'for'.  And don't you OOphiles go telling me that your 
>>> fancy class foo that has iteration /needs/ 'foreach':
>>>   for (auto bar = foo.begin(); !(bar is null); bar = foo.iterate(bar))
>>> Is it less pretty than foreach?  Yeah.  That's why foreach exists.
>>
>> :-)  Heh heh.
>>
>>> But don't go saying that the reverse foreach is a band-aid patch, 
>>> because
>>> both forms are just convenience wrappers around the far more powerful 
>>> and useful 'for'.
>>
>> Yeh, for is like a piece of wood.  You can do anything with it. 
>> Including make a door.  But sometimes its better just to have the door 
>> pre-made.
>>
>>> Your small door is actually the screen door.
>>
>> Lots of little holes?  Maybe.  But screen doors have their uses too.
>> Much better for the summertime to help make the livin' easy. ;-)
>>
>> --bb
> 
> 
> Don't screen doors keep the bugs out? ;)
> 

LOL!  Yes, they do! ;-)

--bb
October 19, 2006
Re: foreach, an analogy
I just want to put my heartfelt cry here. Foreach_reverse is evil! I like D,
but such a things just increase probability that it never will be not a
toy. Implement an iterators integration into foreach, or do something else,
but do in intensive way, not extensive!
Walter, read some books about language architectures and design, please!
There are lots of info in the Internet.
October 19, 2006
Re: foreach, an analogy
Vladimir Kulev wrote:
> I just want to put my heartfelt cry here. Foreach_reverse is evil! I like D,
> but such a things just increase probability that it never will be not a
> toy. Implement an iterators integration into foreach, or do something else,
> but do in intensive way, not extensive!

I disagree. foreach_reverse is much more clear and concise than any 
solution using iterators. I don't get why so many people are griping 
about it. It's just sugar, much like foreach itself. If you don't like 
it, don't use it. You can implement iterators yourself, or use delegates 
with a plain foreach to get any sort of order traversal you like. Don't 
take away foreach_reverse from those of use who actually like it.

> Walter, read some books about language architectures and design, please!
> There are lots of info in the Internet.

Oh, that's a gem.
October 19, 2006
Re: foreach, an analogy
Gregor Richards wrote:
> The bigger door is 'for'.  'foreach' is nothing but a convenient wrapper 
> around 'for'.  And don't you OOphiles go telling me that your fancy 
> class foo that has iteration /needs/ 'foreach':
>   for (auto bar = foo.begin(); !(bar is null); bar = foo.iterate(bar))
> Is it less pretty than foreach?  Yeah.  That's why foreach exists.  But 
> don't go saying that the reverse foreach is a band-aid patch, because 
> both forms are just convenience wrappers around the far more powerful 
> and useful 'for'.

The C++ iterator approach has a serious problem: collections need to be 
linearized. This is not reasonable for some types of collections, such 
as a binary tree, which really wants to be traversed in a recursive 
descent fashion, rather than linearly.
October 19, 2006
Re: foreach, an analogy
Vladimir Kulev wrote:
> I just want to put my heartfelt cry here. Foreach_reverse is evil! I like D,
> but such a things just increase probability that it never will be not a
> toy. Implement an iterators integration into foreach, or do something else,
> but do in intensive way, not extensive!
> Walter, read some books about language architectures and design, please!
> There are lots of info in the Internet.

Not many programmers can implement an iterator correctly. For the moment 
let's assume that's not an issue. But still foreach is much more likely 
to be done correctly, and it is much easier to look at it and see that 
it is correct.
October 19, 2006
Re: foreach, an analogy
Did you mean writing own class with iterator, or using standard classes with
one?
October 19, 2006
Re: foreach, an analogy
Vladimir Kulev wrote:
> Walter, read some books about language architectures and design, please!
> There are lots of info in the Internet.



Thanks, this just made my morning :D
October 19, 2006
Re: foreach, an analogy
Vladimir Kulev wrote:

> I just want to put my heartfelt cry here. Foreach_reverse is evil! I like D,
> but such a things just increase probability that it never will be not a
> toy. Implement an iterators integration into foreach, or do something else,
> but do in intensive way, not extensive!
> Walter, read some books about language architectures and design, please!
> There are lots of info in the Internet.

I absolutely agree!

-- 
'non-optimal' is a politically correct term for shit
October 19, 2006
Re: foreach, an analogy
Andrey Khropov wrote:
> Vladimir Kulev wrote:
> 
>> I just want to put my heartfelt cry here. Foreach_reverse is evil! I like D,
>> but such a things just increase probability that it never will be not a
>> toy. Implement an iterators integration into foreach, or do something else,
>> but do in intensive way, not extensive!
>> Walter, read some books about language architectures and design, please!
>> There are lots of info in the Internet.
> 
> I absolutely agree!
> 

I would guess that Walter has forgotten more about language architectures and
compiler design than you two ever knew combined.  foreach_reverse is not a
large enough issue to question Walter's abilities.

If you've listened closely, and I don't think you have, he has said repeatedly
that he sees enough utility (its use w/ arrays) that it's staying.  Give it a
few releases and hopefully this woeful abomination of sugar won't affect you
too much.

BA
October 19, 2006
Re: foreach, an analogy
Walter Bright wrote:
> Gregor Richards wrote:
> 
>> The bigger door is 'for'.  'foreach' is nothing but a convenient 
>> wrapper around 'for'.  And don't you OOphiles go telling me that your 
>> fancy class foo that has iteration /needs/ 'foreach':
>>   for (auto bar = foo.begin(); !(bar is null); bar = foo.iterate(bar))
>> Is it less pretty than foreach?  Yeah.  That's why foreach exists.  
>> But don't go saying that the reverse foreach is a band-aid patch, 
>> because both forms are just convenience wrappers around the far more 
>> powerful and useful 'for'.
> 
> 
> The C++ iterator approach has a serious problem: collections need to be 
> linearized. This is not reasonable for some types of collections, such 
> as a binary tree, which really wants to be traversed in a recursive 
> descent fashion, rather than linearly.

A slight modification can fix that:

 for (auto bar = foo.begin(); !(bar is null); bar = bar.next())


Anyway, my point was merely that 'foreach' is not analogous to the 
too-small-door, since it's merely an alternative to 'for' :)

 - Gregor Richards
1 2 3 4 5 6
Top | Discussion index | About this forum | D home