safer casts - take II

Janice Caron caron800 at googlemail.com
Thu May 15 09:19:54 PDT 2008


On 14/05/2008, terranium <spam at here.lot> wrote:
> BCS Wrote:
>
>  > I guess if you can convince me that I am in the minority here
>
> In fact, I am the only who argued for throwing cast, it seems like everyone else is against my proposal, so the result is obvious.

I don't understand. In the next Phobos release, you will have your
wish. to!(T) will work as a throwing dynamic cast. It looks to me like
you've actually got what you wanted. What's the problem?

It would be very, very impractical to make cast(T) itself throw,
because it would break a lot of a code. Obviously, my/Yigal's probosal
will itself break lots of code, but in our case, the fix of adding an
exclamation mark to the offending line will make it compile again,
almost all of the time. But if cast(T) were to suddenly change its
behavior to start throwing, there would be no compile errors for using
it - just lots of runtime exceptions generated by existing code. And
even once the cause is discovered, it's not clear how existing code
would have to be rewritten in order to carry on working.

The way I see it, the fact that you've got to!(T) coming means that
you can write your code in the way that you want it, but also so can
everyone else. What's wrong with that?



More information about the Digitalmars-d mailing list