• 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: ObjC procedure vs C procedure within Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ObjC procedure vs C procedure within Cocoa


  • Subject: Re: ObjC procedure vs C procedure within Cocoa
  • From: email@hidden
  • Date: Fri, 10 Feb 2006 16:06:51 -0800

void doAlphaRects(CGContextRef context){} vs -(void) doAlphaRects (...){}

An excellent question. I don't think there's a definitive favourite... in general it's probably a style thing, but there are a few rough guidelines that I myself follow:


* C functions are faster to call than ObjC methods, so anything that's going to get called a lot and has no explicit reason to be a method, should be a function.
* If you want to hide the procedure in question, a C function is harder to find and get at than a method. There's no such thing as a private method as far as the ObjC runtime is concerned.
* C functions don't have implicit access to self or any instance variables there-in; they are not members of the class. Thus, if your code needs to access a dozen instance variables, the overhead of passing all those as parameters can become prohibitive.
* Subclasses cannot override a C function (well, not easily or nicely).


Those cases aside, I prefer to keep things as methods, so that they can be utilised by other classes, subclasses, and whatnot. But there are plenty of places where I explicitly use C functions for one or more of the reasons above.

I find I ask this question of my own code pretty rarely, though... in most cases it seems pretty intuitive as to which way it should go.

Wade
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >ObjC procedure vs C procedure within Cocoa (From: "Frederick C. Lee" <email@hidden>)

  • Prev by Date: ObjC procedure vs C procedure within Cocoa
  • Next by Date: Re: adding rows to an array-controller managed table atomically
  • Previous by thread: ObjC procedure vs C procedure within Cocoa
  • Next by thread: Re: ObjC procedure vs C procedure within Cocoa
  • Index(es):
    • Date
    • Thread