Why does Objective-C use YES/NO macro convention instead of true/false?

后端 未结 5 1276
礼貌的吻别
礼貌的吻别 2020-12-30 01:54

Most languages use the true/false keywords for boolean values. I found that even Smalltalk is using true/false. I know Objective-C is just borrow

5条回答
  •  误落风尘
    2020-12-30 02:15

    The best way to think of this is that it's parallel evolution.

    Objective-C's BOOL and YES/NO dates all the way back to early 1980s, and was likely intended to not only mimic other languages but miss C's future development. _Bool, true/false in C were only made part of the standard in 1999.

    So are YES and NO historical? Yes. Are they only historical? No. Just as NULL is not the result of 3-3 in a pure sense (despite NULL often being defined as 0, or casually usable if it were), true is not a value for BOOL.

    You would not (I think) write this code:

    int matches = NULL;
    for (int i = 0; i

    This is less obviously wrong, but it's on the same spectrum:

    BOOL foundMatch = false;
    for (int i = 0; i

提交回复
热议问题