Re: Programming Style: Method Definition with or without a semicolon.
Re: Programming Style: Method Definition with or without a semicolon.
- Subject: Re: Programming Style: Method Definition with or without a semicolon.
- From: glenn andreas <email@hidden>
- Date: Fri, 16 Oct 2009 09:19:41 -0500
On Oct 16, 2009, at 2:55 AM, Bill Bumgarner wrote:
On Oct 16, 2009, at 12:17 AM, Sander Stoks wrote:
If it's a feature, then it's definitely a new one since the
original specification of Objective-C. It turned out to be
surprisingly hard to find that specification, but I found a grammar
description here:http://www.cilinder.be/docs/next/NeXTStep/3.3/nd/
Concepts/ObjectiveC/B_Grammar/Grammar.htmld/index.html
There it says:
instance-method-definition:
<sp.gif><c2D.gif> [ method-type ] method-selector [ declaration-
list ] compound-statement
method-selector:
<sp.gif>unary-selector
<sp.gif>keyword-selector [ , ... ]
<sp.gif>keyword-selector [ , parameter-type-list ]
The declaration-list and compound-statement are not specified
further and are taken from the C spec. In other words: There's no
semicolon.
On the other hand, the grammar spec has been removed from Apple's
documentation, and I suppose the official line is now "Objective-C
is whatever we ship with Xcode."
I haven't booted my NS 0.8 cube in about a decade, but I'm pretty
sure the semi-colon was always required in the header file and
always allowed in the @implementation.
'Twas many a moon ago, but, I do distinctly remember triple-clicking
method declarations from headers (with semis) to copy-paste into my
implementation without deleting the semi. It always stuck with me
as an über-convenience.
b.bum
You can (or at least could) copy the entire @interface section from
the .h, paste into the .m and change @interface to @implementation and
it would compile.
So yes, this is legal:
@implementation MyObject : NSObject<SomeProtocol> {
id myIvar;
}
- (void) doSomething;
@end
Not that I'd recommend or even admit to doing this (I have no idea
what happens if the @implementation class details are different from
the @interface ones, and, again, not that I'd ever admit to having
done this, it is easy to accidentally write your implementation in
your .h file and leave the pasted @interface in your .m).
Glenn Andreas email@hidden
The most merciful thing in the world ... is the inability of the human
mind to correlate all its contents - HPL
_______________________________________________
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