Arbitrary abbreviations in phobos considered ridiculous

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Mar 9 21:06:40 PST 2012


On 3/9/12 5:05 PM, Adam D. Ruppe wrote:
> On Friday, 9 March 2012 at 23:50:50 UTC, bearophile wrote:
>> At first I didn't like it a lot because it's cheap syntax sugar that
>> adds no new power and gives programmers more freedom to write
>> different-looking versions of the the same code (and this is often bad).
>
> 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.

Insert obligatory link: http://drdobbs.com/184401197

Very insightful article.


Andrei


More information about the Digitalmars-d mailing list