Parenthesis
Steve Horne
stephenwantshornenospam100 at aol.com
Fri Dec 22 23:16:48 PST 2006
On Fri, 22 Dec 2006 21:02:22 +0000 (UTC), Wolven <rma at wolven.net>
wrote:
>"Elegance" is in the eyes of the beholder... I agree with the original poster.
I agree. Pascal-family language advocates have often ridiculed
C-family language advacates for the inelegancy of needing those
parens.
Personally, I don't much care whether block statements have mandatory
parens or not, and that shorthand-everything logic has caused
significant problems in C (though the only approach I personally
prefer to brace-based blocks are the indentation-based blocks in
Python).
But I do agree that single-statement conditionals are far from rare,
and often don't get the braces treatment, and this is also a good
thing. Redundant braces look at least as stupid as redundant parens.
You basically can't always have everything. The C and Pascal styles
for block structures have different advantages and disadvantages.
Trying to get the best of both worlds risks bringing in a whole bunch
of new problems...
if a == b // fine
{
...
}
if a == b return c; // errm - well...
if a == b *c++; // aaarrrggghhh!!!
So, since the best-of-both-worlds doesn't work, making the brackets
optional implies making the braces non-optional. For every happy
person there's an angry person. What's the point?
Of course, we could add a Python-style colon. Pascal and Basic
advocates would generally advocate keywords in place of colons, but
they'd advocate different keywords for different block structures (if
... then, while ... do, etc etc) so a single consistent symbol sounds
good to me for reasons that have nothing to do with shorthand.
There's always an alternative syntax, in other words. But this isn't D
any more. It's a whole new language. With its own advantages and
disadvantages. I seem to recall a recurring suggestion on
comp.lang.python that the colons for block structures should be made
optional, for instance. And the indentation-haters are always
suggesting that brace-based blocks should be added.
Language designers have been messing about with block structure syntax
for decades. Innovation can still be worthwhile, but if there was a
single perfect approach that would keep everyone happy, I think
someone would have found it by now.
--
Remove 'wants' and 'nospam' from e-mail.
More information about the Digitalmars-d
mailing list