Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Not null check

Not null check

Scheduled Pinned Locked Moved The Weird and The Wonderful
announcement
11 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Ciumac Sergiu
    wrote on last edited by
    #1

    How about this piece of code: if (a == null == false) { } Spent some time before figuring out it is a version of if (а != null) {}

    L F C 3 Replies Last reply
    0
    • C Ciumac Sergiu

      How about this piece of code: if (a == null == false) { } Spent some time before figuring out it is a version of if (а != null) {}

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      when in doubt, you can look it up and then clarify by adding parentheses, like so:

      if ( ( (a==null) == false ) == true ) {...}

      :)

      Luc Pattyn [Forum Guidelines] [My Articles] [My CP bug tracking] Nil Volentibus Arduum

      Season's Greetings to all CPians.

      K H K 3 Replies Last reply
      0
      • C Ciumac Sergiu

        How about this piece of code: if (a == null == false) { } Spent some time before figuring out it is a version of if (а != null) {}

        F Offline
        F Offline
        fjdiewornncalwe
        wrote on last edited by
        #3

        A a clear and sustainable piece of code, this is truly a horror and definitely deserves its place in the Hall of Shame.

        I wasn't, now I am, then I won't be anymore.

        1 Reply Last reply
        0
        • L Luc Pattyn

          when in doubt, you can look it up and then clarify by adding parentheses, like so:

          if ( ( (a==null) == false ) == true ) {...}

          :)

          Luc Pattyn [Forum Guidelines] [My Articles] [My CP bug tracking] Nil Volentibus Arduum

          Season's Greetings to all CPians.

          K Offline
          K Offline
          Kevin Drzycimski
          wrote on last edited by
          #4

          Luc Pattyn wrote:

          if ( ( (a==null) == false ) == true ) {...}

          can you extend this recursively? only to be very very sure:

          if ( ( ( ( ( (a==null) == false) == true) == true) == true) == true)

          to shock afterworkers and make compiler happy, one could sometimes say == true and == false :laugh:

          1 Reply Last reply
          0
          • C Ciumac Sergiu

            How about this piece of code: if (a == null == false) { } Spent some time before figuring out it is a version of if (а != null) {}

            C Offline
            C Offline
            Ciumac Sergiu
            wrote on last edited by
            #5

            Related to the above: flag = bool(int(flag) - 1);

            G 1 Reply Last reply
            0
            • C Ciumac Sergiu

              Related to the above: flag = bool(int(flag) - 1);

              G Offline
              G Offline
              GibbleCH
              wrote on last edited by
              #6

              I presume this toggles the flag? And that in this language false is zero and anything else is considered true

              1 Reply Last reply
              0
              • L Luc Pattyn

                when in doubt, you can look it up and then clarify by adding parentheses, like so:

                if ( ( (a==null) == false ) == true ) {...}

                :)

                Luc Pattyn [Forum Guidelines] [My Articles] [My CP bug tracking] Nil Volentibus Arduum

                Season's Greetings to all CPians.

                H Offline
                H Offline
                HimanshuJoshi
                wrote on last edited by
                #7

                Just to make it more subtle add a little "!" at the beginning

                if ( !( ( ( (a==null) == false ) == true ) == false)) {...}

                :suss:

                C 1 Reply Last reply
                0
                • H HimanshuJoshi

                  Just to make it more subtle add a little "!" at the beginning

                  if ( !( ( ( (a==null) == false ) == true ) == false)) {...}

                  :suss:

                  C Offline
                  C Offline
                  Ciumac Sergiu
                  wrote on last edited by
                  #8

                  This one would be even more subtle :cool:

                  if ( !( !( !( !(a==null) == true ) == false ) == true)) {...}

                  P 1 Reply Last reply
                  0
                  • C Ciumac Sergiu

                    This one would be even more subtle :cool:

                    if ( !( !( !( !(a==null) == true ) == false ) == true)) {...}

                    P Offline
                    P Offline
                    Paladin2000
                    wrote on last edited by
                    #9

                    How about this one? :-D

                    if ( true == (!((!(((a ?? true) is bool) ? true : false) == false) == true) == false)) {...}

                    L 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      when in doubt, you can look it up and then clarify by adding parentheses, like so:

                      if ( ( (a==null) == false ) == true ) {...}

                      :)

                      Luc Pattyn [Forum Guidelines] [My Articles] [My CP bug tracking] Nil Volentibus Arduum

                      Season's Greetings to all CPians.

                      K Offline
                      K Offline
                      Keith Barrow
                      wrote on last edited by
                      #10

                      I used to work at Accenture, they used to make us bracket like that to "Disambiguate" the otherwise very clear logic X|

                      Sort of a cross between Lawrence of Arabia and Dilbert.[^]
                      -Or-
                      A Dead ringer for Kate Winslett[^]

                      1 Reply Last reply
                      0
                      • P Paladin2000

                        How about this one? :-D

                        if ( true == (!((!(((a ?? true) is bool) ? true : false) == false) == true) == false)) {...}

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        How about overloading those operators? Also, you might want to use the monad- or the decorator pattern to split that up into multiple lines :)

                        I are Troll :suss:

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups