Comma operator = broken design
Adam Ruppe
destructionator at gmail.com
Wed Dec 7 09:47:39 PST 2011
Alex Rønne Petersen Wrote:
> I really do not see the value in allowing such syntax in the first
> place. I've been told that one argument was that generated code might
> use it, but I have no idea why it would be needed.
Aside from the compiler's implementation, one possible use
is something I ended up doing in Javascript recently.
I have a thing that takes an attribute and pastes it into a code
string to check it.
given validate="this.value.length > 3"
it writes:
if(!(this.value.length > 3))
return false; // failed validation
since the given string is inside an if statement, you can't put
a semicolon in there.
So, if you have a check more complex than returning a boolean
and want to stuff it all in that string (so functions are out), the
comma lets you do it:
validate="do something, true"
This is pretty ugly style that I think I've only ever done in D inside
a for loop... but the point is sometimes something comes up, and
it's nice to have another option available, even if it is ugly.
More information about the Digitalmars-d
mailing list