Re: 'this' instance field reference
"A. Kevin Baynes" <[email protected]>
| Newsgroups | gmane.org.user-groups.trijug.juglist |
|---|---|
| Message-ID | <[email protected]> |
The idea of clarifying scope of variables is good. In Ruby, all globals start with $, instances with @, local instances with lowercase and constants with an uppercase. I think I can buy into 'this.instanceVariable' on those grounds, although this does remind me of Tools vs Language arguments... you don't need explicit naming conventions like Ruby's if you have great tools like Eclipse (which tells you the scope of a variable on mouse hover). I think you've convinced me, though. Thanks! 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 > > -- A. Kevin Baynes Life's a garden. Dig it!