I have noticed that most Objective-C coders never use the self->ivar
syntax when accessing instance variables directly. Most sample code that I see simply references the instance variable without self->
. I think that it is rather confusing to reference an instance variable without making clear that it is an instance variable and not simply a variable of the current scope.
I feel like I want to write stuff like:
- (void)dealloc {
[self->someVar release];
[self->anotherVar release];
[super dealloc];
}
or
- (void)setVar:(Foo *)newVar {
[self->var autorelease];
self->var = [newVar retain];
}
There aren't a whole lot of occasions when we ever even should access our instance variables without using an accessor for encapsulation, but sometimes we need to such as in dealloc, or in custom getters and setters.
Am I a bad person/programmer for doing this? Is there some really good reason for not writing code like this? Because it feels really good to do it this way.