Is opCast need, we have to!

Jesse Phillips jessekphillips+D at gmail.com
Thu Dec 2 08:58:31 PST 2010


Jesse Phillips Wrote:

> > besides the overflow issue you have mentioned, I also don't want special cases. No implicit conversions should be applied equally everywhere. 
> 
> Then be explicit in all of _your_ code. That won't stop others from using implicit conversion, but you can just assume they are of the same type and be fine.

Now that I'm clearer on my own stance I should state my view on this. D has some unique rules for implicit conversion. You'll notice many of your complaints were _not_ valid in D. D allows for more implicit conversions then languages like C#, but not at the same cost as C (loss of data). For this reason I think experience from other languages can not dictate that implicit conversion is bad/unsafe in D.

The desire to specify specific explicit conversions is understandable, as it prevents conversions that weren't expected. Cast should be avoided, D's implicit conversion rules help _prevent_ miss use of this drastically unsafe tool as you can just make assignments and issues are compiler errors which bring to your attention the problem. This is one of the reasons I want to restrict what to! allows for conversions.

So we have:

Safe conversions: implicit
Type conversion: to!()
Unsafe/forced/qualifier conversions: cast

Even qualifier conversions have some library support to avoid using cast: std.exception.assumeUnique!() (maybe that should be in std.conv? Made sense in std.contract but not really exception).


More information about the Digitalmars-d mailing list