Subject: Re: [boost] [property] interest in C# like properties for C++?
From: Edward Diener (eldiener_at_[hidden])
Date: 2009-10-21 04:27:08
Stefan Strasser wrote:
> Am Wednesday 21 October 2009 06:02:23 schrieb Edward Diener:
>>> int I = x.count();
>> I do not believe this is the right syntax for accessing properties. The
>> idea of a "property" is that one uses syntax to access it as if it were
>> a data object, while it still has the backing of a function to provide
> why? there is no widely used practice to use public data objects.
> so why would you need a property to emulate that syntax?
> while you might not consider accessor functions a property in the language
> construct sense, they do represent a property of the object they're a part
> of. this is widely used in the C++ standard library and boost.
> what's the rationale for another properties syntax?
Properties are just syntactic sugar for accessors to retrieve or set a
"data" value which is part of an object. In other languages in which
properties exist, such as C#, C++/CLI, C++ Builder, and Python, the
syntax uses the form of "x = value" to set the "data" value x and
"variable = x" to retrieve the "data" value x. There is nothing which
intrinsically makes this form of syntactic sugar better or worse than "x
= value()" and "variable = x()", as you suggest, other than common usage
in other languages and the concept that a property represents at least
theoretically some piece of "data" of that object, even though that
"data" may not actually exist.
I think it would be wise to keep the same syntactical form for property
in C++ which commonly exists in other languages.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk