Subject: Re: Is "-init" really needed?



As others have mentioned, I too have never seen any evidence or statements from
Apple that discourages +new or -init. Or designated initializers. The
Objective-C Programming Guide from Apple describes very well all of the above
and the reasoning behind using them. Please point to evidence, such as
documentation or statements by Apple. My fear is that further speculation
without backup is confusing people.

Getting back to the original question…you still need -init. And on a related
note, it’s a great shorthand to use +new.

Doug Hill


> On Aug 8, 2017, at 6:46 AM, [email protected] wrote:
>
> Unlike with Swift, in Objective-C it is to no small part the developers who
> drive how the language evolves.
>
> +new used to be the canonical initializer in the very olden days. But then
> folks wanted a better distinction between object allocation and object
> initialization to make memory management a bit more mechanical and less
> hidden. They also came up with the concept of the "designated initializer".
> That was in the very early 80s IIRC.
>
> This worked, but two things happened:
>
> - having to remember designated initializers, and chaining them correctly
> when subclassing, is a tad cumbersome. It's like having to know a secret
> handshake to use an object. Further Objective-C never formally introduced
> syntactic support for a designated initializer, so eventually some people
> resorted to some weird hinting with macros. Yuk.
>
> - ARC
>
> So "designated initializers" became de-emphasized over time, most modern
> objects rarely use them. And ARC now makes it less important to distinguish
> between object allocation and object initialization. Hence the renaissance of
> +new. And with the advent of dot notation some (like me) even started to
> further de-emphasize that by using "MyClass.new". This is debatable I guess,
> but I like it, because it visually distracts less from the purpose of the
> surrounding code.
>
> Just my 2 cents, and I may be completely wrong.
>
> Gerd
>
>
>> On Aug 8, 2017, at 05:13, Uli Kusterer <[email protected]
>> <mailto:[email protected]>> wrote:
>>
>> On 8. Aug 2017, at 02:23, Carl Hoefs <[email protected]> wrote:
>>> Is the use of +new discouraged also?
>>
>> Apple have gone back and forth on this AFAIR. +new was actually the
>> pre-retain/release way to create an object. So it has been discouraged since
>> ... OpenStep, I think? But it was never formally deprecated, and I'm seeing
>> it used more and more in ARC code these days.
>>
>> Cheers,
>> -- Uli Kusterer
>> "The Witnesses of TeachText are everywhere..."
>> http://www.zathras.de
>

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/maillists%40codeha.us

This email sent to [email protected]



Programming list archiving by: Enterprise Git Hosting