|
Boost : |
Subject: Re: [boost] [property] interest in C# like properties for C++?
From: Matt Chambers (matthew.chambers_at_[hidden])
Date: 2009-10-21 09:20:23
Stefan Strasser wrote:
> 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
> looks nicer.
> 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++
> properties syntax.
>
I don't agree that what you call C++ properties are standard or widely
used. I think the get/set prefix is probably just as widely used (just
not in boost or std). Even in cases where one does find both get/set
properties in the style you say is standard, X() and X(value), the
X(value) function almost never returns X& (with both const and non-const
overloads). This means that it can't be used in a chain of assignment
operations like A.X(B.X(5)) which incidentally looks awful compared to
A.X = B.X = 5. For properties, operator= is greater than operator() ;)
-Matt
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk