Required Reading: "How Non-Member Functions Improve Encapsulation"
Patrick Schluter
Patrick.Schluter at bbox.fr
Tue Oct 31 06:23:47 UTC 2017
On Tuesday, 31 October 2017 at 01:47:39 UTC, Steven Schveighoffer
wrote:
> 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.
>
And under the hood the difference is also minimal. A member
function is compiled to a free function in the object file. It's
only the mangled name that makes the difference.
More information about the Digitalmars-d
mailing list