• 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: Is "-init" really needed?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is "-init" really needed?


  • Subject: Re: Is "-init" really needed?
  • From: Alastair Houghton <email@hidden>
  • Date: Wed, 9 Aug 2017 11:01:53 +0100

On 8 Aug 2017, at 17:38, Doug Hill <email@hidden> wrote:
>
> As others have mentioned, I too have never seen any evidence or statements
> from Apple that discourages +new or -init.

I suspect it was ObjC programmers themselves rather than Apple/NeXT that
discouraged it.  As for why, well I can imagine a few reasons:

- Performance - it incurs an extra message send (which would have been an issue
back in the day)

- Clarity - [[… alloc] init] shows clearly that it’s a two step operation (some
classes support being *re*-initialized, so you can call initialisers more than
once; other classes don’t actually need initialising)

- If +new was the way to go, you’d need variants of +new for each variant of
-init (or you have to use [[… alloc] init] anyway)

- The fact that convenience constructors were often written naming the object,
e.g. [NSString stringWithFormat:…], [NSArray array].  +new would duplicate
that, but isn’t as nice to read or look at.  OK, +new doesn’t autorelease, but
still.

Kind regards,

Alastair.

--
http://alastairs-place.net

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Is "-init" really needed?
      • From: Doug Hill <email@hidden>
References: 
 >Is "-init" really needed? (From: David Hoerl <email@hidden>)
 >Re: Is "-init" really needed? (From: Jens Alfke <email@hidden>)
 >Re: Is "-init" really needed? (From: じょいすじょん <email@hidden>)
 >Re: Is "-init" really needed? (From: Carl Hoefs <email@hidden>)
 >Re: Is "-init" really needed? (From: Uli Kusterer <email@hidden>)
 >Re: Is "-init" really needed? (From: email@hidden)
 >Re: Is "-init" really needed? (From: Doug Hill <email@hidden>)

  • Prev by Date: Re: Is "-init" really needed?
  • Next by Date: Re: Is "-init" really needed?
  • Previous by thread: Re: Is "-init" really needed?
  • Next by thread: Re: Is "-init" really needed?
  • Index(es):
    • Date
    • Thread