H
Harry Colquhoun
For my current job I've encountered a java coding 'technique' in the
existing code that has me scratching my head. Most places in the code
where a method variable is referenced, the previous programmers prefix
the variable with the "this" keyword (i.e. this.myVariable = 10).
Even worse (imho), they've defined their setter methods as follows:
setVariableName(String variableName) {
this.variableName = variableName;
}
Is this a common coding technique that I just haven't seen before? To
me, proper coding style would dictate that you never define a parent
and child class to each have their own variable with the same name,
and therefore use of the 'this' keyword is both dangerous and
unnecessary.
I'm wondering what others think...
Cheers,
Harry
existing code that has me scratching my head. Most places in the code
where a method variable is referenced, the previous programmers prefix
the variable with the "this" keyword (i.e. this.myVariable = 10).
Even worse (imho), they've defined their setter methods as follows:
setVariableName(String variableName) {
this.variableName = variableName;
}
Is this a common coding technique that I just haven't seen before? To
me, proper coding style would dictate that you never define a parent
and child class to each have their own variable with the same name,
and therefore use of the 'this' keyword is both dangerous and
unnecessary.
I'm wondering what others think...
Cheers,
Harry