Re: Silly question
Re: Silly question
- Subject: Re: Silly question
- From: "John C. Randolph" <email@hidden>
- Date: Thu, 20 Dec 2001 14:15:03 -0800
On Thursday, December 20, 2001, at 01:50 PM, Erik M. Buck wrote:
>
How about return ?
>
>
- (void) mySelector:(id) argument
>
{
>
if (condition)
>
{
>
NSBeginAlertSheet(...);
>
return;
>
}
>
}
>
>
However, it is considered a bad practice to have multiple returns in a
>
single function or method.
I disagree with you on this. What I tend to do is something like:
- (void) mySelector:(id) argument
{
if (condition1)
{
if (condition 2)
{
[everything isHunkyDory];
return;
}
NSLog (@"condition2 didn't happen! Oh, the humanity!");
}
NSLog (@"condition1 is false! Help!");
}
IOW, I'll usually nest the tests that get me to what I *usually*
want to do in the method in question.
-jcr
>
>
How about the following instead ?
>
>
- (void) mySelector:(id) argument
>
{
>
if (condition)
>
{
>
NSBeginAlertSheet(...);
>
}
>
else
>
{
>
// all of the code for the non-error case here
>
}
>
}
[Objc retain];