Announcement

Collapse
No announcement yet.

Grrrrrr :-( Does this bother anyone else?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Grrrrrr :-( Does this bother anyone else?

    programmers

    why can't -even just for windows programming- we agree on true and false? can some explain it too me please.

    like in clay clear's (not attacking you) recent post to the source forum http://www.powerbasic.com/support/pb...ad.php?t=24007
    "will return true (-1) if:..."

    i hear lots of "true is -1" or "true is non zero"

    win32api.inc has these defined.

    %true = 1
    %false = 0

    doesn't this inconvenince people? why not just pass around defined equates? why have a function return "-1" ??

    please explain

    thanks

    ------------------
    paul dwyer
    network engineer
    aussie in tokyo

  • #2
    Paul,

    Try this:

    True& = NOT True&
    PRINT True& ' -1
    True& = NOT True&
    PRINT True& ' 0

    this is the reason why I like using True& = -1 myself
    because it works well with the NOT operator
    then I don't need the overhead of functions like ISTRUE/ISFALSE.

    %TRUE = 1 is the C definition,
    %TRUE = -1 has always been the "TRUE" BASIC definition.

    That's my point


    ------------------
    Patrice Terrier
    mailto[email protected][email protected]</A>
    http://www.zapsolution.com
    Toolkit: WinLIFT (Skin Engine), GDI+ helper (Graphic package), dvBTree (Index manager)
    Freeware: ZAP Audio Player, ZAP Picture Browser.
    Artwork on demand.
    Patrice Terrier
    www.zapsolution.com
    www.objreader.com
    Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

    Comment


    • #3
      hmmmmm.

      Any annoying situation though having two types. Generally I don't like to think about the actual values of true and false but just use them. Problem is that if I use:

      If MyFunc() = %true then

      I may never execute the code if it's someone elses as they are passing me a -1.

      In the case of Clay's code I'm glad he qualified what he meant by True as often people don't.

      I'm a big fan of standards thats all... don't get me started about DVD+R and DVD-R

      ------------------
      Paul Dwyer
      Network Engineer
      Aussie in Tokyo

      [This message has been edited by Paul Dwyer (edited September 26, 2003).]

      Comment


      • #4

        hehehe

        I remember in the days of Qbasic...


        CONST TRUE = -1
        CONST FALSE = NOT TRUE




        ------------------
        Learning is not the capacity to retain information, It is the capacity to compare old information with new information... And make new Knowledge.

        Comment


        • #5
          Well,

          This works with the %true/%false I use, so I suppose I'm happy....

          Code:
          #Compile Exe
           
          #Include "win32api.inc" 
          
          Function PbMain() As Long
              
              Dim T As Long
              Dim F As Long
              
              T = %true
              F = %false
              
              If IsTrue(T) Then
                  MsgBox "T is True"
              Else
                  MsgBox "T is Not True"
              End If
              
              If IsFalse(F) Then
                  MsgBox "F is False"
              Else
                  MsgBox "F is Not False"
              End If
              
          End Function
          ------------------
          Paul Dwyer
          Network Engineer
          Aussie in Tokyo

          Comment


          • #6
            I got used to doing "IF ISTRUE ...", and "IF ISFALSE ...", instead of
            "IF x = %true" etc. ISTRUE and ISFALSE may have been invented to avoid
            confusion with NOT in IF statements, they also make this discussion
            redundant.

            FALSE = zero; TRUE = anything else, set it to what you like, doesn't
            matter. And of course, NOT FALSE = -1& and NOT FALSE = 4,294,967,295???


            Cheers guys,


            ------------------
            Dale
            mailto:[email protected][email protected]</A>
            Dale

            Comment


            • #7
              I remember reading that FALSE is defined as 0 and TRUE as NOT FALSE. So it really doesn't matter if TRUE = 1 or TRUE = -1. Both is NOT FALSE.

              At least PB's IsTrue() and IsFalse() work that way.

              Knuth

              ------------------
              http://www.softAware.de

              Comment


              • #8
                Exactly,

                FALSE = 0
                TRUE = everything else = NOT FALSE

                I actually like this cos I use

                IF SomeFlag then


                I can then use 1 for sub condition 1, 2 for sub condition 2 etc
                or 1 and -1 for long and short ie

                If TradeFlag Then ' in a trade
                If TradeFlag < 0 Then ' Short Processing

                If TradeFlag > 0 Then ' Long Processing


                ------------------
                Kind Regards
                Mike

                Comment


                • #9
                  I never make use of these constants.
                  I just use 0 and 1 since a 'boolean' this way can be upgraded to a number later like:
                  0,1,2 etc..


                  ------------------
                  http://www.hellobasic.com
                  hellobasic

                  Comment


                  • #10
                    I too have a strong preference for %FALSE = 0 and %TRUE = -1 because those values work so well with the logical operators. For example using -1 allows me to use NOT in a logical way, as in...
                    Code:
                    IF NOT lUserAbort THEN...
                    But complete standardization is impossible because not all data types can hold negative numbers. WORDs, DWORDs, BYTEs, etc. can't store negative one.

                    The problem is further complicated by the fact that if you set all of the bits of a BYTE you get 255, if you set all of the bits of a WORD you get 64k, and so on. So "all bits on" doesn't work as a standard either. Every data type would have a different value for True. Not good.

                    So Microsoft settled on positive one, which all data types can store. It's really the only value that makes sense as a "universal true". The %TRUE equate in W=in32API.INC is a Microsoft value, not a PowerBASIC-defined value. When Win32.HLP and MSDN say "True" they almost always mean positive one.

                    If you want to use signed integers such as LONGs for your logical values, then you are free to re-define %TRUE as negative one, as I do. I change Win32API.INC to...
                    Code:
                    %FALSE    = 0
                    %TRUE     = -1
                    %API_TRUE = +1
                    In the end, I hardly ever use %API_TRUE for anything.

                    -- Eric

                    ------------------
                    Perfect Sync Development Tools
                    Perfect Sync Web Site
                    Contact Us: mailto:[email protected]om[email protected]</A>



                    [This message has been edited by Eric Pearson (edited September 26, 2003).]
                    "Not my circus, not my monkeys."

                    Comment


                    • #11
                      False = Zero
                      True = non-Zero

                      ------------------

                      Comment


                      • #12
                        It actually has to do with the BINARY values given. A logical NOT looks for
                        the OPOSITE value. 1 is stored as "0000000000000001" whereas -1 is stored as
                        "1111111111111111" So NOT -1 would translate to "0000000000000000", and NOT 1
                        would translate to "1111111111111110" which is still a "non-zero" value (-2).



                        ------------------
                        Scott Slater
                        Summit Computer Networks, Inc.
                        www.summitcn.com
                        Scott Slater
                        Summit Computer Networks, Inc.
                        www.summitcn.com

                        Comment


                        • #13
                          Ever since Commodor days I've NEVER trusted Ture!
                          False is ZERO, always, no exceptions!

                          True, therefore is NOT ZERO. eg:

                          IF Whatever <> 0 THEN
                          PRINT "This is ALWAYS a good test for NOT ZERO!"
                          END IF



                          ------------------
                          C'ya
                          Don
                          [email protected]
                          C'ya
                          Don

                          http://www.ImagesBy.me

                          Comment


                          • #14
                            For those of you who are from a VB background you will recall one more little annoyance though,

                            Many functions in the language returned -1 as an error. So if you had this as TRUE you would run into problems

                            This was sometimes sensible too as you could do what Mike was mentioning

                            If MyFunt() then

                            but if -1 is true .....

                            As the topic states, this bothers me somewhat, especially when having to support other people's code

                            ------------------
                            Paul Dwyer
                            Network Engineer
                            Aussie in Tokyo

                            Comment


                            • #15
                              PB should have a proper intrinsic BOOLEAN type (is it already on the wish list?). This would avoid having to use an integer type, with all the consequent confusion and scope for error. Mind you, I can see that this would be a bit difficult to add now without introducing backward compatibility problems.

                              Keith


                              ------------------

                              Comment


                              • #16
                                Yeah, what he said ...

                                ------------------
                                Kind Regards
                                Mike

                                Comment


                                • #17
                                  Paul Dwyer wrote: Why can't we agree on TRUE and FALSE?

                                  I just say, "@#$% 'em both!"

                                  I use 0 and 1. That way I know what the @#$% I have.
                                  Who wants to type that %TRUE and %FALSE junk anyway.

                                  (I admit there are uses for them, but most of the time
                                  I don't need it.)


                                  ------------------
                                  Gary Peek, Industrologic, Inc.

                                  Comment


                                  • #18
                                    Why can't we agree on TRUE and FALSE?
                                    Better idea: Why can't we just faggedaboudit?

                                    When in Rome....use ISTRUE and ISFALSE.

                                    MCM
                                    Michael Mattias
                                    Tal Systems (retired)
                                    Port Washington WI USA
                                    [email protected]
                                    http://www.talsystems.com

                                    Comment

                                    Working...
                                    X