OT: for (;;) {} vs while (true) {}
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Fri Nov 25 04:59:07 PST 2016
On 11/25/2016 07:53 AM, Dennis Ritchie wrote:
> On Friday, 25 November 2016 at 11:20:24 UTC, Jonathan M Davis wrote:
>> Probably the complete lack of a condition to test in for(;;). I
>> confess that I was shocked when I found out that it was legal to have
>> a for loop without a condition. That seems like doing while() or if(),
>> which makes no sense. So, I never use for(;;) and wish that it didn't
>> exist, but it does, and some folks use it. So, I have to live with the
>> possiblity of dealing with it when dealing with code written by other
>> people. But I won't ever use it.
>
> IMO, it is very convenient for system programming guru. It is believed
> that it came from the K&R.
>
> For example, this option is definitely very convenient to use:
> https://github.com/dlang/phobos/blob/master/std/algorithm/comparison.d#L591
I like that function. If I were to review it now, I'd approve with these
nits:
* drop the parens for popFront
* s/-cast(int)!r2.empty/-int(!r2.empty)/
* Merge with the cmp implementation for strings and simplify the
constraint from
if (isInputRange!R1 && isInputRange!R2 && !(isSomeString!R1 &&
isSomeString!R2))
to
if (isInputRange!R1 && isInputRange!R2)
i.e. it's not relevant to users that the string version has a distinct
implementation.
In fact I suggest someone implements this.
Andrei
More information about the Digitalmars-d
mailing list