Re:Developing on WP7 vs Android vs iPhone
by ryanpetrich on Friday December 31, 2010 @02:24AM
(#2054833)
The worst offender is the comparison methods:
NSString *myString = nil;
if ([myString compare:@"something"] == NSOrderedSame) {
...
}
The trick is to use null checks almost like you're writing C++, but drop them when they are unnecessary and inelegant. Convince yourself that a null check is unnecessary before removing it. This way you're reducing the chance of bugs and making them easier to pinpoint.
For example, you can do:
rather than On the other hand, you may be asking for trouble if you do without checking [someArray lastObject] for nil, since if someArray is empty, then nothing will dance and you won't know about it.tl;dr: Messaging nil is not idiot-proof but it makes code read better.