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. Another gem from the VB6 code I'm "porting"

Another gem from the VB6 code I'm "porting"

Scheduled Pinned Locked Moved The Weird and The Wonderful
rubyquestion
12 Posts 8 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 NormDroid

    Rob Grainger wrote:

    (before someone says, predictably, that the real WTF is VB, I'd like to point out I've seen code just as horrible in most languages.

    But VB seems to bring out the best in bad programming.

    Software Kinetics - Dependable Software news

    R Offline
    R Offline
    Rob Grainger
    wrote on last edited by
    #3

    You need to try "View Source" on a few web pages then ;-) I think it applies generally to many "high-level"/scripting languages, unless (like Dart, Smalltalk) they were well-designed in the first place.

    "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

    1 Reply Last reply
    0
    • R Rob Grainger

      In one function, the following is used to call SomeFunc (names changed to protect the guilty):

      If UCase(SomeFunc("" & int_var, bool_var)) = "YES" Then
      F.chkBox.Value = 1
      Else
      F.chkBox.Value = 0
      End If

      (with two more calls to the same function further down). Where F is a form variable (because frm would be too hard to type) Looking at the definition...

      Private Function SomeFunc(Result As Long, Optional cond As Boolean) As String
      If cond = True Then
      Select Case (Result)
      Case Is < 3
      SomeFunc = "No"
      Case Is > 2
      SomeFunc = "Yes"
      End Select

      Else
          Select Case (Result)
              Case 1
                  SomeFunc = "No"
              Case Is >= 2
                  SomeFunc = "Yes"
          End Select
      End If
      

      End Function

      Why use a Boolean when a string comparison, case conversion and check for null string will do? Why is that Boolean argument optional, when it is always supplied? (before someone says, predictably, that the real WTF is VB, I'd like to point out I've seen code just as horrible in most languages. The real real WTF is that people who produce such garbage are still employed.

      "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

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

      You missed one: it converts int_var (which is presumably a Long) to a String, and then relies on VB's implicit conversion to convert it back to a Long. :doh:


      "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

      R 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        You missed one: it converts int_var (which is presumably a Long) to a String, and then relies on VB's implicit conversion to convert it back to a Long. :doh:


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

        R Offline
        R Offline
        Rob Grainger
        wrote on last edited by
        #5

        Well spotted - I left that one deliberately to ensure folk are paying attention ;-) Actually, most of the real horrors in this particular code base are more subtle and hard to illustrate in short snippets and more to do with putting too much business logic in event handlers for controls. When a form loads, info from the database is written to a control, which fires an event handler, which writes to another control, which fires an event handler, which... I think you get the picture. Business logic is totally interspersed with UI logic - often broken out into separate modules the contents of which have no logical relation. Global variables are used for all sorts of purposes. "Option Strict" has not been used, and frequently variables are not declared anywhere at all... GoTo's and even GoSub's are used liberally. I'm just glad I'm tasked with rewriting it rather than maintaining it, but it can be software archaeology trying to determine what the heck the original logic was intended to accomplish.

        "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

        Richard DeemingR R 2 Replies Last reply
        0
        • N NormDroid

          Rob Grainger wrote:

          (before someone says, predictably, that the real WTF is VB, I'd like to point out I've seen code just as horrible in most languages.

          But VB seems to bring out the best in bad programming.

          Software Kinetics - Dependable Software news

          C Offline
          C Offline
          Chris Quinn
          wrote on last edited by
          #6

          As I always say, it ain't the tool that is used, it's the tool that uses it that's the problem.

          ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

          R 1 Reply Last reply
          0
          • C Chris Quinn

            As I always say, it ain't the tool that is used, it's the tool that uses it that's the problem.

            ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

            R Offline
            R Offline
            Rob Grainger
            wrote on last edited by
            #7

            Spot on!

            "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

            1 Reply Last reply
            0
            • R Rob Grainger

              Well spotted - I left that one deliberately to ensure folk are paying attention ;-) Actually, most of the real horrors in this particular code base are more subtle and hard to illustrate in short snippets and more to do with putting too much business logic in event handlers for controls. When a form loads, info from the database is written to a control, which fires an event handler, which writes to another control, which fires an event handler, which... I think you get the picture. Business logic is totally interspersed with UI logic - often broken out into separate modules the contents of which have no logical relation. Global variables are used for all sorts of purposes. "Option Strict" has not been used, and frequently variables are not declared anywhere at all... GoTo's and even GoSub's are used liberally. I'm just glad I'm tasked with rewriting it rather than maintaining it, but it can be software archaeology trying to determine what the heck the original logic was intended to accomplish.

              "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

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

              Rob Grainger wrote:

              "Option Strict" has not been used

              I didn't think VB6 had Option Strict? From my hazy memory, it only had Option Explicit, Option Compare and Option Base. MSDN also lists Option Private[^], but I don't think I ever saw that used.


              "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
              • R Rob Grainger

                Well spotted - I left that one deliberately to ensure folk are paying attention ;-) Actually, most of the real horrors in this particular code base are more subtle and hard to illustrate in short snippets and more to do with putting too much business logic in event handlers for controls. When a form loads, info from the database is written to a control, which fires an event handler, which writes to another control, which fires an event handler, which... I think you get the picture. Business logic is totally interspersed with UI logic - often broken out into separate modules the contents of which have no logical relation. Global variables are used for all sorts of purposes. "Option Strict" has not been used, and frequently variables are not declared anywhere at all... GoTo's and even GoSub's are used liberally. I'm just glad I'm tasked with rewriting it rather than maintaining it, but it can be software archaeology trying to determine what the heck the original logic was intended to accomplish.

                "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                R Offline
                R Offline
                Ron Beyer
                wrote on last edited by
                #9

                Its amazing how many programs would be completely broken with the simple addition of "Option Strict" at the top. Probably written by people who think VB6 is the best thing since sliced bread[^]. Notice the publish date on that...

                1 Reply Last reply
                0
                • R Rob Grainger

                  In one function, the following is used to call SomeFunc (names changed to protect the guilty):

                  If UCase(SomeFunc("" & int_var, bool_var)) = "YES" Then
                  F.chkBox.Value = 1
                  Else
                  F.chkBox.Value = 0
                  End If

                  (with two more calls to the same function further down). Where F is a form variable (because frm would be too hard to type) Looking at the definition...

                  Private Function SomeFunc(Result As Long, Optional cond As Boolean) As String
                  If cond = True Then
                  Select Case (Result)
                  Case Is < 3
                  SomeFunc = "No"
                  Case Is > 2
                  SomeFunc = "Yes"
                  End Select

                  Else
                      Select Case (Result)
                          Case 1
                              SomeFunc = "No"
                          Case Is >= 2
                              SomeFunc = "Yes"
                      End Select
                  End If
                  

                  End Function

                  Why use a Boolean when a string comparison, case conversion and check for null string will do? Why is that Boolean argument optional, when it is always supplied? (before someone says, predictably, that the real WTF is VB, I'd like to point out I've seen code just as horrible in most languages. The real real WTF is that people who produce such garbage are still employed.

                  "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

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

                  What happens, if you pass cond as False and Result as 0 (or anything < 1)? Does the function return a Null value and cause an Exception in the If?

                  The good thing about pessimism is, that you are always either right or pleasently surprised.

                  S 1 Reply Last reply
                  0
                  • F Freak30

                    What happens, if you pass cond as False and Result as 0 (or anything < 1)? Does the function return a Null value and cause an Exception in the If?

                    The good thing about pessimism is, that you are always either right or pleasently surprised.

                    S Offline
                    S Offline
                    Sentenryu
                    wrote on last edited by
                    #11

                    It should return null, but no exception. it will just be evaluated as false, because null != "YES"

                    1 Reply Last reply
                    0
                    • R Rob Grainger

                      In one function, the following is used to call SomeFunc (names changed to protect the guilty):

                      If UCase(SomeFunc("" & int_var, bool_var)) = "YES" Then
                      F.chkBox.Value = 1
                      Else
                      F.chkBox.Value = 0
                      End If

                      (with two more calls to the same function further down). Where F is a form variable (because frm would be too hard to type) Looking at the definition...

                      Private Function SomeFunc(Result As Long, Optional cond As Boolean) As String
                      If cond = True Then
                      Select Case (Result)
                      Case Is < 3
                      SomeFunc = "No"
                      Case Is > 2
                      SomeFunc = "Yes"
                      End Select

                      Else
                          Select Case (Result)
                              Case 1
                                  SomeFunc = "No"
                              Case Is >= 2
                                  SomeFunc = "Yes"
                          End Select
                      End If
                      

                      End Function

                      Why use a Boolean when a string comparison, case conversion and check for null string will do? Why is that Boolean argument optional, when it is always supplied? (before someone says, predictably, that the real WTF is VB, I'd like to point out I've seen code just as horrible in most languages. The real real WTF is that people who produce such garbage are still employed.

                      "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                      M Offline
                      M Offline
                      Marc Clifton
                      wrote on last edited by
                      #12

                      Rob Grainger wrote:

                      The real real WTF is that people who produce such garbage are still employed.

                      And quite possibly one of the 23 million surveyed![^] Say it's not true! Marc

                      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