Subject: Re: [boost] [property] interest in C# like properties for C++?
From: Stefan Strasser (strasser_at_[hidden])
Date: 2009-10-21 10:10:55
Am Wednesday 21 October 2009 10:27:08 schrieb Edward Diener:
> 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.
I don't think that's wise at all. standard practices exist for a reason.
that's like using UpperCaseNaming in the public interface of your classes,
rather than lower_case_naming, because other languages do and you think it
you might be right about that, but it requires everyone who uses your classes
to know your syntax preferences, instead of just the standard.
I've used properties in C# and there is no reason not to use them. in C++, I
wouldn't use a C#-like properties syntax for this reason alone, even if all
previously mentioned problems could be solved - there is an established C++
size2=my_container.size; //no "()"?! class author was using C# properties.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk