for loop parens

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jul 12 18:26:50 PDT 2013


On Sat, Jul 13, 2013 at 03:19:04AM +0200, ixid wrote:
> >As long as the syntax is not *too* ugly (*cough*C++ templates*cough*)
> >isn't the *semantics* more important? A pretty language that has
> >limited expressiveness is useless; a powerful language that's a bit
> >ugly in syntax isn't any less powerful because of it.
[...]
> What is the cost of expressiveness in these cases?

But that's the issue, this is just a cosmetic change that doesn't really
add expressiveness to the language.


> I don't think expressiveness should be limited and often prettiness
> lends itself to expressiveness. People find D templates much easier to
> use than C++ ones and in part that's because they're much easier for
> humans to parse.

But I find C's for-loop syntax easier to parse, because what's in the
preamble is clearly distinguished from what's in the loop body. Omitting
the parens would make it visually more similar to the loop body, and
thus more liable to be confused with it.

I think comparing this to D vs. C++ template syntax is a bit unfair. C++
templates made a bad choice of using angle brackets, which are already
being used for comparison operators, thus things like func<a<b>(x)>y are
ambiguous: is it func<(a<b)>(x) > y, or is it func<(a<b>(x))> y? Not to
mention func<a<b>> is actually syntactically invalid until C++11 (how
many years did it take for them to fix that one!). D templates are so
much better, in part because they use normal parentheses, which *don't*
suffer from ambiguity with existing operators.

In the case of optional parens in for-loops, there are no such ambiguity
issues involved. It's more a matter of personal preference than anything
else, IMO.


T

-- 
To err is human; to forgive is not our policy. -- Samuel Adler


More information about the Digitalmars-d-learn mailing list