Design Element
Comment on "A Roadmap Through Cocoa"
by Scott Stevenson — Jan 21
so why do you prefix instance variables with an underscore ("_delegate") and nevertheless use "delegate" inside the method, Scott? This kind of naming conventions are very confusing to me

A leading underscore usually means "private." All instance variables are implicitly private in Objective-C, so many experienced user simply prefix all of them with an underscore. Part of the reason is to avoid confusion with local variables. For example, take a look at this:

@interface DefinesTest : NSObject { id delegate; } @end @implementation DefinesTest - (void) talkToDelegate { id delegate = nil; } @end

This is, at best, simply confusing. Is the delegate declared in talkToDelegate a local variable or does it refer to the instance variable? If you add an underscore to the instance variable, you can easily tell the two apart.
Back to "A Roadmap Through Cocoa"
Design Element

Copyright © Scott Stevenson 2004-2015