Arbitrary abbreviations in phobos considered ridiculous

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Mar 9 17:29:05 PST 2012


On Sat, Mar 10, 2012 at 02:05:38AM +0100, Adam D. Ruppe wrote:
[...]
> What I like about is the encapsulation benefits. You
> don't have to know if the function is a method or an
> external function, it just works.
> 
> External, non-friend (so separate module in D) functions
> are often preferable to methods because they don't have
> access to the class' private members, so they cannot rely
> on those implementation details.
> 
> Extending objects with new functions in this way also
> means you don't break binary compatibility with the
> existing code, since it isn't modified at all!
> 
> 
> Of course, you could always do this with the old
> syntax too, but then the syntax preference means
> you are biased toward one implementation or the
> other - it doesn't mesh as well and you may be
> tempted to make things methods for the syntax,
> despite the cost in compatibility.
> 
> UFCS rox.

+1. Thanks for bringing this up; this is a very significant benefit.  It
makes it possible for you to adapt a class which you can't change (e.g.,
shipped as a binary-only library) to work with, say, templates that
expect certain class members that aren't there but can be implemented
using what is available.  UFCS makes this possible without lots of
bandaging, mummy-wrapping, or special-casing that adds lots of bloat to
template code.

UFCS also makes it possible to implement operator overloading to make
diverse types work nicely with each other (esp. if you're importing
multiple numerical libraries that don't know of each other's existence).


T

-- 
Democracy: The triumph of popularity over principle. -- C.Bond


More information about the Digitalmars-d mailing list