Why to have properties to sort or duplicate arrays ?

Daniel Giddings dgiddings at bigworldtech.com
Thu Feb 1 14:21:46 PST 2007


It's a bit of a tradeoff. Clearing an object like that isn't the 
intended use, but a possible one. It's just bad design, or bad coding. 
Additionally if you want to prevent that happening, set the clear return 
type to void. If you want have a bad API design or code, C++ allows you 
to do so much more ;-)

 From a usability point of view for libraries it allows the API designer 
to hook into property changes to validate assignments, proxy values to 
other objects and the like. All without having to have ugly setXXX, 
getXXX methods for each property. It comes down to how you use the 
language feature; if I was designing a library I would use the property 
syntax to validate the data, store it differently internally, etc, but I 
wouldn't have them do something other than "set or get the property" in 
a general sense. It's similar to overloading the arithmetic operators, 
it's really bad to do if they are overloaded to completely different 
semantics than expected.



Pierre Renié wrote:
> It's a big problem. If a method clear() acts like a property, does it mean that "value = object.clear" will clear my object?



More information about the Digitalmars-d mailing list