Re: Looking at self = [super init].
Re: Looking at self = [super init].
- Subject: Re: Looking at self = [super init].
- From: Alex Zavatone <email@hidden>
- Date: Fri, 29 May 2015 14:34:50 -0400
On May 29, 2015, at 2:19 PM, Jens Alfke wrote:
> Not to mention that putting assignments in ‘if’ statements is EVIL, even if it does save you a line of code.
>
> —Jens
I tend to agree with you as it makes the code just a little more obtuse. As an example, I went through this entire email thread typing == by habit instead of =.
However, having to go through a few lines just for an init seems like a lot of noise to add to every object initialization. Seems like we could come up with some sort of macro that would replace that and provide an early return.
Having to indent the statements one extra level in an init just seems like an obvious case of "we're doing this wrong - isn't there any way we can do this better?" That and being able to handle leave with an early return make the init method feel nicer to me. I'm just a little too tired at the moment to put a solution together that doesn't fail badly in the non perfect case.
I was thinking about this statement though:
if (! (self = [super init]) ) {
return nil;
}
// start initing stuff
return self;
Then there must be a nice way to step back to the original question and see if that could be a macro. I'm sure someone's done that already as well.
_______________________________________________
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