@property
Jonathan M Davis
jmdavisProg at gmail.com
Thu Jun 24 15:50:23 PDT 2010
Jonathan M Davis wrote:
> writeln() isn't a property because it makes no sense to replace it with a
> getter or setter. The same goes for save() or popFront() on a range.
> However, things like length() and empty() are properties because they
> could be replaced with functions like getLength() and isEmpty().
Okay. After some thought, I recant what I said about save (but not the
rest). It's _is_ a property (or at least a pseudo-property), but it's poorly
named (as Steven has been saying). Personally, I would say that for a
function to make sense as a property, you should be able to rewrite its name
as a getter or setter and have it make sense - e.g. length as getLength().
save doesn't work as getSave(), so it's poorly named. Something like copy -
therefore getCopy() as a getter - would make more sense. dup would be even
better, but I'm not sure that that would work given how dup is already used
with arrays.
In any case, I'd say it's a pseudo-property rather than a property because
it really isn't a property of the range. It's returning a copy of the range
rather than any property of that range. It would make no sense whatsoever
for save to be a member variable of the range. But it _does_ make sense to
have a getter which returns a copy, so save is definitely one of those weird
cases where something is a property, but it isn't. In this case, Andrei
appears to have chosen for it to be a property.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list