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. Code that makes you go "hmmmm"

Code that makes you go "hmmmm"

Scheduled Pinned Locked Moved The Weird and The Wonderful
testingbeta-testingquestion
12 Posts 12 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.
  • I Offline
    I Offline
    icemanind
    wrote on last edited by
    #1

    Where I am working, there USED to be a guy here who had written the following piece of code (swear to God this is a true function):

    Private Function CaseInsensiveCompare(ByVal str1 As String, ByVal str2 As String) As Boolean
    Dim Apples As String = str1.ToUpper()
    Dim Oranges As String = str2.ToUpper()
    Dim AreTheyEqual As Boolean = str1.Equals(str2)
    Dim NotEqual As Boolean = Not AreTheyEqual

        If AreTheyEqual = True Then
            Return AreTheyEqual <> NotEqual
        Else
            Return AreTheyEqual = NotEqual
        End If
    
        Return (Not (AreTheyEqual)) = NotEqual Or AreTheyEqual
    End Function
    

    What boogles me is: 1. Why write a function for this? Just use If str1.ToUpper()=str2.ToUpper() Then ... 2. Why in the hell use this NOT logic stuff? 3. Is that final Return ever even hit in any scenario? My best guess as to why he would have done this is maybe he was testing something and was commenting/decommenting a line in there.

    R P C 0 T 10 Replies Last reply
    0
    • I icemanind

      Where I am working, there USED to be a guy here who had written the following piece of code (swear to God this is a true function):

      Private Function CaseInsensiveCompare(ByVal str1 As String, ByVal str2 As String) As Boolean
      Dim Apples As String = str1.ToUpper()
      Dim Oranges As String = str2.ToUpper()
      Dim AreTheyEqual As Boolean = str1.Equals(str2)
      Dim NotEqual As Boolean = Not AreTheyEqual

          If AreTheyEqual = True Then
              Return AreTheyEqual <> NotEqual
          Else
              Return AreTheyEqual = NotEqual
          End If
      
          Return (Not (AreTheyEqual)) = NotEqual Or AreTheyEqual
      End Function
      

      What boogles me is: 1. Why write a function for this? Just use If str1.ToUpper()=str2.ToUpper() Then ... 2. Why in the hell use this NOT logic stuff? 3. Is that final Return ever even hit in any scenario? My best guess as to why he would have done this is maybe he was testing something and was commenting/decommenting a line in there.

      R Offline
      R Offline
      Rob Smiley
      wrote on last edited by
      #2

      This is a true horror & unfortunately I've seen my fair share of this 'style' of coding, usually from ex VB6 programmers... get over it & learn your way around the .net framework is what I say! What's the deal with Apples & Oranges? they're not even used?? Are there other fruit themed vegetables variables in the project?!

      "An eye for an eye only ends up making the whole world blind"

      1 Reply Last reply
      0
      • I icemanind

        Where I am working, there USED to be a guy here who had written the following piece of code (swear to God this is a true function):

        Private Function CaseInsensiveCompare(ByVal str1 As String, ByVal str2 As String) As Boolean
        Dim Apples As String = str1.ToUpper()
        Dim Oranges As String = str2.ToUpper()
        Dim AreTheyEqual As Boolean = str1.Equals(str2)
        Dim NotEqual As Boolean = Not AreTheyEqual

            If AreTheyEqual = True Then
                Return AreTheyEqual <> NotEqual
            Else
                Return AreTheyEqual = NotEqual
            End If
        
            Return (Not (AreTheyEqual)) = NotEqual Or AreTheyEqual
        End Function
        

        What boogles me is: 1. Why write a function for this? Just use If str1.ToUpper()=str2.ToUpper() Then ... 2. Why in the hell use this NOT logic stuff? 3. Is that final Return ever even hit in any scenario? My best guess as to why he would have done this is maybe he was testing something and was commenting/decommenting a line in there.

        P Offline
        P Offline
        Paul Conrad
        wrote on last edited by
        #3

        Yes, a horror indeed. Perhaps he wrote the code on April Fools Day :)

        "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

        1 Reply Last reply
        0
        • I icemanind

          Where I am working, there USED to be a guy here who had written the following piece of code (swear to God this is a true function):

          Private Function CaseInsensiveCompare(ByVal str1 As String, ByVal str2 As String) As Boolean
          Dim Apples As String = str1.ToUpper()
          Dim Oranges As String = str2.ToUpper()
          Dim AreTheyEqual As Boolean = str1.Equals(str2)
          Dim NotEqual As Boolean = Not AreTheyEqual

              If AreTheyEqual = True Then
                  Return AreTheyEqual <> NotEqual
              Else
                  Return AreTheyEqual = NotEqual
              End If
          
              Return (Not (AreTheyEqual)) = NotEqual Or AreTheyEqual
          End Function
          

          What boogles me is: 1. Why write a function for this? Just use If str1.ToUpper()=str2.ToUpper() Then ... 2. Why in the hell use this NOT logic stuff? 3. Is that final Return ever even hit in any scenario? My best guess as to why he would have done this is maybe he was testing something and was commenting/decommenting a line in there.

          C Offline
          C Offline
          Chris Meech
          wrote on last edited by
          #4

          :omg: The programmer is trying to compare Apples to Oranges. That function will always return false. ;)

          Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]

          K 1 Reply Last reply
          0
          • I icemanind

            Where I am working, there USED to be a guy here who had written the following piece of code (swear to God this is a true function):

            Private Function CaseInsensiveCompare(ByVal str1 As String, ByVal str2 As String) As Boolean
            Dim Apples As String = str1.ToUpper()
            Dim Oranges As String = str2.ToUpper()
            Dim AreTheyEqual As Boolean = str1.Equals(str2)
            Dim NotEqual As Boolean = Not AreTheyEqual

                If AreTheyEqual = True Then
                    Return AreTheyEqual <> NotEqual
                Else
                    Return AreTheyEqual = NotEqual
                End If
            
                Return (Not (AreTheyEqual)) = NotEqual Or AreTheyEqual
            End Function
            

            What boogles me is: 1. Why write a function for this? Just use If str1.ToUpper()=str2.ToUpper() Then ... 2. Why in the hell use this NOT logic stuff? 3. Is that final Return ever even hit in any scenario? My best guess as to why he would have done this is maybe he was testing something and was commenting/decommenting a line in there.

            0 Offline
            0 Offline
            0x3c0
            wrote on last edited by
            #5

            It gets worse. He's getting the upper case values, then comparing the original values

            1 Reply Last reply
            0
            • I icemanind

              Where I am working, there USED to be a guy here who had written the following piece of code (swear to God this is a true function):

              Private Function CaseInsensiveCompare(ByVal str1 As String, ByVal str2 As String) As Boolean
              Dim Apples As String = str1.ToUpper()
              Dim Oranges As String = str2.ToUpper()
              Dim AreTheyEqual As Boolean = str1.Equals(str2)
              Dim NotEqual As Boolean = Not AreTheyEqual

                  If AreTheyEqual = True Then
                      Return AreTheyEqual <> NotEqual
                  Else
                      Return AreTheyEqual = NotEqual
                  End If
              
                  Return (Not (AreTheyEqual)) = NotEqual Or AreTheyEqual
              End Function
              

              What boogles me is: 1. Why write a function for this? Just use If str1.ToUpper()=str2.ToUpper() Then ... 2. Why in the hell use this NOT logic stuff? 3. Is that final Return ever even hit in any scenario? My best guess as to why he would have done this is maybe he was testing something and was commenting/decommenting a line in there.

              T Offline
              T Offline
              tommyligo
              wrote on last edited by
              #6

              Hi I like this code... :laugh: ... oranges and apples are very coloured variable, and in particular i like the IF clause that is very clear. I think that if this man have to compare two INT, he write a if (isLess and not isMoreThan1 or not (isDivisibleBy3 and isSQRTof45)) then return isNotMajor and (not isMonday or isFriday) endif return true ;P Tommy

              1 Reply Last reply
              0
              • I icemanind

                Where I am working, there USED to be a guy here who had written the following piece of code (swear to God this is a true function):

                Private Function CaseInsensiveCompare(ByVal str1 As String, ByVal str2 As String) As Boolean
                Dim Apples As String = str1.ToUpper()
                Dim Oranges As String = str2.ToUpper()
                Dim AreTheyEqual As Boolean = str1.Equals(str2)
                Dim NotEqual As Boolean = Not AreTheyEqual

                    If AreTheyEqual = True Then
                        Return AreTheyEqual <> NotEqual
                    Else
                        Return AreTheyEqual = NotEqual
                    End If
                
                    Return (Not (AreTheyEqual)) = NotEqual Or AreTheyEqual
                End Function
                

                What boogles me is: 1. Why write a function for this? Just use If str1.ToUpper()=str2.ToUpper() Then ... 2. Why in the hell use this NOT logic stuff? 3. Is that final Return ever even hit in any scenario? My best guess as to why he would have done this is maybe he was testing something and was commenting/decommenting a line in there.

                B Offline
                B Offline
                BillW33
                wrote on last edited by
                #7

                This code is poorly organized with terrible variable names and it is very inefficient. But, the worst thing is that it not only doesn't work, it is hard to believe that even a beginning programmer would think it would work. I would hope that this function was written as a joke and was never called by the rest of the program. Bill W

                Just because code works, it doesn't mean that it is good code.

                1 Reply Last reply
                0
                • I icemanind

                  Where I am working, there USED to be a guy here who had written the following piece of code (swear to God this is a true function):

                  Private Function CaseInsensiveCompare(ByVal str1 As String, ByVal str2 As String) As Boolean
                  Dim Apples As String = str1.ToUpper()
                  Dim Oranges As String = str2.ToUpper()
                  Dim AreTheyEqual As Boolean = str1.Equals(str2)
                  Dim NotEqual As Boolean = Not AreTheyEqual

                      If AreTheyEqual = True Then
                          Return AreTheyEqual <> NotEqual
                      Else
                          Return AreTheyEqual = NotEqual
                      End If
                  
                      Return (Not (AreTheyEqual)) = NotEqual Or AreTheyEqual
                  End Function
                  

                  What boogles me is: 1. Why write a function for this? Just use If str1.ToUpper()=str2.ToUpper() Then ... 2. Why in the hell use this NOT logic stuff? 3. Is that final Return ever even hit in any scenario? My best guess as to why he would have done this is maybe he was testing something and was commenting/decommenting a line in there.

                  T Offline
                  T Offline
                  Thomas Weller 0
                  wrote on last edited by
                  #8

                  From time to time there are sort of surreal moments in life. Moments where one simply thinks This can't just be true. This is not really happening. I had such a moment when I saw this 'code'. Regards Thomas

                  1 Reply Last reply
                  0
                  • I icemanind

                    Where I am working, there USED to be a guy here who had written the following piece of code (swear to God this is a true function):

                    Private Function CaseInsensiveCompare(ByVal str1 As String, ByVal str2 As String) As Boolean
                    Dim Apples As String = str1.ToUpper()
                    Dim Oranges As String = str2.ToUpper()
                    Dim AreTheyEqual As Boolean = str1.Equals(str2)
                    Dim NotEqual As Boolean = Not AreTheyEqual

                        If AreTheyEqual = True Then
                            Return AreTheyEqual <> NotEqual
                        Else
                            Return AreTheyEqual = NotEqual
                        End If
                    
                        Return (Not (AreTheyEqual)) = NotEqual Or AreTheyEqual
                    End Function
                    

                    What boogles me is: 1. Why write a function for this? Just use If str1.ToUpper()=str2.ToUpper() Then ... 2. Why in the hell use this NOT logic stuff? 3. Is that final Return ever even hit in any scenario? My best guess as to why he would have done this is maybe he was testing something and was commenting/decommenting a line in there.

                    D Offline
                    D Offline
                    dighn
                    wrote on last edited by
                    #9

                    I think it's just meant to be humorous. It's deliberately made ridiculous. Too bad it has a real error though as already pointed out.

                    1 Reply Last reply
                    0
                    • C Chris Meech

                      :omg: The programmer is trying to compare Apples to Oranges. That function will always return false. ;)

                      Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]

                      K Offline
                      K Offline
                      KarstenK
                      wrote on last edited by
                      #10

                      Youre completly wrong: the code will work. But not always return the truth. CaseInsensiveCompare( "apple", "apple" ) -> true: OK CaseInsensiveCompare( "apple", "orange" ) -> false: OK CaseInsensiveCompare( "Apple", "apple" ) -> false: BUG really SCNR :-O

                      Greetings from Germany

                      1 Reply Last reply
                      0
                      • I icemanind

                        Where I am working, there USED to be a guy here who had written the following piece of code (swear to God this is a true function):

                        Private Function CaseInsensiveCompare(ByVal str1 As String, ByVal str2 As String) As Boolean
                        Dim Apples As String = str1.ToUpper()
                        Dim Oranges As String = str2.ToUpper()
                        Dim AreTheyEqual As Boolean = str1.Equals(str2)
                        Dim NotEqual As Boolean = Not AreTheyEqual

                            If AreTheyEqual = True Then
                                Return AreTheyEqual <> NotEqual
                            Else
                                Return AreTheyEqual = NotEqual
                            End If
                        
                            Return (Not (AreTheyEqual)) = NotEqual Or AreTheyEqual
                        End Function
                        

                        What boogles me is: 1. Why write a function for this? Just use If str1.ToUpper()=str2.ToUpper() Then ... 2. Why in the hell use this NOT logic stuff? 3. Is that final Return ever even hit in any scenario? My best guess as to why he would have done this is maybe he was testing something and was commenting/decommenting a line in there.

                        K Offline
                        K Offline
                        Kevin McFarlane
                        wrote on last edited by
                        #11

                        Ooh, that gave me headache before I even got to the end of the declarations! :~

                        Kevin

                        1 Reply Last reply
                        0
                        • I icemanind

                          Where I am working, there USED to be a guy here who had written the following piece of code (swear to God this is a true function):

                          Private Function CaseInsensiveCompare(ByVal str1 As String, ByVal str2 As String) As Boolean
                          Dim Apples As String = str1.ToUpper()
                          Dim Oranges As String = str2.ToUpper()
                          Dim AreTheyEqual As Boolean = str1.Equals(str2)
                          Dim NotEqual As Boolean = Not AreTheyEqual

                              If AreTheyEqual = True Then
                                  Return AreTheyEqual <> NotEqual
                              Else
                                  Return AreTheyEqual = NotEqual
                              End If
                          
                              Return (Not (AreTheyEqual)) = NotEqual Or AreTheyEqual
                          End Function
                          

                          What boogles me is: 1. Why write a function for this? Just use If str1.ToUpper()=str2.ToUpper() Then ... 2. Why in the hell use this NOT logic stuff? 3. Is that final Return ever even hit in any scenario? My best guess as to why he would have done this is maybe he was testing something and was commenting/decommenting a line in there.

                          N Offline
                          N Offline
                          Nathan Tuggy
                          wrote on last edited by
                          #12

                          There's just one thing that puzzles me about VB6: why are all the OTHER VB6 programmers so bad? I don't use VB6 anymore (when I saw .NET, I never looked back), but I was never this bad -- I wasn't even this bad when I was writing programs in QBASIC! I mean, seriously! So what's with all the amazingly awful VB programmers? It must be a curse.

                          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