...

View Full Version : True and false or 1 and 0?



krycek
03-26-2003, 07:15 PM
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 [::

Jason
03-26-2003, 08:17 PM
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

Spookster
03-26-2003, 08:44 PM
It really a matter of readability. It is more obvious what true and false means verses 1 and 0.

krycek
03-26-2003, 08:58 PM
true, true, true (lol! :p)

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! :rolleyes:

::] krycek [::

brothercake
03-26-2003, 11:51 PM
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 :D

krycek
03-27-2003, 12:34 AM
mu? :confused:

::] krycek [::

brothercake
03-27-2003, 01:43 AM
:) 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

krycek
03-27-2003, 02:31 AM
lol :D cool! :p

::] krycek [::

SYP}{ER
03-27-2003, 03:36 AM
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.

krycek
03-27-2003, 03:48 AM
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 [::

Dylan Leblanc
03-27-2003, 08:01 AM
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.

firepages
03-27-2003, 05:50 PM
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!)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum