Why I'm Excited about D
Dicebot via Digitalmars-d
digitalmars-d at puremagic.com
Sun Apr 12 22:46:30 PDT 2015
On Sunday, 12 April 2015 at 18:42:01 UTC, Andrei Alexandrescu
wrote:
> On 4/12/15 10:43 AM, Dicebot wrote:
>> It is much better in languages that do support dedicated
>> properties
>> because language rules can be used to express the same notion
>> without
>> resorting to any conventions.
>
> Wouldn't e.g. C# allow arbitrary code in getters and setters?
> And if so, wouldn't C# code need to resort to conventions to
> avoid surprising behavior? -- Andrei
This is totally reasonable way to put it but in practice there
are enough differences to keep it maintainable. With dedicated
getters decision (and reviewer attention) is focused on
definition of getter and done there once and for all. Some tough
decisions are inevitable but it is at least possible to ensure
that all such decisions are deliberate. In D such decision is
done at call site which makes it very hard to review as changes
are distributed everywhere. Though DScanner can possibly help
here and I am really looking forward trying to it in our code
control.
That said, I think the main reason why this notion didn't work
well for D when @property was introduces is because of extremely
vague range semantics. I find it important that you have
mentioned exactly `front` and `popFront` as examples for unclear
parens placement - problem with those is that there isn't.
`front` may or may not be trivial getter depending on (sometimes
arbitrary) decision by range implementor, there is no uniformity
between those. Which makes impossible to enforce consistent
calling style and makes "drop everything" approach much more
tempting.
More information about the Digitalmars-d
mailing list