• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: About iVars declaration and property
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: About iVars declaration and property


  • Subject: Re: About iVars declaration and property
  • From: Kyle Sluder <email@hidden>
  • Date: Wed, 16 Nov 2011 08:03:51 -0800

On Nov 16, 2011, at 1:00 AM, Don Quixote de la Mancha <email@hidden> 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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: About iVars declaration and property
      • From: Don Quixote de la Mancha <email@hidden>
References: 
 >Re: About iVars declaration and property (From: Matt Neuburg <email@hidden>)
 >Re: About iVars declaration and property (From: Torsten Curdt <email@hidden>)
 >Re: About iVars declaration and property (From: glenn andreas <email@hidden>)
 >Re: About iVars declaration and property (From: Torsten Curdt <email@hidden>)
 >Re: About iVars declaration and property (From: Kyle Sluder <email@hidden>)
 >Re: About iVars declaration and property (From: Torsten Curdt <email@hidden>)
 >Re: About iVars declaration and property (From: Kyle Sluder <email@hidden>)
 >Re: About iVars declaration and property (From: Torsten Curdt <email@hidden>)
 >Re: About iVars declaration and property (From: Jens Alfke <email@hidden>)
 >Re: About iVars declaration and property (From: Torsten Curdt <email@hidden>)
 >Re: About iVars declaration and property (From: Jens Alfke <email@hidden>)
 >Re: About iVars declaration and property (From: Don Quixote de la Mancha <email@hidden>)

  • Prev by Date: Re: About iVars declaration and property
  • Next by Date: Memory usage from PID
  • Previous by thread: Re: About iVars declaration and property
  • Next by thread: Re: About iVars declaration and property
  • Index(es):
    • Date
    • Thread