• 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: Ondra Cada <email@hidden>
  • Date: Fri, 21 Dec 2001 14:55:35 +0100

Ben,

>>>>>> Ben Hines (BH) wrote at Thu, 20 Dec 2001 23:23:07 -0800:
BH> Most CS professors will tell you not to use multiple returns.

Well, yep, but (almost) any rule, if used too strictly, becomes PITA.

Especially the pattern

-(void)foobar:arg {
if (!arg) return;
// blahblahblah
}

seems to me indeed much more readable (ie. easily maintainable) than

-(void)foobar:arg {
if (arg) {
// blahblahblah
}
}

Both of them are "correct" though, and I guess the selection of either is in
the eye of beholder. The latter might be more maintainable if you accept the
other advice

BH> As Ondra said, if your function can't fit on one screenful of text,
BH> it's too long.

(which I've learnt from Doug Comer, incidentally), since then you can see
that if !arg, the mthod really does nothing at the first look. Still I
personally would prefer the former.

Just like those dreaded '=' and '==': myself, I use no extra macros like
JCR's -- I learnt to be kinda careful with them ages ago when I started with
C, and in all those years since was bitten, uhm, once or twice. In my _very
personal_ opinion, it's a good price for (a) possibility to nest assignment
operators into ifs, (b) better (=more intuitive) readability of "if (p==123)"
compared to safer, but to me kinda weird "if (123==p)".

I think it's a matter of personal preferences. I don't like unnecessary
parentheses; I also found that

if (a && b || c && d) command;

is for me _much_ more readable (and thus easily and more safely
maintainable) than the equivalent others here seem to prefer:

if ((a && b) || (c && d))
{
command;
}

which makes me think thrice why on earth those unnecessary things were used
-- is there some hidden trick or hook?
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
2K Development: email@hidden http://www.2kdevelopment.cz
private email@hidden http://www.ocs.cz/oc


  • Follow-Ups:
    • Re: Silly question
      • From: "Craig S. Cottingham" <email@hidden>
References: 
 >Re: Silly question (From: Lance Bland <email@hidden>)
 >Re: Silly question (From: Ben Hines <email@hidden>)

  • Prev by Date: Re: Is an just allocated object allways set to autorelease? What about my subclasses?
  • Next by Date: Re: row bg color in NSOutlineView
  • Previous by thread: Re: Silly question
  • Next by thread: Re: Silly question
  • Index(es):
    • Date
    • Thread