• 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: じょいすじょん <email@hidden>
  • Date: Tue, 8 Aug 2017 09:17:33 +0900

> On Aug 8, 2017, at 9:09, Jens Alfke <email@hidden> wrote:
>
>
>> On Aug 7, 2017, at 5:02 PM, David Hoerl <email@hidden> wrote:
>>
>> But then I though - heck, if Foo has NSObject as its super class, gee, maybe
>> -init isn't really need. I mean, if all of Foo's ivars and properties are
>> initialized, its a shortcut, right.
>
> -[NSObject init] happens to be a no-op empty method. So if a direct subclass
> of NSObject has no -init method of its own, you could get by with just
> calling +alloc. However, I think this would be a really bad idea. If at some
> point you needed to add an -init method to class Foo, like to initialize an
> ivar, you’d have to go and fix all this code that wasn’t calling -init, or
> else you’d suddenly have a number of bugs in your code. Even worse, if
> someone else added the -init method and didn’t know about this quirk of how
> callers initialized Foo, they might have  no idea why their method didn’t get
> called. Yuck.
>
> —Jens
> _______________________________________________
>
It definitely should never pass in a code review for exactly these reasons and
should be fixed by either adding the init call or changing the alloc call to a
new call (since new is a synonym for alloc init).
If you saw it pre-existing in code that was being checked in, require it to be
fixed. Refusal to type a few characters is absolutely a shortcut to trouble
later (Y2K).
_______________________________________________

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: Carl Hoefs <email@hidden>
References: 
 >Is "-init" really needed? (From: David Hoerl <email@hidden>)
 >Re: Is "-init" really needed? (From: Jens Alfke <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