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

Re: Accessors


  • Subject: Re: Accessors
  • From: Chris Ridd <email@hidden>
  • Date: Thu, 08 Aug 2002 12:44:08 +0100

Bill Cheeseman <email@hidden> wrote:
> on 02-08-08 2:03 AM, Shawn Erickson at email@hidden wrote:
>
>> - setSomeName: (SomeType*)newSomeName
>> {
>> if (newSomeName == _someName) return;
>> [_someName release];
>> _someName = [newSomeName copy];
>> }
>
> I've noticed a couple of people testing for equality and returning in the
> first line, like this. My usual practice is to test for inequality, then
> fall through to the bottom if the test is false.
>
> Is there some advantage to the return? I've always thought it was just a
> matter of style.

Style - it doesn't distract from the guts of the method, and it avoids a
level of indentation which you'd need if you did the "fall-through to the
bottom". It does violate a principle of only having one exit point per
method however, though to an extent that's just style too.

In such a short and simple method it isn't really worth it.

Cheers,

Chris
_______________________________________________
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.

References: 
 >Re: Accessors (From: Bill Cheeseman <email@hidden>)

  • Prev by Date: Guard clauses vs. early return (Re: Accessors)
  • Next by Date: RE: Accessors
  • Previous by thread: Guard clauses vs. early return (Re: Accessors)
  • Next by thread: Prgramming style (was: Accessors)
  • Index(es):
    • Date
    • Thread