Why explicit cast?

janderson askme at me.com
Sun Feb 11 22:45:07 PST 2007


janderson wrote:
> Andreas Kochenburger wrote:
>> I find it extremely annoying to have to write 'cast' before every 
>> C-like  cast. The C-syntax is as clear as tap water, so why had this 
>> complication been added?
> 
> I've used languages that simplicity convert casts.   They are a pain 
> because its so easy to accidentally convert something into something 
> else you didn't want.  

I think I missed the point here.  cast is more explicit then C style. 
Its easier to phase.  D is meant to be a very phasable language (which 
also improves compile times).  The longer syntax also makes them easier 
to spot/grep and act as a warning. Thankfully they are not as bad as 
C++'s or Ada's casts (which where made long on purpose).

> Admittedly there are some cases I think casting 
> could be ignored (or perhaps cast(auto)(...) or auto(...) ) however most 
> of the time they are necessary.
> 
> If you see code with lots of casts in it, its a sign something is wrong.
> 
> -Joel



More information about the Digitalmars-d-announce mailing list