Are properties actually all that good?
Ali Çehreli
acehreli at yahoo.com
Mon Jul 22 08:53:01 PDT 2013
On 07/22/2013 08:07 AM, Land wrote:
> I was just thinking about properties and to be honest, I don't
> like them all that much. There's no way to tell if it's a
> read-only or write-only property (right?),
Documentation should make it clear. Otherwise, it should be possible to
detect whether a property is read-only, etc. a la templates in std.traits.
> but getValue and setValue are pretty self-explanatory.
Agreed, but as I said in that earlier thread, I find it repetitive and
unnecessary when it is obvious:
cpu.temperature;
The following is also slightly wrong, in the sense that it is not 'cpu'
that will get the temperature:
cpu.getTemperature();
Temperature is a property of 'cpu'; there shouldn't be a verb associated
with it. The whole issue is not that important anyway. However
imperfect, everybody understands what get/set methods are. (Judging from
the word "method", they must be common in languages that have "methods". ;))
> Also, someone was angry about .keys making a copy. I agree with
> that person and think that instead of a property, there should be
> a method called copyKeys or getKeysCopy to make it obvious.
Agreed. It is simply historical.
> Or does anyone have different view on the matter? I'd be happy to
> hear it.
Ali
More information about the Digitalmars-d-learn
mailing list