Re: Initializing object pointers to nil
Re: Initializing object pointers to nil
- Subject: Re: Initializing object pointers to nil
- From: Gregory Weston <email@hidden>
- Date: Thu, 17 Apr 2003 10:34:42 -0700
Jeffrey Mattox <email@hidden> wrote:
>
I know that [nil release] is allowed (although I can't find
>
documentation), but am I guaranteed that an object pointer will be
>
nil if it hasn't been explicitly set? That is, must I declare
>
variables this way:
>
>
NSArray *myArray = nil;
You don't have to, but it's a good idea.
>
In general, what are the ramifications of initializing variables
>
where they are declared as opposed to in-line, in the code itself?
I don't know if it's still the case with modern compilers, but it used to be that initialization was faster than declare+assign. Whether that's still true or not, I'm of the opinion that setting a known sane value at the point of declaration improves readability (just as a side effect of the compaction) and reliability by ensuring that the variable has no excuse to ever be referenced in an unknown state.
_______________________________________________
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.