Safer casts

Yigal Chripun yigal100 at gmail.com
Sun May 11 03:17:51 PDT 2008


Koroskin Denis wrote:
> On Sun, 11 May 2008 13:18:33 +0400, Janice Caron
> <caron800 at googlemail.com> wrote:
> 
>> sort!("a.member > b.member")(array)
> 
> I like this one, too. It's very simple, efficent and clean.

In what way is that clean? How is that different from a C macro?
if you have a typo: "a.member > b.membr" the compiler won't check it at
the place you wrote it, since it's just a string. the compiler will
probably complain about the library code instead. (I haven't tried that
on actual code, though).
Now there is a way to tell the compiler to validate the content of
strings with q"here goes a valid D code snippet" (if i remember
correctly), but that requires me to not forget that q.
all in all, all those string manipulations, although powerful, are quite
dangerous, IMO.
also, what if a doesn't actually have a "member" member? this is still
syntactically valid D code, but again I think the error would be
reported elsewhere.

--Yigal



More information about the Digitalmars-d mailing list