What did you think about an implicitConversionOp ?

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Dec 26 18:12:02 UTC 2020


On Sat, Dec 26, 2020 at 04:26:14PM +0000, Paul Backus via Digitalmars-d wrote:
> On Saturday, 26 December 2020 at 15:48:49 UTC, sighoya wrote:
> > I like the idea of an `implicitConversionOp` or `implicitCoercionOp`
> > more than multiple alias this since the operator is separated from
> > the source type.
> 
> User-defined implicit conversions have been proposed many, many times,
> and Walter has always rejected them. For example, here's a reply of
> his to a post from 2004:
> 
> > Implicit casting is a great idea. It's problems don't become
> > apparent for years, when battle-weary programmers eventually
> > conclude that it just causes more problems than it is worth. I know
> > that it is difficult to be convincing in a few lines about this, but
> > when the complexity of the classes goes beyond the trivial, the
> > interactions between them and other classes with implicit casting
> > becomes remarkably impenetrable.
> 
> https://forum.dlang.org/post/cqoj59$sle$1@digitaldaemon.com

I also used to be a fan of implicit conversions.  Over time, though,
I've come to agree with Walter.  Implicit conversions are admittedly
very convenient in the short term, but in the long term they tend to
make code obtuse and hard to maintain.  Over time I've come to regret
deeply-ingrained implicit conversions I've done in my code with alias
this.


T

-- 
People tell me I'm stubborn, but I refuse to accept it!


More information about the Digitalmars-d mailing list