为什么Objective-C的使用YES / NO宏观约定,而不是真/假?
大多数语言使用真/假
关键字布尔值。我发现,即使Smalltalk是使用真/假
。我知道的Objective-C只是借用概念从Smalltalk的,而不是语言本身,但我很好奇,为什么它的使用 YES / NO
而不是更广泛使用真/假
。是否有历史的原因?
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 borrowing concepts from Smalltalk, not the language itself, but I'm curious why it's using YES/NO
instead of the more widely-used true/false
. Is there any historical reason?
目标-C被设计成(现在仍然是)C的严格超创作者非常努力,以确保它们没有打破与C兼容性以任何方式。他们还试图让自己的修改,有些明显,这样它会很容易分辨哪个Objective-C中的code使用的零件和部件点使用纯C.个案中, @
用来表示NSString的,而不是仅仅使用引号。这让普通的C字符串与新的共存。
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处已经有TRUE / FALSE宏的非正式制度。我怀疑的Objective-C的设计师选择了YES / NO宏来避免冲突,并使其明显,code实际上是Objective-C的。还要注意使用无
为空对象,而不是修改好老NULL的行为。
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.