Re: obj-c functions versus class methods
Re: obj-c functions versus class methods
- Subject: Re: obj-c functions versus class methods
- From: Patrick Machielse <email@hidden>
- Date: Sat, 13 Mar 2004 19:05:57 +0100
op 13-03-2004 18:13 schreef Mark Eissler
>
Second, I'd like to clarify that the fact that a plain C function is
>
independent and cannot be extended through OOP isn't a concept that I
>
simply forgot. Rather, that wasn't the point of my question. I think it
>
is often quite clear (under normal circumstances) when an object
>
oriented design is beneficial versus functional decomposition.
Don't confuse 'functional' with 'funtion()'...
>
With obj-c the question of plain C versus a class method should
>
probably consider the overhead to instantiate a class and the necessary
>
exposure of symbols in the binary. Other than those two issues, I can't
>
seem to see if there is a difference between the two other than
>
preference and portability issues. What am I missing?
Since they are _class_ methods there is no need to intantiate anything. The
message goes to the class object, not to an instance. What is true, is that
these symbols will be dynamically bound, so there is some 'searching'
involved at runtime before the method is called (messaged). C function
adresses on the other hand are bound at compile time (and functions can be
inlined by the compiler), so calling functions will generally be faster than
messaging a class method. If you need to do a calculation lots of times, say
in a loop, consider a function.
By the way, in Java you have no choice; you have to use class methods like
Math.max() as Java doesn't have functions. However, since Java symbols are
bound at compile time there shouldn't be much of a difference compared to
straigh functions (should they have existed). (I think...)
Patrick,
--
Hieper Software
w: www.hieper.nl
e: email@hidden
_______________________________________________
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.