
Stefan Strasser wrote:
Am Wednesday 21 October 2009 06:02:23 schrieb Edward Diener:
x.count(5); 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 constraints.
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.