foreach
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jun 12 12:10:10 PDT 2014
On Thu, 12 Jun 2014 14:55:52 -0400, Andrew Edwards <ridimz at yahoo.com>
wrote:
> On 6/12/14, 2:40 PM, Steven Schveighoffer wrote:
>> On Thu, 12 Jun 2014 13:36:20 -0400, Ary Borenszweig
>> <ary at esperanto.org.ar> wrote:
>>
>>> On 6/12/14, 2:11 PM, Steven Schveighoffer wrote:
>>>> On Thu, 12 Jun 2014 11:00:11 -0400, Manu via Digitalmars-d
>>>> <digitalmars-d at puremagic.com> wrote:
>>>>
>>>>> I often find myself wanting to write this:
>>>>> foreach(; 0..n) {}
>>>>> In the case that I just want to do something n times and I don't
>>>>> actually care about the loop counter, but this doesn't compile.
>>>>
>>>> The compiler has to assign a variable to this somehow so it can
>>>> increment and test. Naming it isn't the worst thing in the world. As
>>>> others have said, pick an uncommon name.
>>>>
>>>>>
>>>>> You can do this:
>>>>> for(;;) {}
>>>>>
>>>>> If 'for' lets you omit any of the loop terms, surely it makes sense
>>>>> that foreach would allow you to omit the first term as well?
>>>>> I see no need to declare a superfluous loop counter when it is
>>>>> unused.
>>>>
>>>> But that doesn't increment a variable and test it. If you wanted to
>>>> loop
>>>> for N times, you need a variable.
>>>
>>> The compiler needs a variable. The programmer doesn't.
>>
>> In response to both you and HS Teoh, so what? It's not hard to create a
>> variable, just do it. This seems like the most insignificant time-saving
>> feature that will really have almost no impact on anybody. It's not
>> worth the risk it adds some bug to the compiler to add this feature.
>>
>> -Steve
>
> Steven, there is not one thing that makes D great. There are many.
> Dissected and viewed individually most people would regard the
> insignificant: much like you are doing here. But the aggregated whole
> that is D today, is a thing of beauty. And it wouldn't be that way were
> it if not for these ostensibly trifling features.
Sorry, saving 1-2 characters typing is really minor. This does not, in my
opinion of course, have any significant improvement on usability for D. It
simply does not carry it's own weight, and the potential to create bugs in
the foreach handling would be not worth the risk.
Typically, one uses i,j,k, etc for loops indexes. It's not so much more
difficult to do foreach(i;... vs. foreach(;...
>
> While I do not see this as a showstopper for anyone, including, it
> doesn't warrant such vehement attack. It is a convenience feature that
> improves the overall experience of the D programmer. A plus in my mind
> and worthy of the time required to discuss, agree upon a solution and
> implement.
It's not an attack of any kind, it's just a rebuttal. It in no way
reflects on the proposer or the defenders of the proposal. If there is
some significant improvement to be shown, I happily would reconsider my
position. Can you name a place where the improvement is more than just
saving the typing of 'i', 'j', or 'k'?
There are hundreds of such proposals made for D, and many of them are
rejected due to the lack of improvement to the language. This is not a
unique situation. The bar must be set high for new features, or we would
have a mess of a language.
I will note obviously that I do not have the final say anyway. It's just
my opinion.
-Steve
More information about the Digitalmars-d
mailing list