Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: True and false or 1 and 0?

1. ## True and false or 1 and 0?

When you are using two-state variables, is it better to actually make them proper booleans by using true and false, or to use 1 and 0?

Personally I kinda like to stick to true and false (well, that's boolean, so why not make the variable a boolean ) however I am sure that a while back I read a convincing argument for using 1 and 0 instead...

Anyone have any thoughts?

::] krycek [::

• never thought it really mattered concidering the 1s and 0s are basically the same as true and false...it might just be easier to use integers when the program is all done with integers, but I don't see why it really matters what you use. They are both going to be local and declared so there wouldn't be any referencing problems. So take your pick.

Jason

• It really a matter of readability. It is more obvious what true and false means verses 1 and 0.

• true, true, true (lol! )

I was actually talking more about the way they are handled etc. rather than ease of use and such... maybe it was speed? nope - can't see a difference - ways of checking them? hmmm, true is true and false is false... ah well, I wish I could find that article again!

::] krycek [::

• Shame there's not much scope for mu in boolean logic; I mean, you can go

\$mu = "mu";

... but it's hardly the same thing

• mu?

::] krycek [::

• Mu comes from Buddhism - it's neither true nor false, or rather, 'unask the question'. It's a question that can't be answered, like a paradox.

Check this out http://www.angelfire.com/electronic/bodhidharma/mu.html

• lol cool!

::] krycek [::

• I use true and false. if (\$var == 0) is harder than if (!\$var). Not that it's "hard" to type the extra bits, but it saves valuable milliseconds.

• Originally posted by SYP}{ER
I use true and false. if (\$var == 0) is harder than if (!\$var). Not that it's "hard" to type the extra bits, but it saves valuable milliseconds.
Hmmm, but, if \$var is 0, then you can say if(!\$var) just like if \$var was false. So basically there is no logic difference between the two, at least, not in that way... although, if \$var is 0, then of course checking if(\$var===false) is different.

::] krycek [::

• Some functions can return both a 0 value and a false value, and they mean different things. So you do need to discriminate between 0 and false in these cases.

• Originally posted by Dylan Leblanc
Some functions can return both a 0 value and a false value, and they mean different things. So you do need to discriminate between 0 and false in these cases.
exactly , if you mean true or false ? use true or false , it makes for easier reading later on as there is no ambiguity (I just know I spelt that wrong .. and if I didn't ,well it was by accident!)

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•