为什么Objective-C的使用YES / NO宏观约定,而不是真/假? [英] Why does Objective-C use YES/NO macro convention instead of true/false?

查看:440
本文介绍了为什么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.

这篇关于为什么Objective-C的使用YES / NO宏观约定,而不是真/假?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆