• 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: Declarations near usage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Declarations near usage


  • Subject: Re: Declarations near usage
  • From: tibbetts <email@hidden>
  • Date: Wed, 16 Oct 2002 15:25:17 -0400 (EDT)

James,

> One thing I don't like about Objective C is that you have to declare
> variables at the top of a block. I think code that declares variables
> near their first use is much more readable. This is the norm in C++.

The "declare at the beginning" syntax is a feature (sic) of C.

> To get around this in Objective C, I sometimes add blocks (open and
> close parenthesis) in the middle of my methods. Then I can declare
> variables at the top of this block. I also declare variables, as
> needed, at the top of blocks that follow if
> statements.
>
> When done within reason, this seems to make Objective C code more human
> readable, but I wonder if it introduces any slight inefficiencies. How
> about efficiency of declarations in loop bodies?

There should be absolutely no difference at runtime whether you add extra blocks
or not--they are compiler constructs that introduce a new -naming- scope, not to
be confused with things like jumps (for loops) or stack frames (for functions).
(Of course, it may add a millisecond or two to the -compile- time, but I doubt it.)

For the record, this is a well-established coding practice in C, and probably in
Objective-C, too.

jason r tibbetts
www.toad.net/~tibbetts/jason

:wq


_________________________________________________________________________
This mail sent via toadmail.com, web e-mail @ ToadNet - want to go fast?
http://www.toadmail.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Declarations near usage
      • From: Ondra Cada <email@hidden>
    • empty string, or: totally clearing the NSTextStorage
      • From: Arthur Clemens <email@hidden>
    • Re: Declarations near usage
      • From: Sherm Pendley <email@hidden>
References: 
 >Declarations near usage (From: James Hober <email@hidden>)

  • Prev by Date: Re: Re-open last saved document
  • Next by Date: Re: Declarations near usage
  • Previous by thread: Declarations near usage
  • Next by thread: Re: Declarations near usage
  • Index(es):
    • Date
    • Thread