rtti cast
BCS
BCS at pathlink.com
Wed May 7 07:26:45 PDT 2008
terranium wrote:
> Jarrett Billingsley Wrote:
>
>
>>I perform downcasts extremely rarely.
>
> That's *exactly* why you need safe cast.
>
How does that follow? I don't see the connection.
>
>>if(auto y = cast(Y)x)
>> ...
>>else
>> // not a Y, try something else
>
> yeah, try something else, hide the bug :)
>
That's not a bug. That is the normal idiom for checking to see if x is a
Y and acting on it.
>
>>Furthermore, it's a lot easier and more efficient to have the cast return
>>null and throw an exception _only if needed_ than to throw an exception and
>>then have to catch it:
>
>
> most programmers won't bother to thow an exception in this case, they just cast and go.
>
And this will result in a Seg-V. The program will stop in a predictable
manner. IMHO (and it seems others opinions) that is what matters.
>
>>For that matter, some languages (like C#) have both kinds of casts - one
>>that throws an exception and one that doesn't. Either can really be
>>implemented in the other, but the null-returning kind is more basic and
>>efficient.
>
> ...efficient bugmaker.
the same can be said going the other way. IMHO any code that take a
More information about the Digitalmars-d
mailing list