Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > stylistic use ofexplicit this.

Reply
Thread Tools

stylistic use ofexplicit this.

 
 
Adam Maass
Guest
Posts: n/a
 
      04-22-2004

"P.Hill" <> wrote in message
news:c664ta$bgr$...
> This is a syntax style question, but hopefully not the usually silly
> personal choice issues. I find myself use lots of explicit "this."
> while most Java code has few to none explicit "this." uses.
>


In general: I use an explicit "this." when it will help disambiguate my
code.

Writing .equals methods is one place where the explicit "this" helps a lot.


-- Adam Maass


 
Reply With Quote
 
 
 
 
Timo Kinnunen
Guest
Posts: n/a
 
      04-22-2004
On Wed, 21 Apr 2004 23:52:04 GMT, Mohun Biswas wrote:

> Roedy Green wrote:
>> I'm with you. If in doubt put in the explicit this, especially when
>> you are dealing with two different objects at once this one and some
>> other.

>
> Let's take it a little farther to a related style issue I've never seen
> treated: let's say your class has private members foo and bar, and
> therefore accessors getFoo() and getBar(). Now in some third method I
> need the value of foo. My options include:
>
> this.getFoo()
> getFoo()
> foo


I use the last option normally. If I can't use an IDE with debugging
support and I need to see the changes, I'll convert my code to use
accessors. For this I introduce new private accessors.

private int foo;

becomes

private void foo(int value) { this.foo0 = value; }
private int foo() { return foo0; }

private int foo0;

For me, this affects readability the least. The change in the name of the
variable ensures that I won't miss any callsites.
 
Reply With Quote
 
 
 
 
P.Hill
Guest
Posts: n/a
 
      04-22-2004
Adam Maass wrote:

> In general: I use an explicit "this." when it will help disambiguate my
> code.
>
> Writing .equals methods is one place where the explicit "this" helps a lot.


Oh definitely! I had forgotten about this one.

if ( this.equals(that) ) {
...
}
is definitely the right construct.

if ( equals(that) ) {
....
}

is just stupid.

-Paul

 
Reply With Quote
 
Adam Maass
Guest
Posts: n/a
 
      04-23-2004

"P.Hill" <> wrote in message
news:c68pfk$6ic$...
> Adam Maass wrote:
>
> > In general: I use an explicit "this." when it will help disambiguate my
> > code.
> >
> > Writing .equals methods is one place where the explicit "this" helps a

lot.
>
> Oh definitely! I had forgotten about this one.
>
> if ( this.equals(that) ) {
> ...
> }
> is definitely the right construct.
>
> if ( equals(that) ) {
> ...
> }
>
> is just stupid.
>
> -Paul
>


I was thinking more like

class Foo {
int a, b, c;
public boolean equals(Object o){
Foo that = (Foo)o;

return this.a == that.a && this.b == that.b && this.c == that.c;
}
}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fujitsu Siemens Stylistic ST5022D Tablet PC. Gerhard Nerge Computer Support 1 09-25-2006 03:06 AM
A stylistic question. Mark Healey C Programming 60 05-28-2006 09:59 PM
Stylistic question about inheritance Andrew Koenig Python 17 04-01-2005 12:49 PM
Stylistic question -- initialization lists and vectors Denis Remezov C++ 4 04-30-2004 05:10 PM
stylistic prototype question Mantorok Redgormor C Programming 5 10-30-2003 01:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57