• 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: Method not seeing array as array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Method not seeing array as array


  • Subject: Re: Method not seeing array as array
  • From: Marco Scheurer <email@hidden>
  • Date: Thu, 3 Feb 2005 12:49:15 +0100

On Feb 03, 2005, at 02:24AM, Andrew Farmer wrote:

On 2 Feb 2005, at 13:08, Marco Scheurer wrote:
While not harmful, and probably good style (except for the the 'if(!self) return nil' line)

Is there something wrong with
if(!self) return nil;
other than its being a shorthand for
if(self == nil) return nil;

Not from a code correctness point of vue: all compilers will do the right thing. It is really a matter of taste: I prefer to always us blocks, even for only one statement (I like to visually close if, while, etc. with a closing }.


I also prefer to explicit test equality with a number (== 0) or a pointer (== NULL) or an on object (== nil) etc. (but not with booleans of course).

So I would write:

if (self == nil) {
	return nil;
}

More important, I'm not fond of the school of programming where magic formulas are applied without thinking. This is true of the infamous autorelease accessors, and this "pattern" also falls in that category.

When you inherit from a class, you usually know what super will do, and it is not necessary to blindly use "defensive programming" and test against everything. When inheriting from NSObject, how could init return anything else than self?

There's a good reason to write:

self = [super init];

and that's because init returns an object, so we may just as well use it rather than documenting the fact that we don't care by writing:

(void) [super init];

Other than that, it is not necessary in that case. Also, the value returned by NSObject's init can not be nil, so I usually don't put that test in my code.

No flame, please, all this is an opinion and a matter of taste. I know that the doc says "Programs should therefore always use the object returned by init, and not necessarily the one returned by alloc or allocWithZone:, in subsequent code."...

Marco Scheurer
Sen:te, Lausanne, Switzerland   http://www.sente.ch

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Method not seeing array as array
      • From: Evan Schoenberg <email@hidden>
References: 
 >Method not seeing array as array (From: Michael Swan <email@hidden>)
 >Re: Method not seeing array as array (From: Andrew Farmer <email@hidden>)
 >Re: Method not seeing array as array (From: Marco Scheurer <email@hidden>)
 >Re: Method not seeing array as array (From: Andrew Farmer <email@hidden>)

  • Prev by Date: Re: [AppleScript Studio] Table View
  • Next by Date: Stop dragging my <NSWindow> around
  • Previous by thread: Re: Method not seeing array as array
  • Next by thread: Re: Method not seeing array as array
  • Index(es):
    • Date
    • Thread