Required Reading: "How Non-Member Functions Improve Encapsulation"

Steven Schveighoffer schveiguy at yahoo.com
Tue Oct 31 01:47:39 UTC 2017


On 10/30/17 9:44 PM, codephantom wrote:
> On Monday, 30 October 2017 at 23:03:12 UTC, H. S. Teoh wrote:
>>
>> But in D, UFCS allows obj.func() to work for both member functions and 
>> free functions, so if the client code uses the obj.func() syntax, it 
>> won't have to care about the difference.
>>
> 
> I don't like it.
> 
> When I see obj.func(), to me, func() is a member function. Why should I 
> spend any time trying to work out whether it's a member function or a 
> free function? It doesn't make sense to me.
> 
> If it's really a free function, I'd like that to be more explicit..
> 
> e..g
> 
> obj.\func().   (or something like that ..where \ means its a free function)

I once thought as you do (though not as the syntax you propose). I now 
embrace UFCS fully, it's awesome.

-Steve


More information about the Digitalmars-d mailing list