• 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
Prgramming style (was: Accessors)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Prgramming style (was: Accessors)


  • Subject: Prgramming style (was: Accessors)
  • From: Ondra Cada <email@hidden>
  • Date: Thu, 8 Aug 2002 14:53:55 +0200

On Thursday, August 8, 2002, at 12:29 , Bill Cheeseman 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.

Pure style, and the advantages of return are completely subjective.

Your usual practice is cleaner from the theoretical POV of structured programming: it makes for just one exit of block, which is *generally* desirable. (Note though it might be argued that the break command is bad for the same reason, whilst not using break leads to *really* messed up code with artifical BOOL variables and unnecessary blocks; let's not go into that!)

The outlined practice, OTOH, might be for some better readable and saves at least one line, making so the source (for some) easier to grasp at the first look (there's a world of difference between a complete class implementation which fits inside a window and one which does not).

There are no hard rules "go this way, lest XYZ". There are people who claim the rigid structuring helps them to keep their code bugfree and easily maintainable. My own 20 years + programming experience says exactly otherwise -- for me and my team, it proved better to write a simple and intuitive code whenever rigid rules would lead to more complicated and/or less intelligible one. The best advice for you is just to do what suits *you* best.

Finally, I can't resist to point out that it's funny how -- at least in those first four-odd follow-ups I've seen in the list already -- nicely correlates style rigidness with the "I know best what's good for you" attitude: we who prefer the early return say "do what suits you"; those who prefer rigid style say "do what suits me"! ;))))
---
Ondra Hada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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.
  • Follow-Ups:
    • [OT] Re: Prgramming style (was: Accessors)
      • From: Angela Brett <email@hidden>
References: 
 >Re: Accessors (From: Bill Cheeseman <email@hidden>)

  • Prev by Date: Re: NSRunLoop and NSNotification
  • Next by Date: Re: NSRunLoop and NSNotification
  • Previous by thread: Re: Accessors
  • Next by thread: [OT] Re: Prgramming style (was: Accessors)
  • Index(es):
    • Date
    • Thread