On 24.1.2013 23:04, Andrei Alexandrescu wrote:
On 1/24/13 4:56 PM, Adam Wilson wrote:
Simplicity is clearly good, but there's something to be said about
those warts in chained calls. The UFCS-enabled idioms clearly bring a
strong argument to the table, there's no ignoring it.
Andrei
Then @property needs to be fixed such that optional parens don't effect
it one way or the other. Removing the concept of properties and making
functions that look like properties through optional parens is a very
poor (and lazy) solution. As Mr. Ruppe pointed out, properties are DATA,
and functions do stuff. That statement alone is an excellent argument
for clearly delineating which is which... Properties are not functions.
I'm not all that convinced, and it's easy to get wedged into a black vs
white position that neglects many subtleties. Properties are DATA, well
except when you need to pass fields by reference etc. at which point the
syntactic glue comes unglued.
There's been a lot of strong positions years ago about functions vs.
procedures, statements vs. expressions, or even (the glorious 60s!)
in-language I/O primitives vs. I/O as library facilities. Successful
languages managed to obviate such dichotomies.
Andrei
Maybe this will clarify what is meant by "properties are data":
// http://dpaste.dzfl.pl/822aab11
auto foo () {
return { return 0; };
}
@property auto bar () {
return { return 0; };
}
void main () {
auto localFoo = foo;
assert(!is(typeof(localFoo) == typeof(foo)));
auto localBar = bar;
assert(is(typeof(localBar) == typeof(bar)));
}
function:
auto localFoo = foo; // call foo and store the result
typeof(localFoo) // typeof(data returned by foo) - function pointer
typeof(foo) // typeof(function foo) - function
data:
auto localBar = bar; // get data represented by bar
typeof(localBar) // typeof(data represented by bar) - function pointer
typeof(bar) // typeof(data represented by bar) - function pointer
Data represented by bar can be some value, or a function call that
returns a value. As a user of that property I don't care. And I don't
want my code to break if that property changes from a function pointer
to a function that returns a function pointer. Hence typeof(foo) is a
function, and typeof(bar) is a type of that property (type that is
returned by a calling bar). I would like to emphasize that @property is
not a syntactic, but rather a semantic issue.