|
Boost : |
Subject: Re: [boost] [property] interest in C# like properties for C++?
From: David Brownstein (dbrownstein_at_[hidden])
Date: 2009-10-21 17:46:36
Hi,
I like the setter ".value" notation. Although I prefer method-style getters
and setters, if others prefer assignment notation then both can be included
in a Property class. I experimented with get() and set() methods as well,
and discovered that in a MS development environment (VC++ 7.1 or higher),
there is a macro with the name "set" that causes problems without a #undef
set statement. For this reason I stopped using get/set.
I think the notation used to reference properties is less important (to me
at least) than having properties be declarative, so that they automatically
generate access code. After all a Property is a convenience. In my work I
need to package and move a lot of data, so for me to express data members as
properties has greatly reduced the amount of boiler-plate code that I have
to write (i.e. getters and setters).
I agree that simple property definition is desirable, as often a
"symmetrical property" (public getter and setter) is desired, and in that
(probably most common?) case, it should be easy to write:
Property<int> counter;
This is easy to do allow by defaulting template parameters.
David
-----Original Message-----
From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]]
On Behalf Of Gennadiy Rozental
Sent: Wednesday, October 21, 2009 1:51 PM
To: boost_at_[hidden]
Subject: Re: [boost] [property] interest in C# like properties for C++?
> A.X() = B.X() = 5 isn't horrible, but A.X = B.X = 5 is what one expects
when
one thinks of "properties."
Sorry, if I jump in in the middle of the discussion.
Boost.Test uses properties with syntax like this:
int i = a.p_X;
a.p_X.value = 1;
This syntax IMO has couple advantages:
1. From encapsulation standpoint this is as good as having explicit setter
and
getter.
2. I do not like to allow a.p_X = 1. ".value" syntax allows me to grep
easily
for all the encounters of property modification. This is especially useful
in
situations where there are myriads of read-only access and only couple
mutating
ones.
3. Single line definition:
readwrite_property<int> p_X;
Instead of 3 lines required by data member, getter and setter.
4. I also have readonly_property, which can restrict mutating access to the
property value for all classes (in which case property initialized in a
constructor once and never changes). Or I can have readonly property with
fixed
list of classes allowed mutating access.
Gennadiy
_______________________________________________
Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk