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. What condition, or lack thereof, am I even testing for again???

What condition, or lack thereof, am I even testing for again???

Scheduled Pinned Locked Moved The Weird and The Wonderful
testingbeta-testingregexquestion
3 Posts 3 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.
  • N Offline
    N Offline
    nedmech
    wrote on last edited by
    #1

    Condensed and renamed to protect the guilty...

    Public Sub TestThis(bFlag as Boolean, objVar as Object)

    If (Not bFlag) And (bFlag <> Not CBool(objVar Is Nothing)) Then
         'do some stuff
    End If
    

    End Sub

    I know the CBool is completely unneeded. But I'm having a heck of a time understanding what this little snippet was supposed to be testing for, or how it even came into existence in the first place. It seems like it would be cleaner to just test:

    (Not bFlag) And Not (objVar Is Nothing)
    

    There are actually several other instances of this kind of test that I think are just there for a confusion factor. They all follow the same basic pattern of:

    (Not boolean1) And (boolean1 <> boolean\_test\_condition)
    

    In order for the whole test to be True, the first Boolean must be False, so boolean test condition on the right side MUST be True. Why even bother comparing the test condition result against the first value?

    (Not boolean1) And boolean\_test\_condition
    

    I'm so ripping my hair out every time I have to dive into legacy code like this. Good thing it's Friday!

    B B 2 Replies Last reply
    0
    • N nedmech

      Condensed and renamed to protect the guilty...

      Public Sub TestThis(bFlag as Boolean, objVar as Object)

      If (Not bFlag) And (bFlag <> Not CBool(objVar Is Nothing)) Then
           'do some stuff
      End If
      

      End Sub

      I know the CBool is completely unneeded. But I'm having a heck of a time understanding what this little snippet was supposed to be testing for, or how it even came into existence in the first place. It seems like it would be cleaner to just test:

      (Not bFlag) And Not (objVar Is Nothing)
      

      There are actually several other instances of this kind of test that I think are just there for a confusion factor. They all follow the same basic pattern of:

      (Not boolean1) And (boolean1 <> boolean\_test\_condition)
      

      In order for the whole test to be True, the first Boolean must be False, so boolean test condition on the right side MUST be True. Why even bother comparing the test condition result against the first value?

      (Not boolean1) And boolean\_test\_condition
      

      I'm so ripping my hair out every time I have to dive into legacy code like this. Good thing it's Friday!

      B Offline
      B Offline
      Brisingr Aerowing
      wrote on last edited by
      #2

      :doh: X|

      public void WriteCode(ICodeContext ctx)
      {
      throw new BrainNotFoundException();
      }

      Bill Gates is a very rich man today... and do you want to know why? The answer is one word: versions. Dave Barry Read more at [BrainyQuote](http://www.brainyquote.com/quotes/topics topic_technology.html#yAfSEbrfumitrteO.99)[^]

      1 Reply Last reply
      0
      • N nedmech

        Condensed and renamed to protect the guilty...

        Public Sub TestThis(bFlag as Boolean, objVar as Object)

        If (Not bFlag) And (bFlag <> Not CBool(objVar Is Nothing)) Then
             'do some stuff
        End If
        

        End Sub

        I know the CBool is completely unneeded. But I'm having a heck of a time understanding what this little snippet was supposed to be testing for, or how it even came into existence in the first place. It seems like it would be cleaner to just test:

        (Not bFlag) And Not (objVar Is Nothing)
        

        There are actually several other instances of this kind of test that I think are just there for a confusion factor. They all follow the same basic pattern of:

        (Not boolean1) And (boolean1 <> boolean\_test\_condition)
        

        In order for the whole test to be True, the first Boolean must be False, so boolean test condition on the right side MUST be True. Why even bother comparing the test condition result against the first value?

        (Not boolean1) And boolean\_test\_condition
        

        I'm so ripping my hair out every time I have to dive into legacy code like this. Good thing it's Friday!

        B Offline
        B Offline
        Bernhard Hiller
        wrote on last edited by
        #3

        That's called obfuscation. Theoretically, it could be intended (protection against reverse engineering, or just abuse of the colleagues who have to maintain that code). But more often, it happens due to other factors. E.g. the law of thermodynamics: things get worse under pressure. Or medical conditions like hypocaffeinemia.

        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