Re: forward decls vs #import
Re: forward decls vs #import
- Subject: Re: forward decls vs #import
- From: Kyle Sluder <email@hidden>
- Date: Thu, 14 Mar 2013 18:04:38 -0700
On Thu, Mar 14, 2013, at 04:51 PM, Luther Baker wrote:
> Given today's computing power, is there a strong case that can be made
> for
> or against the general use of forward declarations?
>
> I grew up using them as a best practice in C++ projects ... but more
> recently, several seniors Obj-C devs have suggested that they prefer
> #import in the .h files.
Forward declarations still fill a unique role: they allow two
mutually-referent declarations to refer to each others' declared types.
For example, without forward declarations, this is impossible:
//--begin
#import "ClassB.h"
@interface ClassA : NSObject
{
B* bIvar;
}
@end
#import "ClassA.h"
@interface ClassB : NSObject
{
A* aIvar;
}
@end
//--end
>
> Initially, I thought this might be related to the prevalence of Java or
> C#
> (which don't deal with such things) ... but the suggestion today was that
> forward decls was actually unnecessary typing, not considered a best
> practice ... and that, indeed, #importing in the .h file could
> potentially
> actually help weed out bad code.
I still like using forward declarations, because it means that a simple
change to an seldom-used interface doesn't cause your entire framework
target to rebuild just because the umbrella header imports that file.
--Kyle Sluder
_______________________________________________
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