• 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: argument checks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: argument checks


  • Subject: Re: argument checks
  • From: Alastair Houghton <email@hidden>
  • Date: Mon, 16 Jun 2008 13:47:07 +0100

On 12 Jun 2008, at 15:02, Hamish Allan wrote:

On Thu, Jun 12, 2008 at 6:50 AM, Ashley Perrien <email@hidden> wrote:

NSNumber *myNum;

// Lots of code where I've forgotten to actually do anything with myNum

results = [myClass someCalculationUsing: myNum];

I'd recommend not declaring myNum until you are ready to define it. Making all your declarations upfront is a hangover from when compilers weren't so clever; thankfully, GCC facilitates a more useful locality of reference.

In point of fact, in ANSI C you have always been allowed to start a new block and declare more variables inside it, which actually provides stronger scope guarantees than the C++ mid-block decls feature that has found its way into C99. I can't recall if K&R C worked this way (it's been a long time), or whether it was an ANSI innovation, but it wouldn't surprise me either way.


Additionally it seems to be traditional amongst mid-block decl enthusiasts to ignore the primary advantage of top-of-block decls, which is that you can easily find them. Thanks to the syntax of C and C++, it can occasionally be tricky trying to locate a mid-block decl because they can look strikingly similar to various kinds of statements.

Personally I use both top-of-block and mid-block decls. I have a *slight* preference for top-of-block, if I'm honest, but they both have pros and cons. As with most stylistic questions, there is no Universal Truth here.

Anyway, this being primarily a question of coding style, the OP should do as he feels best and take recommendations from others (me included) with a suitable sized pinch of salt.

Kind regards,

Alastair.

--
http://alastairs-place.net


_______________________________________________

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


References: 
 >argument checks (From: Ashley Perrien <email@hidden>)
 >Re: argument checks (From: "Hamish Allan" <email@hidden>)

  • Prev by Date: Re: argument checks
  • Next by Date: launching finder with optionschi
  • Previous by thread: Re: argument checks
  • Next by thread: Re: argument checks
  • Index(es):
    • Date
    • Thread