UFCS for D

Steven Schveighoffer schveiguy at yahoo.com
Fri Mar 30 03:52:36 PDT 2012


On Fri, 30 Mar 2012 02:42:03 -0400, Walter Bright  
<newshound2 at digitalmars.com> wrote:

> On 3/29/2012 6:57 PM, Nick Sabalausky wrote:
>> How the heck does that improve encapsualtion? With D's implicit  
>> friends, it
>> *doesn't*, it's just shifting things around. There is NO encapsualtion
>> benefit there. Like Steven said, to *get* the encapsualtion, you have to
>> create a whole new module to stick "extraFunctionality" into.
>
> It doesn't improve intra-module encapsulation, you're right. The point  
> of UFCS, however, is so that *other* modules can extend a class's  
> methods without breaking encapsulation.

This is misleading, the class being extended or the code that uses the  
extensions must import the extension methods or it doesn't work.

The OP to this sub-thread brought up your example in the article -- adding  
range functions to a class.  Yes, you can do it, but it won't work with  
std.algorithm.  There's no need to test this, because it fundamentally  
cannot work that way (see my counter-case).

-Steve


More information about the Digitalmars-d-announce mailing list