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. Range Checking

Range Checking

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharpdatabasecomquestion
13 Posts 6 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

    Some production VB.Net code I happened across and fixed (variable names and such changed to protect the innocent):

    If number > 10 Or number < 30 Then
    allowed = 1
    End If

    You should notice two things strange about that code. Also, that code to check a range was hardcoded right after code that looks up ranges in a database and performs the same check. Perhaps it was added by somebody without database permission? :doh:

    [Forum Guidelines]

    F M C 3 Replies Last reply
    0
    • A AspDotNetDev

      Some production VB.Net code I happened across and fixed (variable names and such changed to protect the innocent):

      If number > 10 Or number < 30 Then
      allowed = 1
      End If

      You should notice two things strange about that code. Also, that code to check a range was hardcoded right after code that looks up ranges in a database and performs the same check. Perhaps it was added by somebody without database permission? :doh:

      [Forum Guidelines]

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

      It could have been written before the db contained the validation or without knowledge of the previous. (I know I'm making assumptions and such. It's late and I'm ready to go to bed.)

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

      A 1 Reply Last reply
      0
      • A AspDotNetDev

        Some production VB.Net code I happened across and fixed (variable names and such changed to protect the innocent):

        If number > 10 Or number < 30 Then
        allowed = 1
        End If

        You should notice two things strange about that code. Also, that code to check a range was hardcoded right after code that looks up ranges in a database and performs the same check. Perhaps it was added by somebody without database permission? :doh:

        [Forum Guidelines]

        M Offline
        M Offline
        makumazan84
        wrote on last edited by
        #3

        I'm currently ROFL-ing inside, guys!!! A true pearl. Notice, that ANY int suits the condition )))

        F A R 3 Replies Last reply
        0
        • M makumazan84

          I'm currently ROFL-ing inside, guys!!! A true pearl. Notice, that ANY int suits the condition )))

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

          I must have really been tired last night not to catch that. I'm having the same laugh now. :doh:

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

          1 Reply Last reply
          0
          • A AspDotNetDev

            Some production VB.Net code I happened across and fixed (variable names and such changed to protect the innocent):

            If number > 10 Or number < 30 Then
            allowed = 1
            End If

            You should notice two things strange about that code. Also, that code to check a range was hardcoded right after code that looks up ranges in a database and performs the same check. Perhaps it was added by somebody without database permission? :doh:

            [Forum Guidelines]

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

            With that kind of range checking, the coder is more suited to checking the range where the burgers are being cooked. :)

            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]

            A 1 Reply Last reply
            0
            • F fjdiewornncalwe

              It could have been written before the db contained the validation or without knowledge of the previous. (I know I'm making assumptions and such. It's late and I'm ready to go to bed.)

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

              A Offline
              A Offline
              AspDotNetDev
              wrote on last edited by
              #6

              The fact that an integer is being set to 1 or 0 rather than using a bool is a pretty good indicator that some of this code was copied from the database. Here is what my best guess is as to how this code evolved: *Only single numbers were checked, so they were put in a database table. *Next, certain ranges needed to be checked, and they were hard coded in the SP that checked single numbers. *Somebody thought the SQL code looked ugly or needed to use the SP without ranges, so they moved that to the VB.Net. *Somebody thought the VB.Net looked ugly, so they added ranges to the database table. *At some point, there was some VB.Net copy/pasting so that hard coded logic stayed. Result: X|

              [Forum Guidelines]

              F 1 Reply Last reply
              0
              • M makumazan84

                I'm currently ROFL-ing inside, guys!!! A true pearl. Notice, that ANY int suits the condition )))

                A Offline
                A Offline
                AspDotNetDev
                wrote on last edited by
                #7

                Indeed, that was the real bug I fixed and one of the two things that was odd about the code (excluding the fact that it's VB.Net rather than C#, which is obviously a flaw too). :)

                [Forum Guidelines]

                F 1 Reply Last reply
                0
                • C Chris Meech

                  With that kind of range checking, the coder is more suited to checking the range where the burgers are being cooked. :)

                  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]

                  A Offline
                  A Offline
                  AspDotNetDev
                  wrote on last edited by
                  #8

                  Either that, or being brought to the range to be slaughtered. Which wouldn't be much different, because he'd end up at the burger place anyway. :)

                  [Forum Guidelines]

                  F 1 Reply Last reply
                  0
                  • A AspDotNetDev

                    The fact that an integer is being set to 1 or 0 rather than using a bool is a pretty good indicator that some of this code was copied from the database. Here is what my best guess is as to how this code evolved: *Only single numbers were checked, so they were put in a database table. *Next, certain ranges needed to be checked, and they were hard coded in the SP that checked single numbers. *Somebody thought the SQL code looked ugly or needed to use the SP without ranges, so they moved that to the VB.Net. *Somebody thought the VB.Net looked ugly, so they added ranges to the database table. *At some point, there was some VB.Net copy/pasting so that hard coded logic stayed. Result: X|

                    [Forum Guidelines]

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

                    aspdotnetdev wrote:

                    integer is being set to 1 or 0 rather than using a bool is a pretty good indicator that some of this code was copied from the database

                    I would have agreed with you until I say some javascript web page logic a while back that was hand coded to work with 1s and 0s instead of booleans. Now I just think there are some pretty thick junior devs out there being allowed to write code that gets to prod without review.

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

                    B 1 Reply Last reply
                    0
                    • A AspDotNetDev

                      Indeed, that was the real bug I fixed and one of the two things that was odd about the code (excluding the fact that it's VB.Net rather than C#, which is obviously a flaw too). :)

                      [Forum Guidelines]

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

                      aspdotnetdev wrote:

                      VB.Net rather than C#

                      Very obviously...

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

                      1 Reply Last reply
                      0
                      • A AspDotNetDev

                        Either that, or being brought to the range to be slaughtered. Which wouldn't be much different, because he'd end up at the burger place anyway. :)

                        [Forum Guidelines]

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

                        Shhh!!! Don't give John any ideas!!!

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

                        1 Reply Last reply
                        0
                        • M makumazan84

                          I'm currently ROFL-ing inside, guys!!! A true pearl. Notice, that ANY int suits the condition )))

                          R Offline
                          R Offline
                          richard_k
                          wrote on last edited by
                          #12

                          Heh heh.. messed up boolean conditions are the bane of so many.. I think boolean logic is one of the hardest things to read well, and is one reason why I unit test my code thoroughly. Misused AND and OR is so easy to miss on code inspection.. but good tests never lie.

                          1 Reply Last reply
                          0
                          • F fjdiewornncalwe

                            aspdotnetdev wrote:

                            integer is being set to 1 or 0 rather than using a bool is a pretty good indicator that some of this code was copied from the database

                            I would have agreed with you until I say some javascript web page logic a while back that was hand coded to work with 1s and 0s instead of booleans. Now I just think there are some pretty thick junior devs out there being allowed to write code that gets to prod without review.

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

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

                            I have seen people use ints with 1s and 0s because they learned programming with a language that did not have a boolean type. I say that is what you get when you have someone whose degree is not in programming write the software :sigh: What is really scary is when folk with a real programming degree do the same thing! :omg:

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

                            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