(response is pedantic for the purposes of the archive :)

even more better flaming pedanticism!

On Oct 15, 2009, at 10:41 PM, Nathan Vander Wilt wrote:

Ouch. So the following pattern is incorrect?

Yes;  it is incorrect.

NSError* internalError = nil;
(void)[foo somethingReturningBool:bar error:&internalError];
if (internalError) {
  // ...
}

Specifically, assuming anything about the value of 'internalError'
without first determining the return value of -
somethingReturningBool:error: returned a value indicating an error
(typically NO/0/nil/NULL) is an error.

The specific issue is failing to check the return value of the method before touching the internalError value. You MUST check it.

However, the documentation also encourages not assigning nil to local NSError* declarations. Not initializing locals is imho, professionally, realistically, and morally wrong. It's just a bug waiting to happen. And you have to know it is, just looking at it. Whatever might have been saved / gained by not initializing them was wasted, for all of time, the first time I had to debug the segfault. Which I did, like an idiot, a long time ago.

Let me just say I really especially appreciated the time spent debugging other people not initializing their locals. It wasn't visions of sugar plums.

Other people have different perspectives on local variable initialization. Wrong perspectives, but different. Fortunately now, they waste their arguments upon the merciless <http://llvm.org/img/DragonFull.png >

- Ben

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to