Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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 [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #2
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    It really a matter of readability. It is more obvious what true and false means verses 1 and 0.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #6
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    mu?

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Last edited by brothercake; 03-27-2003 at 12:47 AM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #8
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    lol cool!

    ::] krycek [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Offtone.com - In the works...

  • #10
    Regular Coder
    Join Date
    Nov 2002
    Location
    Bristol, UK
    Posts
    932
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 [::
    ithium | SOAPI | SDP | PTPScript manual
    "ithium is a non-profit webhost, which is pretty much unique. The mission of ithium is to provide free hosting resources for worthwhile and needy non-profit projects, which otherwise may not be able to obtain such facilities. The money from commercial customers goes to maintain ithium's servers and further development."

  • #11
    Regular Coder
    Join Date
    Sep 2002
    Location
    British Columbia
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #12
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,073
    Thanks
    11
    Thanked 98 Times in 96 Posts
    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!)
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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