Skip to main content
added 1409 characters in body
Source Link
Martin Maat
  • 18.5k
  • 3
  • 31
  • 58

I do this all the time, it is giving me great piece of mind. If it is an argument passed to a constructor that needs to be assigned to a member, my member would be named range as well and the assignment would be

this.range = range;

And I would typically have a property named Range.

They are all the same valuething, only differing in context so it makes sense to maintain a single name and you will have to remember only one thingname. It is one thing, the differences are purely technical.

You should be strict with fully qualifying members with "this." though, but that is what StyleCop is for.

StyleCop side note

Controversy guaranteed!

To those advocating against the use of "this.": I have seen _, m, m_ and just nothing. The language itself is offering us a perfectly clear, unambiguous universally recognizable way of indicating we are dealing with a class member. Why on earth would you want to make up your own way that mutilates already perfect names?

The only reason I can think of it that it is a legacy habit from the C era, when it actually made sense to do it because there was no other way.

"It is more characters!" Seriously? "Compile time will skyrocket!" Seriously? "I will have to lift my pinky when typing it!". As if typing time had any significance in the total development time.

I recognize that any style different from what you are used to will raise some opposition. But using this consistently is hard to argue with. Here's how it works for me: Before I push a new code file I run StyleCop and it will find a number of members lacking "this" qualifiers. I put "this." on the clipboard, run by the members and insert. No effort at all.

StyleCop does a lot more than this (haha). There are so many ways a developer can (only considering code formatting) frustrate the maintenance work of his successor. StyleCop prevents most of them. It is invaluable.

If you are new to it: it typically makes you grumble for a week or two and then you will love it.

I do this all the time, it is giving me great piece of mind. If it is an argument passed to a constructor that needs to be assigned to a member, my member would be named range as well and the assignment would be

this.range = range;

And I would typically have a property named Range.

They are all the same value, only differing in context so it makes sense to maintain a single name and you will have to remember only one thing. It is one thing, the differences are purely technical.

You should be strict with fully qualifying members with "this." though, but that is what StyleCop is for.

I do this all the time, it is giving me great piece of mind. If it is an argument passed to a constructor that needs to be assigned to a member, my member would be named range as well and the assignment would be

this.range = range;

And I would typically have a property named Range.

They are all the same thing, only differing in context so it makes sense to maintain a single name and you will have to remember only one name. It is one thing, the differences are purely technical.

You should be strict with fully qualifying members with "this." though, but that is what StyleCop is for.

StyleCop side note

Controversy guaranteed!

To those advocating against the use of "this.": I have seen _, m, m_ and just nothing. The language itself is offering us a perfectly clear, unambiguous universally recognizable way of indicating we are dealing with a class member. Why on earth would you want to make up your own way that mutilates already perfect names?

The only reason I can think of it that it is a legacy habit from the C era, when it actually made sense to do it because there was no other way.

"It is more characters!" Seriously? "Compile time will skyrocket!" Seriously? "I will have to lift my pinky when typing it!". As if typing time had any significance in the total development time.

I recognize that any style different from what you are used to will raise some opposition. But using this consistently is hard to argue with. Here's how it works for me: Before I push a new code file I run StyleCop and it will find a number of members lacking "this" qualifiers. I put "this." on the clipboard, run by the members and insert. No effort at all.

StyleCop does a lot more than this (haha). There are so many ways a developer can (only considering code formatting) frustrate the maintenance work of his successor. StyleCop prevents most of them. It is invaluable.

If you are new to it: it typically makes you grumble for a week or two and then you will love it.

Source Link
Martin Maat
  • 18.5k
  • 3
  • 31
  • 58

I do this all the time, it is giving me great piece of mind. If it is an argument passed to a constructor that needs to be assigned to a member, my member would be named range as well and the assignment would be

this.range = range;

And I would typically have a property named Range.

They are all the same value, only differing in context so it makes sense to maintain a single name and you will have to remember only one thing. It is one thing, the differences are purely technical.

You should be strict with fully qualifying members with "this." though, but that is what StyleCop is for.