byKey and byValue: properties or methods?
Marco Leise
Marco.Leise at gmx.de
Fri Jan 20 00:58:42 PST 2012
Am 19.01.2012, 21:53 Uhr, schrieb Jonathan M Davis <jmdavisProg at gmx.com>:
> On Thursday, January 19, 2012 20:56:39 Marco Leise wrote:
>> I just came across some C++ code and came to the conclusion, that
>> properties and indexed access should not modify the structure. In other
>> words all my @property and opIndex will probably also by const. An
>> exception to that being caching and access counting.
>
> I don't know why you came to that concluson. I don't agree at all.
> Obviously,
> you're free to do what you want with your code, but that seems overly
> restrictive to little or no benefit. Properties can be both getters and
> setters
> for a reason. It would be horrible if all you had were getters.
>
> - Jonathan M Davis
Ah, I meant to say that getters should not modify their object. When I see
"a = abc.x[i]" I would be a little surprised to find that it changes the
observable state of abc. The same goes for "a = b.length()". Now it is
clearer, isn't is? :p
More information about the Digitalmars-d
mailing list