Are properties actually all that good?

develop32 develop32 at gmail.com
Mon Jul 22 10:00:29 PDT 2013


On Monday, 22 July 2013 at 16:42:57 UTC, Land wrote:
> Thank you for the replies. So, what's the bottom line? Should I 
> use accessor methods or should I use properties? (I've read 
> quite a bit of the mentioned 500-post topic, by the way, but 
> I'm still not clear on what's the most logical step here)

In my case I use both. If function is bigger than certain 
threshold (say, 5 lines) or allocates/returns new object each 
time, i use getSomething(), otherwise its a property.

It can also depend on the logic. For example, in graphics 
programming, there are render targets and if I want to get a 
texture representing it I may do it in two ways:

.getTexture() and .texture

At least to me, .texture means that it would be the same object 
each time, possibly a reference to a private variable.
Whereas getTexture() implies to me that the function creates a 
new texture, copies pixel data and returns it.



More information about the Digitalmars-d-learn mailing list