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. When Gobbledygook, Do Nada (Except Break the Build)

When Gobbledygook, Do Nada (Except Break the Build)

Scheduled Pinned Locked Moved The Weird and The Wonderful
comsysadminagentic-aihelpquestion
10 Posts 7 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.
  • A Offline
    A Offline
    AspDotNetDev
    wrote on last edited by
    #1

    Dim strBrowser As String = Request.Browser.Browser.ToString()
    Dim strBroswerVersion As String = Request.Browser.Version.ToString()
    If strBrowser.ToString() = "IE" Then
    If IsNumeric(strBroswerVersion.ToString()) Then
    If strBroswerVersion < 9 Then
    ' Do absolutely nothing. Really, nothing at all.
    End If
    End If
    End If

    While fixing compiler errors after enabling option strict, I have come across a prodigious level of crap. I can't post it all, but this one stood out for being crap on almost every level imaginable. Here are a few notes off the top of my head:

    • Generally, you should avoid checking browser versions, especially in server-side code (I believe the reasoning is that older browsers are slower, so some value was changed).
    • Compilation breaks when trying to compare a string against a number.
    • Anything this would have done has been commented out, so it does nothing.
    • Calling ToString on a string (which I think might even throw a null reference exception if the original string is null)... four times.
    • Comparing strings without ignoring case.
    • The commented out code (not shown) would have caused a compiler error too (attempt to divide a string by a number).
    • Hungarian notation.

    Can I cry yet? :((

    Thou mewling ill-breeding pignut!

    L A Richard DeemingR 3 Replies Last reply
    0
    • A AspDotNetDev

      Dim strBrowser As String = Request.Browser.Browser.ToString()
      Dim strBroswerVersion As String = Request.Browser.Version.ToString()
      If strBrowser.ToString() = "IE" Then
      If IsNumeric(strBroswerVersion.ToString()) Then
      If strBroswerVersion < 9 Then
      ' Do absolutely nothing. Really, nothing at all.
      End If
      End If
      End If

      While fixing compiler errors after enabling option strict, I have come across a prodigious level of crap. I can't post it all, but this one stood out for being crap on almost every level imaginable. Here are a few notes off the top of my head:

      • Generally, you should avoid checking browser versions, especially in server-side code (I believe the reasoning is that older browsers are slower, so some value was changed).
      • Compilation breaks when trying to compare a string against a number.
      • Anything this would have done has been commented out, so it does nothing.
      • Calling ToString on a string (which I think might even throw a null reference exception if the original string is null)... four times.
      • Comparing strings without ignoring case.
      • The commented out code (not shown) would have caused a compiler error too (attempt to divide a string by a number).
      • Hungarian notation.

      Can I cry yet? :((

      Thou mewling ill-breeding pignut!

      L Offline
      L Offline
      lewax00
      wrote on last edited by
      #2

      And to top it all off, someone wrote it in VB! ;P

      1 Reply Last reply
      0
      • A AspDotNetDev

        Dim strBrowser As String = Request.Browser.Browser.ToString()
        Dim strBroswerVersion As String = Request.Browser.Version.ToString()
        If strBrowser.ToString() = "IE" Then
        If IsNumeric(strBroswerVersion.ToString()) Then
        If strBroswerVersion < 9 Then
        ' Do absolutely nothing. Really, nothing at all.
        End If
        End If
        End If

        While fixing compiler errors after enabling option strict, I have come across a prodigious level of crap. I can't post it all, but this one stood out for being crap on almost every level imaginable. Here are a few notes off the top of my head:

        • Generally, you should avoid checking browser versions, especially in server-side code (I believe the reasoning is that older browsers are slower, so some value was changed).
        • Compilation breaks when trying to compare a string against a number.
        • Anything this would have done has been commented out, so it does nothing.
        • Calling ToString on a string (which I think might even throw a null reference exception if the original string is null)... four times.
        • Comparing strings without ignoring case.
        • The commented out code (not shown) would have caused a compiler error too (attempt to divide a string by a number).
        • Hungarian notation.

        Can I cry yet? :((

        Thou mewling ill-breeding pignut!

        A Offline
        A Offline
        Argonia
        wrote on last edited by
        #3

        AspDotNetDev wrote:

        If strBroswerVersion < 9 Then ' Do absolutely nothing. Really, nothing at all.

        Man i cant imagine anything which has to be done in order to see something working as it should be on IE :laugh:

        1 Reply Last reply
        0
        • A AspDotNetDev

          Dim strBrowser As String = Request.Browser.Browser.ToString()
          Dim strBroswerVersion As String = Request.Browser.Version.ToString()
          If strBrowser.ToString() = "IE" Then
          If IsNumeric(strBroswerVersion.ToString()) Then
          If strBroswerVersion < 9 Then
          ' Do absolutely nothing. Really, nothing at all.
          End If
          End If
          End If

          While fixing compiler errors after enabling option strict, I have come across a prodigious level of crap. I can't post it all, but this one stood out for being crap on almost every level imaginable. Here are a few notes off the top of my head:

          • Generally, you should avoid checking browser versions, especially in server-side code (I believe the reasoning is that older browsers are slower, so some value was changed).
          • Compilation breaks when trying to compare a string against a number.
          • Anything this would have done has been commented out, so it does nothing.
          • Calling ToString on a string (which I think might even throw a null reference exception if the original string is null)... four times.
          • Comparing strings without ignoring case.
          • The commented out code (not shown) would have caused a compiler error too (attempt to divide a string by a number).
          • Hungarian notation.

          Can I cry yet? :((

          Thou mewling ill-breeding pignut!

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          You should see some of the crap *wonderful* third-party VB code I've been asked to help with! ;P Here's a typical example:

          Public Shared Function GetBitNr(ByVal TestInteger As Integer, ByVal Nr As Integer) As Integer
          If TestInteger < 0 Then
          If Nr = 32 Then
          Return 1
          End If

            TestInteger = TestInteger + CInt(&H80000000)
          

          End If

          Dim i As Long = 30
          Dim str As String = ""
          Do While (i > -1)
          If 2 ^ i <= TestInteger Then
          str = str & "1"
          TestInteger = CInt(Math.Round(TestInteger - 2 ^ i))
          ElseIf Left(str, 1) = "1" Then
          str = str & "0"
          End If

            i = i - 1
          

          Loop

          Dim result As Integer
          If Len(str) >= Nr Then
          result = CInt(Mid(str, Len(str) - Nr + 1, 1))
          Else
          result = 0
          End If

          Return CInt(result)
          End Function


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          A L 2 Replies Last reply
          0
          • Richard DeemingR Richard Deeming

            You should see some of the crap *wonderful* third-party VB code I've been asked to help with! ;P Here's a typical example:

            Public Shared Function GetBitNr(ByVal TestInteger As Integer, ByVal Nr As Integer) As Integer
            If TestInteger < 0 Then
            If Nr = 32 Then
            Return 1
            End If

              TestInteger = TestInteger + CInt(&H80000000)
            

            End If

            Dim i As Long = 30
            Dim str As String = ""
            Do While (i > -1)
            If 2 ^ i <= TestInteger Then
            str = str & "1"
            TestInteger = CInt(Math.Round(TestInteger - 2 ^ i))
            ElseIf Left(str, 1) = "1" Then
            str = str & "0"
            End If

              i = i - 1
            

            Loop

            Dim result As Integer
            If Len(str) >= Nr Then
            result = CInt(Mid(str, Len(str) - Nr + 1, 1))
            Else
            result = 0
            End If

            Return CInt(result)
            End Function


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            A Offline
            A Offline
            Argonia
            wrote on last edited by
            #5

            Richard Deeming wrote:

            CInt(&H80000000)

            Probably i should not ask but from pure curiosity: What is this ?

            OriginalGriffO 1 Reply Last reply
            0
            • A Argonia

              Richard Deeming wrote:

              CInt(&H80000000)

              Probably i should not ask but from pure curiosity: What is this ?

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              &H is VB prefix for Hex constant: so &H100 is 256, &H200 is 512, and so forth. So it's converting a 32 bit hexadecimal integer constant value to a 32 bit integer value... :doh:

              The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              F 1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                &H is VB prefix for Hex constant: so &H100 is 256, &H200 is 512, and so forth. So it's converting a 32 bit hexadecimal integer constant value to a 32 bit integer value... :doh:

                The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

                F Offline
                F Offline
                Freak30
                wrote on last edited by
                #7

                But if this is a signed integer, wouldn't it just add -1 to the input instead of turning the sign around? Or is Cint() a conversion to unsigned int? Also converting the whole number when you only need one bit, thats "just great". :rolleyes:

                OriginalGriffO Richard DeemingR 2 Replies Last reply
                0
                • F Freak30

                  But if this is a signed integer, wouldn't it just add -1 to the input instead of turning the sign around? Or is Cint() a conversion to unsigned int? Also converting the whole number when you only need one bit, thats "just great". :rolleyes:

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #8

                  Well - no. What it will do is throw an OverflowException "Value was either too large or too small for an Int32." when you try to do the convert in the C# version, or "Arithmetic operation resulted in an overflow." when you add the two together in the VB... :laugh:

                  The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  1 Reply Last reply
                  0
                  • F Freak30

                    But if this is a signed integer, wouldn't it just add -1 to the input instead of turning the sign around? Or is Cint() a conversion to unsigned int? Also converting the whole number when you only need one bit, thats "just great". :rolleyes:

                    Richard DeemingR Offline
                    Richard DeemingR Offline
                    Richard Deeming
                    wrote on last edited by
                    #9

                    Not to mention converting the string manually instead of using Convert.ToString(TestInteger, 2)[^]. Or concatenating up to 31 strings during the conversion. Or extracting a single character as a string instead of a character. Or using CInt when you know it will be either "0" or "1". Or even the fact that the whole method could be replaced with:

                    Return If(TestInteger And (2 ^ (Nr - 1)) = 0, 0, 1)

                    And as for the fact that the function was only ever called with a single value of Nr, so that all the calls could be replaced with:

                    'If GetBitNr(someValue, 7) = 1 Then
                    If (someValue And 64) <> 0 Then

                    X|


                    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                    1 Reply Last reply
                    0
                    • Richard DeemingR Richard Deeming

                      You should see some of the crap *wonderful* third-party VB code I've been asked to help with! ;P Here's a typical example:

                      Public Shared Function GetBitNr(ByVal TestInteger As Integer, ByVal Nr As Integer) As Integer
                      If TestInteger < 0 Then
                      If Nr = 32 Then
                      Return 1
                      End If

                        TestInteger = TestInteger + CInt(&H80000000)
                      

                      End If

                      Dim i As Long = 30
                      Dim str As String = ""
                      Do While (i > -1)
                      If 2 ^ i <= TestInteger Then
                      str = str & "1"
                      TestInteger = CInt(Math.Round(TestInteger - 2 ^ i))
                      ElseIf Left(str, 1) = "1" Then
                      str = str & "0"
                      End If

                        i = i - 1
                      

                      Loop

                      Dim result As Integer
                      If Len(str) >= Nr Then
                      result = CInt(Mid(str, Len(str) - Nr + 1, 1))
                      Else
                      result = 0
                      End If

                      Return CInt(result)
                      End Function


                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                      L Offline
                      L Offline
                      Lutoslaw
                      wrote on last edited by
                      #10

                      Now I see the point of lessons on Assembler... One of the first tasks was to "convert a decimal number to a binary representation and output to the console". If you have to write something in ASM, you desperately look for a smallest an easiest solution possible. Everybody should have such lessons. It teaches how the computer arithmetic works better than a houndred of calculus lectures.

                      Greetings - Jacek

                      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