Fallback 'catch-all' template functions

Dominikus Dittes Scherkl via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 1 04:01:28 PDT 2016


On Thursday, 1 September 2016 at 10:53:01 UTC, Ethan Watson wrote:
> On Thursday, 1 September 2016 at 10:43:50 UTC, Dominikus Dittes 
> Scherkl wrote:
>> I have never seen what benefit could be gained from having 
>> overloads.
>
> Oh, it's perfectly fine if you're not writing a library that's 
> designed to allow user extension by going the "all in one" 
> method. If you encourage your users to modify your function 
> itself, they can no longer drop in a new version and have to do 
> a merge.
Ok, that may be fine, until you reach the point with the fallback 
version: if after that point someone "drops in" a new version, he 
silently changes the behavior of the function, because he 
"steals" some type which used to use the fallback version.
--> overloads make only sense, if a function is NOT for all 
types, so you can add an overload for some type that was not 
considered so far, but you should not change the behaviour for 
some type that was already covered.
At all, most of the time I prefer that the users directly change 
the function, yes.


More information about the Digitalmars-d mailing list