Reddit: why aren't people using D?

Michiel Helvensteijn m.helvensteijn.remove at gmail.com
Thu Jul 23 14:56:53 PDT 2009


Eldar Insafutdinov wrote:

> from your post:
> 
> property int length {
>     get() { return this.len; }
>     set(newLen) { this.len = newLen; }
>     void opIncrement() { this.len++; }
> }
> 
> I don't think that's flexible to overload every operator to get the best
> performance. As Walter likes to say the best way should be the most
> obvious. Besides we forgot that D2 allows to return references, which
> eliminates the issue.

If your property really just hides a private member variable, it was
probably for encapsulation purposes or because you want redundant actions
to be taken for every access. If you return a reference, you give unlimited
and unrestricted access to that variable with only one call, and you might
as well not have used a property at all.

If your property is derived -- that is, if it doesn't directly mirror a
variable --, there is no reference to return.

Besides, in D, you can probably use mixins to copy the entire interface of a
type into the property without code duplication.

-- 
Michiel Helvensteijn




More information about the Digitalmars-d mailing list