Why generate YES and NO through a conditional statement or directly use a condition?

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 ...

+4
source share
1 answer

This is just a bad programming style / understanding. Do not do that.

, ( ), .

. / (Objective-) C (++) , , . 0 1 false/NO true/YES .

+4

Source: https://habr.com/ru/post/1524440/


All Articles