Theocacao
Leopard
Design Element
Comment on "Core Animation Sample Code: NanoLife"
by Scott Stevenson — Feb 23
@Adrian Bool: Scott, Could I ask you why you use extra local variables in your code

Every time you do either one of these:
self.containerLayerForSpheres [self containerLayerForSpheres]

... there's a cost for the method call. It's very small in this case, but if you're making several hundreds or thousand calls like this, it's probably better to get a local reference to the object so you don't have to keep calling the method.

It's also much easier to read "sphereContainer" than the longer "self.containerLayerForSpheres". It's important that instance variables and methods have very descriptive names, but I think it's less important for local variables because their purpose is clear from the context (a variable name like "sc" is not clear enough, though).

A third reason is that it's typically better to "set up" an object locally before setting it as an instance variable with the setter method, because you might write a setter that does some post-processing, such as creating a cached version of the object. It's better to give the setter the complete, finished object.
Back to "Core Animation Sample Code: NanoLife"
Design Element

Copyright © Scott Stevenson 2004-2015