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 protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to