In Cocoa NSRange.h, I noticed the following built-in function:
NS_INLINE BOOL NSLocationInRange(NSUInteger loc, NSRange range) {
return (!(loc < range.location) && (loc - range.location) < range.length) ? YES : NO;
}
I found it rather puzzled that the author decided to return YES and NO through a conditional operator instead of writing a function such as:
NS_INLINE BOOL NSLocationInRange(NSUInteger loc, NSRange range) {
return (!(loc < range.location) && (loc - range.location) < range.length);
}
Is there a reason why the former is preferable? I usually find this to be just a freaky programming style, but I wondered (maybe wrongly) if something was missing from me, as it was in one of Apple.h's public files ...
source
share