kjkilpi at gmail.com
Fri Dec 22 12:37:11 PST 2006
On Fri, 22 Dec 2006 19:08:31 +0200, Gregor Richards <Richards at codu.org>
> NN wrote:
>> What about removing unuseful parenthesis in 'if', 'for', 'while' ?
>> E.g. instead of:
>> if(a == b)
>> We can write:
>> if a == b
>> while c
> Does anybody have a spoon I can stab into my eyes? Thanks.
>> If someone writes parenthesis the code will compile too.
>> So this is almost backwards compatible feature.
> And with only the price of making elegant code become inelegant, ugly
> code! Fantastic!
>> What about 'if' with one expression ?
>> Almost everyone writes curly brackets for more than one expression, so
>> there they will be always written, and there will be no bugs.
> ... what? Most people write curly brackets if they have more than one
> /statement/ (that's the word you're looking for), but with only one
> simple statement I'd say it's more like a 50-50 split.
> - Gregor Richards
Well, well, it seems that Gregor is a pure C/C++/D syntax kind of a guy...
Ugliness is in the eye of the beholder, as we all know. It's a matter of
opinion. If one uses the "if a == b" syntax a long time, (s)he will very
likely get used to it, and no longer think it's ugly.
I have programmed with C++ mainly, but "if a == b" is not so ugly,
actually it's kind of okay for me (not so elegant, sure, but okay). Even
if I always write return statements insided parenthesis. Ah yes, the
return statements... you can write "return a" or "return(a)". So it's not
so strange if that would apply to other statements also.
But I think that NN suggested the syntax not because it's prettier but
because it's easier/faster to type.
I did some testing. I use a scandinavian keyboard: 'Shift + 8' -> '(' and
'Shift + 9' -> ')'. I wrote "if a == 1" ten times, and then "if(a == 1)"
(without the quotation marks):
"if a == 1" : 21 secs.
"if(a == 1)" : 29 secs.
(The starting and stopping of my timer took some time.) So, "if a == 1" is
28% faster than "if(a == 1)"...
More information about the Digitalmars-d