• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Programming Style: Method Definition with or without a semicolon.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Programming Style: Method Definition with or without a semicolon.


  • Subject: Re: Programming Style: Method Definition with or without a semicolon.
  • From: Graham Cox <email@hidden>
  • Date: Fri, 16 Oct 2009 12:06:58 +1100


On 16/10/2009, at 11:54 AM, Frederick C. Lee wrote:

Both seem to work the same.
Is there any benefit of (1) over (2) or is it merely style of programming?

(1) isn't really an alternative way of implementing a method, it's just that the trailing semicolon is ignored. I'm not even sure if it's deliberately allowed (it wouldn't be for a C function) or merely an artifact of the way Obj-C is parsed.


-(void) foo
{

}

and

- (void) foo {

}

are both perfectly valid ways of defining any block in C and always have been (though I personally abhor the second style yet seem to be ploughing my own furrow on that one - almost everyone uses it :(

The ignored trailing semicolon is sort of useful when fleshing out the body of a class that you've declared methods for in the header - you need the semicolon for the method's prototypes, so you can cut and paste the prototype into the main body and just add a trailing block to implement the method - the semicolon doesn't have to be removed. However, again a personal thing, I prefer it not to be there so it's consistent with ordinary C functions, and provided you are just fleshing out the body from the headers for the first time (i.e. no other code has yet been written) doing a search/replace of ';' for '\n {\n\n\n}\n\n' is a useful way to convert all your header methods into bodies ready to be filled in with code.

--Graham


_______________________________________________

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


  • Follow-Ups:
    • Re: Programming Style: Method Definition with or without a semicolon.
      • From: Roland King <email@hidden>
References: 
 >Programming Style: Method Definition with or without a semicolon. (From: "Frederick C. Lee" <email@hidden>)

  • Prev by Date: Re: Serial comm in Cocoa?
  • Next by Date: Re: Programming Style: Method Definition with or without a semicolon.
  • Previous by thread: Re: Programming Style: Method Definition with or without a semicolon.
  • Next by thread: Re: Programming Style: Method Definition with or without a semicolon.
  • Index(es):
    • Date
    • Thread