Replies: 3 comments
-
Or you could choose to not write static methods with the same signature as instance members. Then you aren't required to qualify the method at all. This is generally a good practice anyway.
And everywhere else, too. That's what refactoring tools are for. Tooling satisfies the DRY requirement. |
Beta Was this translation helpful? Give feedback.
-
@HaloFour Potential conflict is not only with instance members (which I think would result in a compilation error), but with using static methods and local variables also. And when there's shadowing involved, then you must qualify the method call. |
Beta Was this translation helpful? Give feedback.
-
I like the syntax, but I personally would only be using it if a static member conflicts with an instance member, but in that case I would probably just give those those members unique names instead, for clarity. |
Beta Was this translation helpful? Give feedback.
-
Currently, the only way to unambiguously call a static member on the current type is to use the type's name as qualifier, which goes against DRY, e.g. changing the type's name would require to update every reference in the same type. It also requires that you know the type's name, which might not be the case in certain code-generation scenarios.
With instance members you can do
this.Foo()
and take the rest of the day off. Perhapsstatic.Foo()
would be a good syntax for static members.Beta Was this translation helpful? Give feedback.
All reactions