tags:

views:

992

answers:

7

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?

+29  A: 

Making it more readable is a technical reason.

Aaron Maenpaa
+1  A: 

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.

Brian Mitchell
+4  A: 

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.

thenduks
good explanation
SoloBold
you can still use true/false in objective-c
zPesk
@zPesk: Exactly. @SoloBold: Thanks :)
thenduks
A: 

It's the same as true/false..

Don't ask me why they reinvented the wheel and changed the names.

My pesonal guess is, that the language designer thought it would be cool to be different... (Yes, I know I will get downvotes from the fan-boys)..

Nils Pipenbrinck
I don't think they reinvented the wheel, but just add clarity.And it does, just that.
Rev316
It's not so much that they "reinvented" the wheel. They preceeded the implementation of booleans in C. Having nothing to copy, they implemented it as they chose.
Matt Gallagher
+7  A: 

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.

Mel
+5  A: 
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];

Rev316
+7  A: 

Because the programmer means yes and no, not 1 and 0.

Stephan Eggermont