On Wednesday, 8 April 2015 at 16:47:10 UTC, Andrei Alexandrescu wrote:
On 4/8/15 2:24 AM, Idan Arye wrote:
At the very least, put () after the writelne:

No. -- Andrei

Why not? The property syntax's purpose is to create... well... properties. Give you the illusion that you are reading and writing member fields when you are actually calling functions.

`names.reverse` is OK, because you can imagine that `names` has a member field called `reverse` that holds it reversed(this is not really true because `names.reverse` is mutating the original array, but the point is that we are not calling `reverse` for it's side - we are only interested in it's return value).

`names.reverse.writeln;` - not so much. We are not treating `writeln` as a property - we don't really care what it returns - we treat it as a method, and therefore it should use the method call syntax.

In matter of fact - if `writeln` was a member field - the very same thing the combination of UFCS and property syntax is trying to emulate - this code wouldn't compile:


struct Foo {
    string writeln;
}
struct Bar {
    Foo reverse;
}

void main() {
    Bar names;
    names.reverse.writeln;
}

source/app.d(10): Error: dotvar has no effect in expression (names.reverse.writeln)

Reply via email to