OT: for (;;) {} vs while (true) {}

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 25 08:57:50 PST 2016


On Friday, November 25, 2016 11:01:56 Andrei Alexandrescu via Digitalmars-d 
wrote:
> On 11/25/16 10:29 AM, Adam D. Ruppe wrote:
> > Let's just close the book and officially put the status quo on optional
> > parenthesis in stone: they are optional on zero-argument calls,
> > regardless of @property, and that isn't going to change.
>
> Agreed. -- Andrei

That's fine, but it doesn't help any when the callable can't be used with
optional parens - which is the case with a type overloading opCall as well
as function pointers and delegates. And the real problem here isn't whether
someone chooses to call a function with parens or not in some chunk of their
code. The problem is whether _generic_ code does it. If you're calling
something with parens in generic code, then you need to be able to rely on
it working with parens regardless of the types of the function arguments.
And if you're calling it without parens, then you need to be able to rely on
it working _without_ parens regardless of the types of the function
arguments.

Stuff like empty, save, and length in the range API all of the same problem
as popFront and popBack except in reverse. In their case, they need to be
called without parens, or the code won't work with some ranges (the most
obvious case being for empty being infinite ranges, and the most obvious
case for length being dynamic arrays).

So, restricting popFront and popBack to being functions so that they can
always be called without parens is fine, but it's still the case that you
can't be completely lax with where you do or don't use parens in generic
code.

- Jonathan M Davis



More information about the Digitalmars-d mailing list