Taking address of properties

Steven Schveighoffer schveiguy at yahoo.com
Thu Feb 7 11:13:55 PST 2013


On Thu, 07 Feb 2013 13:05:50 -0500, Robert <jfanatiker at gmx.at> wrote:

> Properties provide a means of access control to fields. (Range checks,
> only readable, only writable, triggering a signal on change, ...)
>
> So as posted a few times, taking the address of the ref return value of
> a property is of no value at all. If you want someone to be able to take
> the address of a field, you should make it simply public (without
> @property), because the @property accessor methods won't gain you
> anything in this case.

@property ref T front(T[] arr) { return arr[0];}

Not being able to take an address of an array's front element is not a  
viable solution.  The array range's business is not to restrict access to  
the first element, it's simply to conform to a certain API.

This all comes down to an incorrect belief that properties are simply  
front ends for private variables.  They are not, even when many languages  
make such things necessary or easy to implement (objective C comes to  
mind).

There are plenty of different uses of properties, and redirecting access  
to another variable (as does the above function) is certainly a valid  
use.  I don't think we should make rules that are focused on specific use  
cases while discarding or diminishing others.

-Steve


More information about the Digitalmars-d mailing list