Re: Declarations near usage
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.