I've been using the "this." prefix for about two years (StyleCop SA1102 rule). But now I'm changing my mind and using the "underscore" prefix for static and instance private fields and remove the "this." prefix.
Here my reasons to switch from "this." to "underscore":
What is your idea?
Is it reasonable to ignore the StyleCop SA1102 rule ("this." prefix) and use the "underscore" prefix to distinguish class fields?
All of you points will apply to underscore as well (it needs to be enforced, not that useful, etc.), and if you changed 77 'this' to 9 _ - you could've gone with 9 'this' as well, I'm sure.
Knowing if this is an instance or static field/property is pretty useful, imo, esp. in multithreaded environment.
However, when I see 'this' - I know exactly what it means; with underscore.. I can guess, but at this point it really depends on how consistent you are.
Personally, I often (not always) use 'this' just to distinguish local variables from class properties, esp. if method is long.
At the end of the day this is just a recommendation, if you and your team feel comfortable with underscore - use that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With