Is there any technical reason why Objective-C uses YES and NO instead of 1 and 0, or is it simply to make it more readable?
6 Answers
typedef signed char BOOL;
// BOOL is explicitly signed so @encode(BOOL) == "c" rather than "C"
// even if -funsigned-char is used.
#define OBJC_BOOL_DEFINED
#define YES (BOOL)1
#define NO (BOOL)0
(For reference)
[button setAttr:YES];
Sounds nicer IMHO then...
[button setAttr:TRUE];
C (on which Objective-C is based) didn't have a boolean type until C99.
Objective-C was created in the 80s and defined it's own boolean type.
-
14
The same reason most languages use true
and false
... You can use 1 and 0 if you like, same as any of those other languages.
Really, if you think about it, we're talking about:
#define YES 1
#define NO 0
It's simply nicer to read.
-
1
-
1Am I the ONLY one that constantly gets tripped up by this... I grew up in the
bash
shell.. where0
... "means good", aka YES!... á laexit 0
... Every time I use aC
boolean
I have to force my mind to accept this paradoxical reality! Oct 1, 2013 at 12:19 -
@alexgray I am a "Bash"-ist too. A way to remember is: "It is true that bash shell executed correctly when there is 0 error (ie 0 == true in Bash) and while everything else think there is 1 error (ie 1 == true in non Bash language)" Sep 3, 2015 at 7:40
It's just syntax, there's no technical reason for it. They just use YES/NO for their BOOL instead of true/false like c++ does.
-
1