Re: semantics of init
Re: semantics of init
- Subject: Re: semantics of init
- From: Karl Goiser <email@hidden>
- Date: Thu, 5 Jun 2003 09:28:29 +1000
A very important principle I learned a long time ago in another
language not so far away is to regard message sends as zero cost.
Of course, I know they do have a cost. But if you work from the cost
perspective, you start doing bad things that could end up costing you
much more in the long run.
eg 1: 'Gee, this code does a lot of message sends to one method in
another class in this loop. Maybe I should copy the code here...'
eg 2: 'Gee, the objects in this array do a lot of state information
requests to the parent object. Maybe I should copy some of the state
information to the local objects...'
The problems are in terms of maintenance and upgrading. Also the extra
overheads of maintaining the local state information and the overheads
of maintaining that code which can get very hairy and then become a
potential source of bugs.
Doing this sort of thing can also affect the design of your objects so
they become less understandable and less re-useable.
I think this is a very important point.
On Thursday, June 5, 2003, at 04:40 AM, Cameron S. Bahan wrote:
I prefer to use accessor methods whenever I need to access or query a
variable, including constructors and destructors ( -init and -dealloc
). To me this assists in maintaining the code base (even with private
variables). If any changes are made in setting / retrieving the
variable, changes to the variable name, or changes to the variable
definition - the single point of access of the get/set routines makes
the change go a lot smoother. If, however, that is not followed in all
cases ( thus including -init ) then you increase the possibilities for
introducing bugs into the code.
If, however, you are constrained by performance and your optimization
traces back to using the accessors in your constructors and destructors
... then Obj-C is not likely the technical solution you are looking
for. Moving to C++ or even further into C might be a choice you should
consider.
Thoughts ? comments ?
On Wednesday, June 4, 2003, at 01:42 PM, Marcel Weiher wrote:
On Wednesday, June 4, 2003, at 04:32 Uhr, Daniel Zitter wrote:
Another problem I'm seeing with this approach is performance - I
don't
think ObjC messages can be inlined, by definition, so every [self
xxx]
call is an extra expense you could probably do without. Plus, it
may
muck up your object's initial message cache, by using a bunch of
setter
methods that don't otherwise get used. So you'd see an extra
performance loss, initially.
I don't buy the argument that the use of setter methods in -init
would substantially degrade performance.
This smells like premature optimization to me.
You've got a well-developed olfactory organ there ;-)
Regards,
Marcel
--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
f0249ab8b1af193ef5addcf39fdff5ca
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.