Template instantiation syntax

Bill Baxter wbaxter at gmail.com
Sat Oct 11 19:02:18 PDT 2008


On Sun, Oct 12, 2008 at 10:46 AM, bearophile <bearophileHUGS at lycos.com> wrote:
> Jarrett Billingsley:
>> It's not "error-prone", it's "you're not used to it."  You very
>> commonly fall into the fallacy that if you think something's
>> bad/confusing/not what you're used to, then _everyone_ must think that
>> way and therefore it _must_ change.  Sorry, that's not the way it
>> works.  I haven't mistyped a foreach loop, ever.  Deal with it.
>
> I remember that when I have discussed about this topic the first time another person has said of sharing this problem of mine with this syntax.
>
> C# foreach syntax uses the "in", and Python too uses it. Both languages are quite more used than D, are modern, and they care about their usability and readability.
>
> If I don't talk about this topic I can't know if it's a common problem, or a personal one.
>
> So even if I am wrong (and I am wrong all the time), and the current foreach syntax of D isn't bug-prone, I think the topic deserves a little discussion, so people can show who's right.

I agree with you, Bearophile.  And I may be the person you remember
agreeing with you before.  So we may be the only two.  :-)   Although
clearly designers of C# and Python thought it looked nicer than other
possibilities, so apparently they agree too.

But anyway it seems not to be an easy change to make it work in D
without ruining the easy syntax parsing.  So another idea for
unambiguous syntax is needed.   An 'of' keyword or make an
in-expression or something.
      foreach(x of thinglist) { ... }
      foreach(x in(thinglist)) { ... }
      foreach(x (in) thinglist) { ... }

But even then, the result has to be so much better than ";" that it's
worth breaking backwards compatibility.  I think that's a hard sell.
";" works and its not totally terrible, and it does have precedent
with the semicolons in regular for loops.

--bb



More information about the Digitalmars-d mailing list