Why does Objective-C use YES/NO macro convention instead of true/false?(为什么 Objective-C 使用 YES/NO 宏约定而不是 true/false?)
问题描述
大多数语言使用 true/false 关键字作为布尔值.我发现即使 Smalltalk 也在使用 true/false.我知道 Objective-C 只是借用 Smalltalk 的概念,而不是语言本身,但我很好奇它为什么使用 YES/NO 而不是更广泛使用的 true/false代码>.有什么历史原因吗?
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?
推荐答案
Objective-C 被设计为(并且仍然是)C 的严格超集.创建者非常努力地确保他们不会破坏与 C 的兼容性以任何方式.他们还试图让他们的修改更加明显,以便很容易分辨出代码的哪些部分使用了 Objective-C,哪些部分使用了普通 C.例如,用于表示 NSStrings 的 @而不仅仅是使用引号.这允许纯 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 宏是为了避免冲突,并明确代码实际上是 Objective-C.还要注意空"对象的 nil 用法,而不是仅仅修改旧 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 宏约定而不是 true/false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 Objective-C 使用 YES/NO 宏约定而不是 true/false?
基础教程推荐
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
