<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>mikeash.com pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html comments</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>mikeash.com Recent Comments</description><lastBuildDate>Sun, 10 May 2026 05:05:53 GMT</lastBuildDate><generator>PyRSS2Gen-1.0.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>mikeash - 2010-10-24 20:21:35</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>Thanks for the typo notice, I've fixed it now.
&lt;br /&gt;
&lt;br /&gt;Regarding &lt;code&gt;copyWithZone:&lt;/code&gt;, while you need to support the zone APIs when overriding in case someone decides to call them directly, I don't think it's important to actually respect the zone parameter. Zones are pretty much unused and useless these days. Certainly it would do no harm to use &lt;code&gt;allocWithZone:&lt;/code&gt; in your implementation, but I don't think it's worth any bother.</description><guid isPermaLink="true">f840a378c394d69aa181bacdc206a1f8</guid><pubDate>Sun, 24 Oct 2010 20:21:35 GMT</pubDate></item><item><title>DavidPhillipOster - 2010-10-24 04:26:08</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>Setters:
&lt;br /&gt;
&lt;br /&gt;typo:
&lt;br /&gt;&amp;nbsp;s/The superclass my call the setter/The superclass may call the setter/
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;Copy:
&lt;br /&gt;
&lt;br /&gt;copyWithZone: shouldn't call alloc, as you've written, it should call allocWithZone:  That's what allocWithZone:  is for.</description><guid isPermaLink="true">0cc11e27139e2c1cba0cc6207c08e851</guid><pubDate>Sun, 24 Oct 2010 04:26:08 GMT</pubDate></item><item><title>Steve Wart - 2010-09-12 13:36:18</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>There is an alternative solution to the &lt;code&gt;NSCopyObject()&lt;/code&gt; problem that doesn't involve tricks with C pointers. The Smalltalk idiom for Object copy is to implement it as follows:
&lt;br /&gt;&lt;code&gt;
&lt;br /&gt;copy
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;^self shallowCopy postCopy
&lt;br /&gt;&lt;/code&gt;
&lt;br /&gt;&lt;code&gt;shallowCopy&lt;/code&gt; is a primitive that behaves essentially the same way as &lt;code&gt;NSCopyObject()&lt;/code&gt;. Apple's documentation states that it will be deprecated at some point, but I think the alternatives are worse.
&lt;br /&gt;
&lt;br /&gt;in Objective-C syntax the most abstract class might contain something like:
&lt;br /&gt;&lt;code&gt;
&lt;br /&gt;-(id)copyWithZone:(NSZone *)zone {
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// shallow copy
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;id copy = NSCopyObject(self, 0, nil);
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[copy postCopy];
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return copy;
&lt;br /&gt;}
&lt;br /&gt;&lt;/code&gt;
&lt;br /&gt;As a rule, subclasses should not overrride &lt;code&gt;copy&lt;/code&gt;, but they could implement &lt;code&gt;postCopy&lt;/code&gt; to maintain reference counting semantics:
&lt;br /&gt;&lt;code&gt;
&lt;br /&gt;-(void)postCopy {
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[super postCopy];
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[someString retain];
&lt;br /&gt;}
&lt;br /&gt;&lt;/code&gt;
&lt;br /&gt;</description><guid isPermaLink="true">2e7089b7b82db9ee910a11cb4ebf675a</guid><pubDate>Sun, 12 Sep 2010 13:36:18 GMT</pubDate></item><item><title>Sean McB - 2010-09-12 01:10:06</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>Mike: well, it wouldn't be the first time Apple's docs were wrong. :)
&lt;br /&gt;
&lt;br /&gt;Personally, I trust Greg Parker's advice (in the link I posted above) more than the docs.  Of course, it doesn't contradict your advice to 'always write your dealloc implementation to tolerate an uninitialized object', one should do that _also_.
&lt;br /&gt;
&lt;br /&gt;Anyway, this is another nice thing about GC... no release/dealloc anyway. :)</description><guid isPermaLink="true">72a533fc1840997ee5f4091c77086a38</guid><pubDate>Sun, 12 Sep 2010 01:10:06 GMT</pubDate></item><item><title>mikeash - 2010-09-04 02:52:16</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>&lt;b&gt;Sean McB:&lt;/b&gt; While the idea that you should call &lt;code&gt;[super dealloc]&lt;/code&gt; directly has been in vogue lately, it's contradicted by the documentation:
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;Subclass implementations of this method should initialize and return the new object. If it can’t be initialized, they should release the object and return nil.&lt;/code&gt;
&lt;br /&gt;
&lt;br /&gt;(From the docs for &lt;code&gt;-[NSObject init]&lt;/code&gt;.)
&lt;br /&gt;
&lt;br /&gt;I mention that this is why you should always write your &lt;code&gt;dealloc&lt;/code&gt; implementation to tolerate an uninitialized object. I would go so far as to say that not doing so would be a bug in the subclass.
&lt;br /&gt;</description><guid isPermaLink="true">7165d8428dd1bd92dc88ccc4f4ad74fb</guid><pubDate>Sat, 04 Sep 2010 02:52:16 GMT</pubDate></item><item><title>Sean McB - 2010-09-04 02:16:06</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>Patrick Stein -&amp;gt; when something fails in init, you should in fact call [super dealloc].
&lt;br /&gt;
&lt;br /&gt;"[self dealloc] or [self release] are bad because they might call some subclass's -dealloc method even though the subclass's -init hasn't done anything yet."[1]  Remember method dispatch is always dynamic in Obj-C.
&lt;br /&gt;
&lt;br /&gt;[1] &lt;a href="http://lists.apple.com/archives/objc-language/2008/Sep/msg00133.html"&gt;http://lists.apple.com/archives/objc-language/2008/Sep/msg00133.html&lt;/a&gt;</description><guid isPermaLink="true">83c188fb00a4e2e395130c425ebdd454</guid><pubDate>Sat, 04 Sep 2010 02:16:06 GMT</pubDate></item><item><title>Jim Rodovich - 2010-08-28 19:41:44</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>&lt;b&gt;Anonymous&lt;/b&gt;: Good point that I hadn't considered.  The lack of a relevant stack is probably on its own a good enough reason not to use autorelease as I proposed, unless you're specifically concerned about waiting too long for release to return or about the stack exploding due to an extremely long release-dealloc-set:nil chain reaction.  (I still have linked lists on my mind.)</description><guid isPermaLink="true">4afb9f7f6167d478433e1b20cc3eccb5</guid><pubDate>Sat, 28 Aug 2010 19:41:44 GMT</pubDate></item><item><title>mikeash - 2010-08-28 17:45:16</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>&lt;b&gt;Jim Rodovich:&lt;/b&gt; Thread safety is a binary property: either something is thread safe, or it's not. None of the setters I showed, nor either of the ones you show, are thread safe. Yours narrow the window for the race condition, but there is still the possibility for a second thread to grab a reference to the object, and then for the first thread to destroy it before the second thread can retain it. When it comes to threaded programming, narrowing the window for a race condition is usually a &lt;i&gt;bad&lt;/i&gt; idea, because it makes problems much harder to track down and debug. Better to crash early and often if the code is busted.
&lt;br /&gt;
&lt;br /&gt;It is possible to do a lockless thread-safe setter but it is an &lt;i&gt;enormous&lt;/i&gt; amount of work, something like 100-200 lines of code last time I tried it. Basically, if you need thread-safe setters (and that's &lt;i&gt;usually&lt;/i&gt; the wrong place for thread safety, but not always) then use a lock.</description><guid isPermaLink="true">75ba09d089d0952b396d323c703e409e</guid><pubDate>Sat, 28 Aug 2010 17:45:16 GMT</pubDate></item><item><title>Anonymous - 2010-08-28 15:57:53</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>&lt;b&gt;Jim Rodovich&lt;/b&gt;: I've always done the latter, using autorelease. However, using autorelease technically can make programs harder to debug since if there is a crash during the actual release, your stack trace with the autorelease will be nowhere to be found.</description><guid isPermaLink="true">e8b35af753bf2cef9c5196d67753608a</guid><pubDate>Sat, 28 Aug 2010 15:57:53 GMT</pubDate></item><item><title>Jim Rodovich - 2010-08-28 14:48:14</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>Regarding memory management in setters, &lt;code&gt;obj&lt;/code&gt; can be freed even if it's unequal to the released ivar, if the ivar holds the only reference to &lt;code&gt;obj&lt;/code&gt; and releases it during dealloc.  (For example, suppose you're implementing a linked list.)  The second pattern you propose is safer: always retain before releasing.
&lt;br /&gt;
&lt;br /&gt;With both patterns, the ivar is temporarily assigned to a value which could have been freed, so I'm not sure that either is thread-safe.  (I may be wrong -- I'll admit I was releasing first before I saw this post.)  Wouldn't the following be safer?
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;NSObject * temp = myObjIvar;
&lt;br /&gt;myObjIvar = [obj retain];
&lt;br /&gt;[temp release];&lt;/code&gt;
&lt;br /&gt;
&lt;br /&gt;Or, more elegantly,
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;[myObjIvar autorelease];
&lt;br /&gt;myObjIvar = [obj retain];&lt;/code&gt;</description><guid isPermaLink="true">463f1db98dc70d65c6b7af4744fe5fe8</guid><pubDate>Sat, 28 Aug 2010 14:48:14 GMT</pubDate></item><item><title>Anonymous - 2010-08-28 12:32:03</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>&lt;b&gt;Mike Shields&lt;/b&gt;: Even better would be if Apple implemented Mike Ash's suggestion that Apple implements -hash on NSObject returning 0 at the very least...
&lt;br /&gt;
&lt;br /&gt;Granted it would be more likely if &lt;b&gt;Mike Ash&lt;/b&gt; submitted this as an actual bug report to Apple (I would but it's just too early in the morning).</description><guid isPermaLink="true">1f030c179a23e2b6ec415c2b221730ae</guid><pubDate>Sat, 28 Aug 2010 12:32:03 GMT</pubDate></item><item><title>Anonymous - 2010-08-28 12:24:23</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>&lt;b&gt;Scott Gould&lt;/b&gt;: I think what Mike means is that Apple can (and does) add &lt;i&gt;private&lt;/i&gt; methods without using the underscore prefix. Thus they are still just as tricky to catch as ones with underscores.
&lt;br /&gt;
&lt;br /&gt;&lt;b&gt;Anyone:&lt;/b&gt; Related: I've always wondered if it would be fine to use two or maybe even three underscores as a method prefix rather than initials or something. Granted this would only work if by convention it was only used in application code and never framework code, so that nobody had the monopoly on multi-underscores thus disabling anyone else from using them when adding a framework to their app.
&lt;br /&gt;
&lt;br /&gt;&lt;b&gt;Dave DeLong&lt;/b&gt;: Oh that's even uglier (IMHO). It comes right before the argument! And what happens when your method has multiple arguments?
&lt;br /&gt;
&lt;br /&gt;&lt;b&gt;Karan&lt;/b&gt;: Do you mean checking if an ivar of the newly copied object is nil, or checking if the newly copied object itself is nil? If the latter, I agree that it would be safer to do that, but I can't think of a single time where -copyWithZone: has failed or would ever fail or was documented to fail, nor have I ever seen an implementation where it would fail and return nil. But yes, technically it should be safer.
&lt;br /&gt;
&lt;br /&gt;&lt;b&gt;Patrick Stein&lt;/b&gt;: As a style, I personally find that one too repetitive to use, because you return several times when you really only need to return twice (self at the end of the method, or nil after an error).
&lt;br /&gt;
&lt;br /&gt;But on the note of different coding styles for -init, if only you could use "return self" or "break" as the last clause of a for() loop, you could do something like this:
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;- (id) init {
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for (self = [super init]; self; break) {
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* ... */
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (something_goes_wrong) {
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[self release], self = nil;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;break;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/* ... */
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return self;
&lt;br /&gt;}&lt;/code&gt;</description><guid isPermaLink="true">0f7f5581ac0600a7558725368697375e</guid><pubDate>Sat, 28 Aug 2010 12:24:23 GMT</pubDate></item><item><title>Mike Shields - 2010-08-28 04:07:46</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>One other thing I'd add to this list is being dang sure that you think about implementing -(void)hash whenever you override -(BOOL)isEqual:. I've been bitten enough times when I implement the second without the first and then stuff an object into a container like NSSet, only to have things not work correctly. 
&lt;br /&gt;
&lt;br /&gt;In fact, I'd say that you should ALWAYS implement -hash, if only to make sure that you know you've thought of the implications.</description><guid isPermaLink="true">71ad45c06c16f039a065d19895bdcae3</guid><pubDate>Sat, 28 Aug 2010 04:07:46 GMT</pubDate></item><item><title>Karan - 2010-08-27 19:57:52</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>I would also recommend adding a nil check for the result from [super copyWithZone:...] since you're doing a C-style pointer dereference on the result and there's no guarantee the result won't be nil, thus causing a crash. </description><guid isPermaLink="true">59257270f4d13840ead73dd215630857</guid><pubDate>Fri, 27 Aug 2010 19:57:52 GMT</pubDate></item><item><title>Scott Gould - 2010-08-27 19:14:36</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;&lt;b&gt;mikeash:&lt;/b&gt; Using an underscore prefix is at the very least no more dangerous than not using a prefix at all.&lt;/div&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;I would think colliding with a public Apple method would be preferable to colliding with a private one.  In the case of colliding with an underscore prefix method, you're guaranteed to hit a private method which will be trickier to catch (I realize I might be missing something here).
&lt;br /&gt;
&lt;br /&gt;Suffixes would seem to solve this problem as Dave DeLong mentioned above.  Although using suffixes when a method takes an argument (or multiple arguments in particular) looks very ugly in Objective-C to my eyes.</description><guid isPermaLink="true">bd0a8b51bce608cb8fff3650a4e27d24</guid><pubDate>Fri, 27 Aug 2010 19:14:36 GMT</pubDate></item><item><title>mikeash - 2010-08-27 18:39:31</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>&lt;b&gt;Patrick Stein:&lt;/b&gt; Thanks for the note about the broken link, that was just a silly typo. Fixed now.
&lt;br /&gt;
&lt;br /&gt;&lt;b&gt;Rob Wills:&lt;/b&gt; I've always found that warning to be a bit strange. Using an underscore prefix is at the very least no more dangerous than not using a prefix at all. Apple can and does add un-prefixed methods to their classes, so unprefixed names can clash too. Adding an underscore at the very least does not &lt;i&gt;increase&lt;/i&gt; the probability of breaking something in the future.</description><guid isPermaLink="true">e3aef3e1036c9c396edc208415223f01</guid><pubDate>Fri, 27 Aug 2010 18:39:31 GMT</pubDate></item><item><title>Rob Wills - 2010-08-27 17:02:40</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>Another defensive tip for Cocoa is avoiding underscore prefixes.. Apple's documentation claims that it has reserved the use of the leading underscore:
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;Avoid the use of the underscore character as a prefix meaning private, especially in methods. Apple reserves the use of this convention. Use by third parties could result in name-space collisions; they might unwittingly override an existing private method with one of their own, with disastrous consequences.&lt;/div&gt;&lt;/div&gt;
&lt;br /&gt;(&lt;a href="http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.pdf"&gt;http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.pdf&lt;/a&gt; page 11)</description><guid isPermaLink="true">fc45aed73fc6a99632cc6de3fe0aaaca</guid><pubDate>Fri, 27 Aug 2010 17:02:40 GMT</pubDate></item><item><title>Patrick Stein - 2010-08-27 16:40:48</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>Two things: 
&lt;br /&gt;1st: 
&lt;br /&gt;
&lt;br /&gt;I use the 
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;- (id)init
&lt;br /&gt;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(! (self=[super init]) )
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return nil;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// put your code herebut remember
&lt;br /&gt;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if( somethingfails )
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[self release];
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return nil;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return self;
&lt;br /&gt;}
&lt;br /&gt;
&lt;br /&gt;this makes it easier to understand in my opinion as you don't have a mile long open/close bracket if your init routine is long. You don't have to keep in mind that open bracket the whole time.
&lt;br /&gt;
&lt;br /&gt;Furthermore remind people to use [self release] in the init method once they have self filled with something but can't initialize the object anyways.
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;2nd: the link to &lt;a href="http://www.mikeash.com/pyblog/the-how-and-why-of-cocoa-initializers.html"&gt;http://www.mikeash.com/pyblog/the-how-and-why-of-cocoa-initializers.html&lt;/a&gt; is broken as it contains a URI which is too long. </description><guid isPermaLink="true">d81fde0f784afe4383b617cfb16d5fe9</guid><pubDate>Fri, 27 Aug 2010 16:40:48 GMT</pubDate></item><item><title>Dave DeLong - 2010-08-27 16:20:19</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>Regarding category name collision:
&lt;br /&gt;
&lt;br /&gt;I personally prefer to use a method suffix instead of a method prefix.  That way I can still name the method something logical and find it in the autocompletion list, without having to remember that it's a category method.  So instead of doing:
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;- (void) dd_map:(id (^)(id obj))block;&lt;/code&gt;
&lt;br /&gt;
&lt;br /&gt;I do:
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;- (void) map_dd:(id(^)(id obj))block;&lt;/code&gt;</description><guid isPermaLink="true">56896d53a1bda745a0434f3b598d6147</guid><pubDate>Fri, 27 Aug 2010 16:20:19 GMT</pubDate></item><item><title>Scott Gould - 2010-08-27 16:20:15</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2010-08-27-defensive-programming-in-cocoa.html#comments</link><description>Thanks so much for the post!
&lt;br /&gt;
&lt;br /&gt;There is a lot of practical wisdom here.  I know the future me really appreciates all of the debugging time and anguish you have likely saved him.  Enjoy your time off.</description><guid isPermaLink="true">5c0e377cb1cf2d669d07d6b4428120d3</guid><pubDate>Fri, 27 Aug 2010 16:20:15 GMT</pubDate></item></channel></rss>
