On Wednesday, November 22, 2017 12:45:01 Daniel Kozak via Digitalmars-d 
wrote:
> Ok I understand why there is no conversion from Duration to float, but
> would be possible to make Duration.total not a member function? So insted
> of:
>
> static mytotal(string unit)(Duration dur)
> {
>     return dur.total!unit;
> }
>
> alias msecs = mytotal!"msecs";
>
> I could just add
> alias msecs = total!"msecs";

How would that help anything? You can clearly create an msecs alias right
now, and you could get the same effect using a free function named msecs
instead of an alias. Also, core.time.msecs is already an alias for
core.time.dur!"msecs", so creating your own symbol called msecs (be it an
alias or a free function) could muck with your use of the one from core.time
(though it's certainly possible to disambiguate between the two or to use
dur!"msecs" directly).

And regardless of this specific situation, in general, turning a member
function into a free function risks breaking code, since instead of it being
a member function that automatically wins out with UFCS, it could suddenly
be in conflict with another function of the same name, meaning that the
calling code would have to then disambiguate between them whereas it didn't
before. So, in general, turning member functions into free functions isn't a
great idea if you're not in control over all of the code involved or
otherwise aren't concerned about the potential fallout.

- Jonathan M Davis

Reply via email to