make (a < b < c) illegal?
Peter Modzelewski
peter.modzelewski at gmail.com
Thu Feb 8 01:21:39 PST 2007
Walter Bright napisał(a):
> Right now, in D (as well as C and C++), when you see the expression:
>
> if (a < b < c)
>
> what is your first thought? Mine is that it was written by a newbie who
> didn't realize that (a < b) returns true or false, and that it does NOT
> mean ((a < b) && (b < c)). The odds approach certainty that this is a
> logic error in the code, and even if it was intentional, it raises such
> a red flag that it shouldn't be used anyway.
>
> Andrei has proposed (and I agreed) that this should be done away with in
> the language, i.e. comparison operators should no longer be associative.
> It's a simple change to the grammar. If one really did want to write
> such code, it could be done with parentheses:
>
> if ((a < b) < c)
>
> to get the original behavior. At least, that looks intentional.
>
> I don't think this will break existing code that isn't already broken.
It's cool when language makes it easy not to make mistakes (maybe not as
java by not letting programmer to do anything serious but still handy
idea) but isn't it (on small scale but always) losing compatibility with
C, which could complicate making bindings etc? Libraries creators could
have used them in the right meaning for some strange reason...
As if making "the real meaning". "The real meaning" can be different for
each person. some would like to use a<b<c in c style, some in python,
some will have own ideas. and if i understand correctly, macros will do
it. every man could write his own macro to change it in any way he like.
So if it will not make problems with C compatibility vote ++ with no
"real meanings"
---------------------------
Peter Modzelewski
www.team0xf.com
www.keyer.team0xf.com
More information about the Digitalmars-d
mailing list