On Mon, May 2, 2011 at 1:45 PM, Chris Koerner <[email protected]> wrote:
> Just curious, under what circumstances in ANY language do you use an > underscore in front of a variable/method/object? > > I've never been a fan of underscore prefixes, but I have recently adopted them when working in Objective-C. If I wanted to have an ivar foo, the convention is to have the property that access that ivar be foo/setFoo:. While I *could* have both an ivar called foo and a property called foo, it's a little confusing. For example, self.foo = 23; foo = 23; Those are not the same thing. The first is using the property, while the second is directly accessing the ivar. So now I define ivars as @private and with a leading underscore to make it very explicit if I'm accessing the ivar directly. Joey -- Blog: http://joeygibson.com Twitter: @joeygibson <http://twitter.com/joeygibson> Facebook: http://facebook.com/joeygibson -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
