Update 5/23/2012: Mystery solved! See the end of this post below.
Until recently, for as long as I’ve been using Xcode, this code has never compiled successfully without warning:
#import <Foundation/Foundation.h>
@interface Foo : NSObject
@end
@implementation Foo
– (void)myMethod {
[self myPrivateMethod];
}
– (void)myPrivateMethod {}
@end
Can you see why? The method myPrivateMethod
is never declared, and it isn’t defined until after its first usage in myMethod
. Since C compilers are, as far as I’m aware, by standard implementation if not formal definition single-pass compilers, that first usage should have been flagged as something the compiler didn’t know about.
In Xcode 4.3.2, the current version of Xcode, the compiler doesn’t make a peep.
This is big.
Many of all the ancient, crufty things we hate about C and C-derived languages are due to that single-pass compilation — predeclarations and declarations of methods and classes (and everything), #import and #include statements, .h files at all. Java, for example, has none of these things.
What if clang got rid of all of that for Objective-C?1
John Siracusa in his 2011 episode of Hypercritical “A Dark Age of Objective-C” bemoaned how Apple was dragging its feet about moving on from its current legacy language and runtime to something more modern and competitive.
What if they’ve already started, without telling anyone?2
Update 5/23/2012: Turns out, it’s not a conspiracy, it’s a bugfix.3 Discussed in this March 6, 2012 thread in the Xcode-users mailing list. The thread points to this llvm commit on August 31, 2011 and mentions that the behavior is new to Xcode 4.3. It also mentions this post on the Apple DevForums, but I get an error when I try to go to it. (I really wish Apple made its non-NDAed DevForums posts freely available on the web.)
Thanks to Andy Lee for the information.
So I guess clang isn’t taking over the world, just yet? It’s too bad…
1. C functions still require declaration before usage.
↩︎
3. Which would be a pretty good name for a podcast episode.
↩︎