Do non-member functions improve encapsulation in D?
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Mon Apr 21 07:35:52 PDT 2014
On Mon, 21 Apr 2014 09:46:18 -0400, Lars T. Kyllingstad
<public at kyllingen.net> wrote:
> On Monday, 21 April 2014 at 12:45:12 UTC, Steven Schveighoffer wrote:
>> 3. There is zero chance of a conflict with another type's similarly
>> named method.
>
> How? If you have the following functions:
>
> void foo(A a);
> void foo(B b);
>
> and you write
>
> foo(new B);
>
> there is also zero chance of conflict -- even if B happens to be a
> subclass of A, since the most specialised function is always called.
I definitely restricted myself too much when I said "another type." Yes,
there is a very low possibility of A and B conflicting. But as I showed in
the other post, there is the possibility of confusing the compiler when
calling a UFCS method.
Essentially, the core issue is that a type provides the strongest tie to
its method overload set. The module's overload set has looser ties, so
they can be accidentally (or intentionally) overridden. It was a common
con against UFCS before it was introduced.
-Steve
More information about the Digitalmars-d
mailing list