use of this keyword in variable access

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

use of this keyword in variable access

Adam Heath-2
What is the policy on use of this to access the variables and methods
in ofbiz?  It's not entirely consistent across the code base.

I would prefer not to use this when it isn't needed, as it introduces
an extra keyword into the code.
Reply | Threaded
Open this post in threaded view
|

Re: use of this keyword in variable access

Adrian Crum
I like using the this keyword because it makes the scope clear. I find
it makes it easier for me to understand someone else's code.

-Adrian

Adam Heath wrote:
> What is the policy on use of this to access the variables and methods
> in ofbiz?  It's not entirely consistent across the code base.
>
> I would prefer not to use this when it isn't needed, as it introduces
> an extra keyword into the code.
>
Reply | Threaded
Open this post in threaded view
|

Re: use of this keyword in variable access

Scott Gray-2
I'm guessing it also gets used a lot because of IDE code completion.

Regards
Scott

On 30/03/2010, at 9:56 AM, Adrian Crum wrote:

> I like using the this keyword because it makes the scope clear. I find it makes it easier for me to understand someone else's code.
>
> -Adrian
>
> Adam Heath wrote:
>> What is the policy on use of this to access the variables and methods
>> in ofbiz?  It's not entirely consistent across the code base.
>> I would prefer not to use this when it isn't needed, as it introduces
>> an extra keyword into the code.


smime.p7s (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: use of this keyword in variable access

Jacques Le Roux
Administrator
In reply to this post by Adam Heath-2
From: "Adam Heath" <[hidden email]>
> What is the policy on use of this to access the variables and methods
> in ofbiz?  It's not entirely consistent across the code base.
>
> I would prefer not to use this when it isn't needed, as it introduces
> an extra keyword into the code.

+1

Jacques

Reply | Threaded
Open this post in threaded view
|

Re: use of this keyword in variable access

Adam Heath-2
In reply to this post by Adrian Crum
Adrian Crum wrote:
> I like using the this keyword because it makes the scope clear. I find
> it makes it easier for me to understand someone else's code.

That's the compilers job, don't try to do an end run around it.

Reply | Threaded
Open this post in threaded view
|

Re: use of this keyword in variable access

Adrian Crum
Adam Heath wrote:
> Adrian Crum wrote:
>> I like using the this keyword because it makes the scope clear. I find
>> it makes it easier for me to understand someone else's code.
>
> That's the compilers job, don't try to do an end run around it.

Excuse me??

int var2 = someMethod(someValue);

The scope of var2 is clear - it is a local variable. What is the scope
of someMethod? It could be an instance method or a static method. What
is the scope of someValue? It could be a local variable, an instance
field, or a class field.

Using the this keyword would make that line of code a lot clearer to
someone looking at it for the first time.