And... we have another QAW (Quality Assurance War) on our hand.
After reading the more generic "What kind of prefix do you use for member variables?" question, I tried to argue with my QA department about the advantages to always add 'this' before instance (or member) variables in java code. They are not convinced.
I know there is a similar question question, but specific to cocoa.
My arguments for adding 'this' before member variables in java are:
- there is no sure way to ensure one naming convention for instance variables, whereas 'this' is universal to the language
- it is easy to do (with IDE like eclipse, and the use of the 'quick fix' mechanism, that IDE can add 'this' automatically throughout the code of a given java source code)
- it clearly differentiates instance variables and member variables, again without depending on a specific naming convention.
When it comes to java, what is your take on that practice ?
Your answers are very informative and help me to understand why the QA (for code quality) was not convinced.
You are basically saying that it is:
- a matter of taste
- a risk of code cluttering (too much 'this' everywhere)
- a way to resolve some punctual naming conflict, or avoid mutability issue.
I would however argue that:
- eclipse already alert us whenever a naming override occurs (between a parameter and an instance variable), so this is not actually an issue for us.
- final keyword is already enforced (findbugs does report every 'final' needed)
- adding 'this' is an alternative to whatever naming convention you may favor (easily applied automatically).
The net added value of 'this. prefix' would be a clear identification, in a long method, of the usage of instance variables, whatever the quality/complexity of the code is.
... But that seem less important than a 'clear' code, based on the faith that the programmer will actually produced such a "clear-not-too-complex-good-quality" code.
Why not. I do respect all those points of view, and thank you again for giving them here.
If you have other argument for or against using 'this.' before instance variables, feel free to add them ;)