Implicit conversions through purity
Jonathan M Davis
jmdavisProg at gmx.com
Mon Apr 14 03:27:08 PDT 2014
On Sunday, April 13, 2014 21:21:02 Daniel Murphy wrote:
> "Jonathan M Davis" wrote in message
> news:mailman.112.1397351369.5999.digitalmars-d-learn at puremagic.com...
>
> > Honestly, I would have considered that to be a bug. Converting the return
> > type
> > to a different level of mutability based on purity is one thing.
> > Automatically
> > casting the return value just because the function is pure is another
> > matter
> > entirely. Clearly, it can work, but it seems incredibly sloppy to me.
>
> It's not a bug, and it's not another matter entirely - it's the same thing
> as converting a call expression, just on the inside instead of the outside.
Doing the conversion on the caller's side enables code that wouldn't otherwise
work - particularly if you're not intimately familiar with what guarantees
pure really gives you. Doing the conversion inside the function doesn't really
buy you much of anything IMHO and promotes being lazy with types. It may not
be a big deal, but I don't think that it's really a good idea either.
So, while from the perspective of what the compiler can guarantee, it may be
the same from both sides, I don't think that it's the same at all with regards
to how it affects the programmer or what code they need to write (or should
write).
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list