Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Objective-C use YES/NO macro convention instead of 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?

like image 462
eonil Avatar asked Jun 21 '11 06:06

eonil


2 Answers

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.

like image 188
Abhay Buch Avatar answered Oct 12 '22 09:10

Abhay Buch


Objective-C is a very verbose language, all methods are very descriptive, and using YES/NO for boolean values instead of true/false makes it more human readable.

You would probably find the following conversation strange, if it happened in real life: A: "Did you see the movie?" B: "True"

If B had answered "yes" (or "no"), it would sound perfectly normal, and code looks more like plain english by using YES/NO instead of true/false.

like image 31
Morten Fast Avatar answered Oct 12 '22 09:10

Morten Fast