Re: 'this' instance field reference
"Harold Meder" <[email protected]>
| Newsgroups | gmane.org.user-groups.trijug.juglist |
|---|---|
| Message-ID | <[email protected]> |
I hate the extra typing ... but I have even turned on the Eclipse warning that lets me know when I forget to use this. I used to do things like prefix the instance attribute names with "_" or, my favorite, "d_". But now, I have grown up and have stopped trying to avoid doing what is right. I use this. So, now that I am using this, what should I do with static attributes? <Classname>.<attributeName>? Even when I am in the Class that contains the static? Oh, this is too much! But, if I want to claim that this is right, then I should use <Classname> for statics. Bottomline: Somehow, the scope of the attribute should be obvious anywhere the attribute is used. I use this for instance attributes and prefix my static attribute names with "s_". Harold Meder. On 8/2/06, Larry Karnowski <[email protected]> wrote: > > Kevin, > I don't understand why people are so afraid of typing five extra > letters. Just do it -- for both methods and instance variables. It > immediately removes all doubt as to the scope of the member in question, > improves readability, and doesn't hurt anything. > > In other languages, most notably Python, you are required to use it to > reference instance members at all. (In Python it is "self." which is > their equivalent of "this.") > > Larry "this.unafraid" Karnowski > > A. Kevin Baynes wrote: > > In an unformal code review, I have a colleague who wrote : > > > > -- > > 'Access to instance fields should be prefixed with "this."' > > > > and > > > > 'Note I'm talking about variables here, not methods. I agree that > > "this." is unconventional on method calls, but I think there is fairly > > universal agreement these days about use of "this." on *variables*.' > > -- > > > > I know that 'this' is needed to resolve class level varaibles obscured > > within a method by a local variable of the same name, and is needed to > > call sibling constructors. > > > > I don't see any problem in referencing class variables as 'this.foo' > > if you wish, it reads the same to me. > > > > My question is 'this' : > > > > Do any of you support this purported 'univeral agreement' theory? > > > > -- > Larry Karnowski > HickoryWind.org, Keeps Callin' Me Home > Americana Music News, Reviews, & Personality > www.hickorywind.org > > > _______________________________________________ > Juglist mailing list > [email protected] > http://trijug.org/mailman/listinfo/juglist_trijug.org > _______________________________________________ Juglist mailing list [email protected] http://trijug.org/mailman/listinfo/juglist_trijug.org