Re: forward decls vs #import
Re: forward decls vs #import
- Subject: Re: forward decls vs #import
- From: Jens Alfke <email@hidden>
- Date: Thu, 14 Mar 2013 19:47:08 -0700
On Mar 14, 2013, at 4:51 PM, Luther Baker <email@hidden> wrote:
> but more
> recently, several seniors Obj-C devs have suggested that they prefer
> #import in the .h files.
Oh god, no. Who says that?! Importing a header just because it defines a class you’re using is a major waste. The only times you should need to import a header are if you’re subclassing a class declared in it, or implementing a protocol it defines, or using some C-level thing like a constant or macro defined in it.
If you overuse #imports in headers you’re liable to run into circular references at some point, as well as slowing down your compilation unnecessarily. It will also tend to bring into scope a whole ton of irrelevant methods from classes you don’t use, which will make autocomplete less useful and increase the chance of mistakes not getting caught when you end up messaging an ‘id’.
Several times in my career I’ve spent time going through a large and excruciatingly slow-to-build project removing unnecessary #includes/#imports. It makes a big difference.
—Jens
_______________________________________________
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