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

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];


  • Follow-Ups:
    • Re: Silly question
      • From: Lance Bland <email@hidden>
References: 
 >Re: Silly question (From: "Erik M. Buck" <email@hidden>)

  • Prev by Date: Re: CriticalAlert
  • Next by Date: Re: (OT) auto-indent a big hit here
  • Previous by thread: Re: Silly question
  • Next by thread: Re: Silly question
  • Index(es):
    • Date
    • Thread