Boost logo

Boost :

From: Luigi Ballabio (ballabio_at_[hidden])
Date: 2002-02-13 15:46:28


At 2:55 PM -0300 2/13/02, Fernando Cacciola wrote:
>IMHO, the ONLY advantage of a 'property' in comparison with the good old:
> int const& foo() const { return m_foo ; }
> int & foo() { return m_foo ; }
> int m_foo ;
>is that the user don't have to write the extra '()'.
>I don't think that a property facility could add that much complexity just
>to allow syntactic sugar.
>Of course, I can be missing something and I'll be glad to know it.

Well, the argument for this in Smalltalk or Ruby is that you access a
piece of information in the same way whether it is through direct
access to a variable or through a method. This gives you the
possibility to switch from one to another. From this point of view,
it's actually a way to enhance encapsulation.

A scenario in which it could be useful is: let's say I released a
library to a user of mine in which a type is POD because it's simple
enough and I didn't foresee that a full-featured class would be
necessary. Before next release, alas, a full-featured class _is_
necessary. My user starts to run in circles and curse my ancestors
because he has to go through his code and change all occurrences of into In this case properties can keep his
valid and my ancestors happy.

Of course all this can be prevented if one uses accessor methods from
the beginning. But it might be good to have the option.



Boost list run by bdawes at, gregod at, cpdaniel at, john at