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

后端 未结 5 1277
礼貌的吻别
礼貌的吻别 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:32

    Objective-C was designed to be (and still is) a strict superset of C. The creators worked very hard to ensure that they did not break compatibility with C in any way. They also tried to make their modifications somewhat obvious so that it would be easy to tell which parts of the code use Objective-C and which parts use plain C. Case in point, the @ used to denote NSStrings rather than just using quotes. This allows plain C strings to coexist with the new ones.

    C already had an informal system of TRUE/FALSE macros. I suspect the designers of Objective-C chose the YES/NO macros to avoid conflict and to make it obvious that the code is actually Objective-C. Notice also the usage nil for the 'empty' object rather than just modifying the behavior of good old NULL.

提交回复
热议问题