On Saturday, 28 June 2014 at 05:13:16 UTC, H. S. Teoh via Digitalmars-d wrote:

Actually, this particular use case is very bad. It's just inviting typos, for example, if you mistyped "int a" as "int s", then you get:

        struct Foo {
                int a;
                this(int s) {
                        this.a = a; // oops, now it means this.a = this.a
                }
        }


While I'd much prefer a syntax to handle this automatically, like:

struct Foo {
    int a;
    this(this.a) { }
}

I prefer having the variable names match what they're assigning since it makes it clearer. Some other benefits include being able to get documentation for free. When I was making my own IDE plugin a year ago, one of the features I liked was that if a parameter in the constructor had the same name as a field/property in the class, documentation would be shown for said field/property as well as for the parameter.

It's just a matter of personal preference. In theory your compiler should tell you if you're making a useless assignment like the one in the example.

Reply via email to