On Nov 16, 2011, at 1:00 AM, Don Quixote de la Mancha <quix...@dulcineatech.com> wrote:
> Using properties significantly increased the size of my executable > file. If I had something like this: > > float a = [self foo: self.scale]; > float b = [self bar: self.scale]; > > I could cut down the size of my code quite a bit by caching the return > value of self.scale: > > float theScale = self.scale; > float a = [self foo: theScale]; > float b = [self bar: theScale]; > > Now just removing one of two getter calls by caching its result won't > have that much effect on binary size, but the other night I went > through my code to do the exhaustively. The size decrease was quite > significant. This isn't an argument against properties, it's an argument against redundant method calls. The same debate existed long before the @property keyword and dot syntax was introduced. > > Using properties when a simple iVar would do is not justified. One > wants to use properties only when the generated code significantly > reduces the amount of work one has to do as a coder, for example by > automagically taking care of retain counts. Or if the superclass anticipates a subclass overriding the getter. Designing for extensibility versus speed is a common tradeoff. Some people always use the property outside of -init and -dealloc. (Brent Simmons recently tweeted about doing this, and there was a mixed set of replies.) I typically don't, unless I'm writing framework code that I expect other developers will subclass. But because it's all our own code, it's very easy to move to direct ivar access if we need more speed, or to calling accessors for correctness. > > Calling accessors is also quite slow compared to a direct iVar access, > because it has to go through Objective-C's message dispatch mechanism. objc_msgSend isn't very slow. What measurements have you done that indicate objc_msgSend is taking any appreciable amount of time? > > Focussing on interface is no excuse for weighty, bloated code! I would argue that you have your priorities confused. Focusing on interface recognizes that programmer time is far more expensive than computer time. --Kyle Sluder_______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com