19-July-2010
Use of the this keyword, is very much a style thing. However there is a great deal of logic behind the recommendation to use it.
Most developers have some kind of consistent style they follow, and consistency is a good thing. In my opinion following historic 'traditions' need to be occasionally challenged to ensure the science and logic behind the original recommendation is still valid. I'm sure everyone would agree that technology and methodology in the software industry is extremely fast moving. So keeping all things current make sense.
The overall goal in any style convention is to consistently add value to code by narrowing the number of ways a piece of code can be interpreted. However the code should always be as readable as possible. The more readable it is, the less chance for bugs.
Here's an example of how the 'this' keyword can make code more readable, indicate scope, and indicate member or static access:
Logically 'this' definitely adds value and is much clear than using Hungarian style prefixes. This also indicates scope as well as static versus member access. I know the code will compile without it, but increasing readability of the code and reducing ambiguity DOES reduce bugs. Using a built in language construct does make more sense than inventing a prefixing or suffixing scheme.
See also Microsoft Design Guidelines. |