• (unregistered)

    Perhaps

     On Error Resume Next 
    On Error GoTo 0

    <script src="chrome://greasemonkey/content/scripts/1106572873125"></script>
  • (unregistered)

    1) Error checking bypassed and then cleared

    2) Going to the db multiple times.

    3) Comparing a string return to numerical 0

  • (cs)

    I see it.  He gets the date and time from the last successful update and then displays the action from the last update.  Also, he checks for LastUpdateSql not LastSuccessfulUpdateSql.  Plus there's the fact that he hits the db a lot more than needed.

  • (unregistered)

    Dim s As String As Long ?

  • (unregistered) in reply to

    he was probably looking for

    If len(SelectSQL("LastUpdateSQL")) = 0 Then

  • (unregistered) in reply to

    executing the same query 3 times

  • (unregistered) in reply to

    er I mean two times

  • (cs)

       Dim s As String As Long

    Umm, what?

  • (cs)

    Uhmmm...

    This code makes me uneasy.

     Dim s As String As Long 

    On Error Resume Next
    On Error GoTo 0
    How do you declare a variable as a string as a long. I certainly hope the database doesn't throw any errors, because if it does, that on error resume next is toast. It would seem easier to get an ADODB recordset object instead of a string with the two needed values..  Why do the column names have to be suffixed with SQL.

    I assume the function names have been changed to protect the guilty, bit if this is how they're really named, they could have used better naming conventions than 'Blahblah'

    If the code gets to the else clause it hits the database 4 times...  Once unnecessarily as the value has already been retreieved. 

    Why are they storing software update history in a SQL database to begin with? Or is it an Access MDB on the local machine?

  • (cs)

    I found many WTF's - the ones listed above by other people - but I didn't get a feeling of 'accomplishment', more like a feeling of being sick to my stomach.[:S]

  • (cs)

    There are almost too many WTFs to count.

    In the immortal word's of Southpark's Cartman: "Lame!"

  • (cs)

    >><FONT color=#0000ff>Dim</FONT> s As String As Long

    I suspect that's a "typo" when Alex edited the code ....

     

  • (unregistered)

    been a while since I've played with VB but lets assume that

     Dim s As String As Long

    causes a fault

    then

       On Error Resume Next
        On Error GoTo 0

    ignores the fault caused by the original stupid declaration to be ignored.

      If SelectSQL("LastUpdateSQL") = 0 Then

    I'm also going to have to assume that empty string is not equal to 0 so this logical operation is never true ( they probably wanted to see if dataset was empty... there are better ways)

            s = "On " & _
                Format(SelectSQL("LastSuccessfulUpdateSQL"), "d Mmmm") & _
                " at " & _
                Format(SelectSQL("LastSuccessfulUpdateSQL"), "h:mm am/pm") & _
                " you processed update " & _
                SelectSQL("LastUpdateSQL") & "."

    here 3 separate db connections and queries are run all to collect the same 2 values... actually 4 if you count the original test.

    So in short everything that wasn't snipped to protect the identity of the culprit was a WTF.

  • (cs) in reply to
    :

      If SelectSQL("LastUpdateSQL") = 0 Then

    I'm also going to have to assume that empty string is not equal to 0 so this logical operation is never true ( they probably wanted to see if dataset was empty... there are better ways)

    VB is pretty free with type conversions - comparing "3.14" to 3.14 will result in true, which could then be assigned to an integer variable, or even a date variable (something that really shouldn't work...)

    I don't know for sure whether "" is equal to 0, but if I had to guess I'd say that it is.  It's not the best way to do the comparison, or even the best way to do the query, but I don't think it is outright wrong.

  • (unregistered)

    Alex Papadimoulis:

    Public Sub cmdRefresh_Click()
    lblBlah.Caption = RefreshBlahBlah()
    End Sub

    I appreciate the fact that a function was written to get the status and DB access code was not written directly into an event[1], but calling a function 'RefreshBlahBlah()'?  Aside from the horrible, 'cutesy' name, 'Refresh...' implies that it does something, not return something.

    How about something sensible like "ReturnUpdateStatus"?

    [1] One of my pet peeves is when people write business logic in event scripts.  Can we at least try to keep the UI logic and business logic seperate?  I blame those 'Learn VB in 21 Days' type books, because they are filled with garbage like that.

  • (cs) in reply to

    :

    [1] One of my pet peeves is when people write business logic in event scripts.  Can we at least try to keep the UI logic and business logic seperate?  I blame those 'Learn VB in 21 Days' type books, because they are filled with garbage like that.

    That's pretty damn accurate.  The textbook I used for my VB course in college was like that.  And it wasn't even a "learn everything in 2 minutes" type book.  I'm just now starting to break the habit. 

  • (cs) in reply to
    :

    [1] One of my pet peeves is when people write business logic in event scripts.  Can we at least try to keep the UI logic and business logic seperate?  I blame those 'Learn VB in 21 Days' type books, because they are filled with garbage like that.

    While I do agree that it's good practice, If the application is simple and small enough, does it actually make sense to break the functionality out to another function if that is all this particular event handler is going to do? Also, it can have a tendency to kludge debugging a bit more (Though, I believe VB steps into functions unless you press F8 with the shift key)

    And, even though some will balk at this, it is another function call, it is another bit of state being put on the stack, it is another branch in the code and it does affect whether the code to be executed will be in the cache, but that only matters when using native code, and it certainly can be argued that the effect of calling a function immediately from an event handler is negligable.

    Actually... One of my pet peeves is people who don't name controls on VB forms (i.e. they leave them as Text1, Test2, Text3, etc...), Then when debugging and editing code, you have a hell of a time trying to find out what happens when an event hits on a control.

  • (cs) in reply to Jeff S
    Jeff S:

    >><FONT color=#0000ff>Dim</FONT> s As String As Long

    I suspect that's a "typo" when Alex edited the code ....

    You're right, my bad ... as you may or may not know, I generally change business entity names and pull out unecessary stuff ...

  • (unregistered)

    <FONT style="BACKGROUND-COLOR: #efefef">As usual, all the comments posted here are the biggest WTFs.  There is nothing wrong with this code.  It works, it is efficient, it is easy to read, what else can you ask for?</FONT>

  • (cs) in reply to
    :

    <font style="background-color: rgb(239, 239, 239);">As usual, all the comments posted here are the biggest WTFs.  There is nothing wrong with this code.  It works, it is efficient, it is easy to read, what else can you ask for?</font>



    As has been pointed out by a multitude of the people that post on this board it creates 4 round trips to the database to read 2 values. How, exactly is that efficient?

    Unfortunantly the database code has been snipped, but I can almost guess by the comment Alex has made that the code originally did a select * from (...), which is horribly inefficient.

    And as far as it working, what happens if the database server is unplugged by the janitor? Does the application as written handle this situation gracefully?
  • (unregistered) in reply to pagefault

    "VB is pretty free with type conversions - comparing "3.14" to 3.14 will result in true, which could then be assigned to an integer variable, or even a date variable (something that really shouldn't work...)"

    True, VB is free with Type Conversions, unless Option Strict is on.  Unfortunately, they've never seen fit to make this default behavior.

  • (cs) in reply to
    :

    <FONT style="BACKGROUND-COLOR: #efefef">As usual, all the comments posted here are the biggest WTFs.  There is nothing wrong with this code.  It works, it is efficient, it is easy to read, what else can you ask for?</FONT>

     
    Efficient? have you been paying attention?
  • (cs) in reply to
    :

    "VB is pretty free with type conversions - comparing "3.14" to 3.14 will result in true, which could then be assigned to an integer variable, or even a date variable (something that really shouldn't work...)"

    True, VB is free with Type Conversions, unless Option Strict is on.  Unfortunately, they've never seen fit to make this default behavior.

     
    In VB.NET, yes.  But for VB6, there is no "Option Strict".
     
    Try to look closely at the code posted to determine what language it's in ... clue: On Error Resume Next is a strong indication of VB6.
  • (cs) in reply to Mike R

    Mike R:


    As has been pointed out by a multitude of the people that post on this board it creates 4 round trips to the database to read 2 values. How, exactly is that efficient?

    I'd just like to point out here that the two values he is reading are from the same table and from the logic of the code (what logic there is anyway) it seems that these two values could be read from the same row.  Which means he could have done all the necessary data access in a single call rather than four.  WTF2.

  • (cs) in reply to Jeff S
    Jeff S:
    [image]  wrote:

    "VB is pretty free with type conversions - comparing "3.14" to 3.14 will result in true, which could then be assigned to an integer variable, or even a date variable (something that really shouldn't work...)"

    True, VB is free with Type Conversions, unless Option Strict is on.  Unfortunately, they've never seen fit to make this default behavior.

     
    In VB.NET, yes.  But for VB6, there is no "Option Strict".
     
    Try to look closely at the code posted to determine what language it's in ... clue: On Error Resume Next is a strong indication of VB6.

    Comparing "3.14" = 3.14 will result in true in VB6.  Try it.

  • (cs) in reply to bjmarte
    bjmarte:
    [image] Jeff S wrote:
    [image]  wrote:

    "VB is pretty free with type conversions - comparing "3.14" to 3.14 will result in true, which could then be assigned to an integer variable, or even a date variable (something that really shouldn't work...)"

    True, VB is free with Type Conversions, unless Option Strict is on.  Unfortunately, they've never seen fit to make this default behavior.

     
    In VB.NET, yes.  But for VB6, there is no "Option Strict".
     
    Try to look closely at the code posted to determine what language it's in ... clue: On Error Resume Next is a strong indication of VB6.

    Comparing "3.14" = 3.14 will result in true in VB6.  Try it.

     
    ummmm .. I think you missed the point of all 3 posts you quoted .... no one disputes that VB6 returns True for that expression.  The point is, w/o an explicit cast, it SHOULDN'T.
  • (unregistered) in reply to Mike R
    Mike R:
    :

    <font style="background-color: rgb(239, 239, 239);">As usual, all the comments posted here are the biggest WTFs.  There is nothing wrong with this code.  It works, it is efficient, it is easy to read, what else can you ask for?</font>



    As has been pointed out by a multitude of the people that post on this board it creates 4 round trips to the database to read 2 values. How, exactly is that efficient?

    Unfortunantly the database code has been snipped, but I can almost guess by the comment Alex has made that the code originally did a select * from (...), which is horribly inefficient.

    And as far as it working, what happens if the database server is unplugged by the janitor? Does the application as written handle this situation gracefully?

    This is a TROLL. Accept it, ignore it, and move past it.

  • (cs) in reply to Jeff S
    Jeff S:
    [image]  wrote:

    "VB is pretty free with type conversions - comparing "3.14" to 3.14 will result in true, which could then be assigned to an integer variable, or even a date variable (something that really shouldn't work...)"

    True, VB is free with Type Conversions, unless Option Strict is on.  Unfortunately, they've never seen fit to make this default behavior.

     
    In VB.NET, yes.  But for VB6, there is no "Option Strict".
     
    Try to look closely at the code posted to determine what language it's in ... clue: On Error Resume Next is a strong indication of VB6.

    Comparing "3.14" = 3.14 will result in true in VB6.  Try it.

  • (cs) in reply to Jeff S

    Yes, you are right.  Sorry about that, I didn't really read the last part of the first post.  Sorry about the double post too.

    Brett

  • (unregistered)

    The WTF is that the board software requires JavaScript just to view the second page of comments. No wonder the vendor's page only lists some shite Microsoft forums "and many others" as their featured users.

  • (unregistered) in reply to Jeff S

    "In VB.NET, yes.  But for VB6, there is no "Option Strict"."

    Whoops.  My fault.  I'll blame it on not having used VB6 since pre-Beta 1 of .NET.

  • (unregistered) in reply to Jeff S

    > no one disputes that VB6 returns True for that expression.  The point is, w/o an explicit cast, it SHOULDN'T.

    but I thought that was supposed to be a "feature" of vb*...

    anyway, the If statement isn't intending to compare an empty string to 0, it is comparing the value of LastUpdateSQL which, as one of the comments shows, returns a number (albeit in a string) - since there's apparently no condition given to the query, the SQLSelect function is assumed to always return a value

    that doesn't diminish the WTFness of it though

  • (unregistered)

    OKay, I know less than nothing about VB... but doesn't "Public Function RefreshBlahBlah() As String" imply that the function will return a string?

    Nothing is actually returned by the function - it sets the "RefreshBlahBlah" variable, but doesn't seem to return it.

    Does VB do globals like that? 

    Or maybe I'm just confused....

  • (unregistered) in reply to

    :
    OKay, I know less than nothing about VB... but doesn't "Public Function RefreshBlahBlah() As String" imply that the function will return a string?

    Nothing is actually returned by the function - it sets the "RefreshBlahBlah" variable, but doesn't seem to return it.

    Does VB do globals like that? 

    Or maybe I'm just confused....

    In VB6, an implicit variable is created that is the same as the function name.  To return a value, you set this "variable" equal to the value you want to return.  Then, when execution of the function terminates, the value of this variable is returned.  Vb.NET behaves similarly, except that they also overloaded the "Return" keyword to fulfill this role.

  • (cs)

    How about the fact that the first function is calling an empty function stub?

    Private Function SelectSQL(col) As String
    'ED: Snip opening a connection to the database, opening a recordset,
    ' returning the requested column
    End Function



  • (unregistered) in reply to Schol-R-LEA

    That's that the "ED:" part is, it was removed to protect the guilty... (probably wasn't necessary to the point(s) of the WTF)

  • (unregistered) in reply to

    ... overloaded in VB.Net ...

    Wait.  Hold on.  Are you saying that in VB6, you can't actually say "Return VarName" and have it return the variable/value stored in VarName?

    To me, that's more of a WTF than anything I've seen so far from this site. 

  • (cs)

    Passing a Column name in order to get a single value only works if the table is restricted to a single row of active data.   Given the context that this code is running in, that is probably the case but you could run into some troubles if someone starts messing with  your back end.

  • (cs) in reply to Bustaz Kool

    I've noticed something you've all missed, or read over, or didn't think was a WTF.

    Imagine, you don't update for a year or two? You wouldn't know if it was one year, or two, or maybe even ten...

    When stating a date, I always try to keep it as complete as possible... My dentist always makes appointment slips with only the day and month on them. I have to grab a calendar to see which appointment slip is for this year. YUCK.

    Drak

  • (unregistered) in reply to Jeff S

    In PHP "3.14" == 3.14 returns true as well, which is really really handy, however "3.14" === 3.14 returns false, which is also really really handy.

  • (unregistered)

    Did I mention that I like yams?

  • (unregistered) in reply to

    Settle down, It's not so Hard. It might take one or two more lines but neh. shrugs
    Ben.

    <disclaimer>samples may not compile and yes can take fewer lines<disclaimer>
    The C Way:
    int GetANumber()
    int x;
    x = 64;
    return x;
    }

    The VB6 Way: Function GetANumber() As Integer Dim x As Integer x = 64 GetANumber = x End Function

    The C Way Part 2: int GetANumber() int x; if (true) { x = 64; return x; } else { x = 65; return x; } }

    The VB6 Way Part 2: Function GetANumber() As Integer Dim x As Integer If (True) Then x = 64 GetANumber = x Exit Function Else x = 65 GetANumber = x Exit Function End If End Function

  • (unregistered) in reply to

    :
    ... overloaded in VB.Net ...

    Wait.  Hold on.  Are you saying that in VB6, you can't actually say "Return VarName" and have it return the variable/value stored in VarName?

    To me, that's more of a WTF than anything I've seen so far from this site. 

    Sorry, I refer to this poster.

    Cheers,

    Ben.

  • (cs)

    I don't think anyone's mentioned that VB's Format function is a little more flexible: that duplicate call could be eliminated by something like this:

    Format(SelectSQL("LastSuccessfulUpdateSQL"), "d Mmmm at h:mm am/pm")

    Which is not, of course, to detract from all the otherful wonderful idiocies presented. Actually, I rather like small pieces of garbage like this, they're easy to clean up and I get to feel good about myself for a few minutes...

  • (unregistered)

    using VB is the most obvious one.

     

  • (cs) in reply to

    > Are you saying that in VB6, you can't actually say "Return VarName" and have it return the variable/value stored in VarName?

    I believe <function-name> = <return-value> is standard Basic syntax for setting a function's return value. At least, it works in all Microsoft Basic implementations that I've used, and Acorn's Basic too. Using a "return" keyword is a C-ism (or maybe an Algol-ism).

  • (unregistered)

    Whut? Speak up son, we can't hear you!

  • (cs) in reply to Ben Hutchings

    <FONT size=2>> </FONT><FONT size=1>Are you saying that in VB6, you can't actually say "Return VarName" and have it return the variable/value stored in VarName?

    I believe <function-name> = <return-value> is standard Basic syntax for setting a function's return value. At least, it works in all Microsoft Basic implementations that I've used, and Acorn's Basic too. Using a "return" keyword is a C-ism (or maybe an Algol-ism).</FONT>

    Gosub .. Return :P

    GW Basic [:P]

    Drak

  • (unregistered) in reply to Drak

    <FONT size=2> </FONT>

    <FONT size=2>> </FONT><FONT size=1>Are you saying that in VB6, you can't actually say "Return VarName" and have it return the variable/value stored in VarName?

    I believe <function-name> = <return-value> is standard Basic syntax for setting a function's return value. At least, it works in all Microsoft Basic implementations that I've used, and Acorn's Basic too. Using a "return" keyword is a C-ism (or maybe an Algol-ism).
    </FONT>

    <FONT size=1>Gosub .. Return :P</FONT>

    <FONT size=1>GW Basic Stick out tongue</FONT>

    <FONT size=1>Gosub ... Return also worked in Apple ][ basic.  (Am I dating myself... and if I am can I break up with myself)</FONT>

  • (unregistered) in reply to

    Actually I think Return is a Fortran-ism.  Nothing so new and modern as Algol.

Leave a comment on “Where's WTF?”

Log In or post as a guest

Replying to comment #:

« Return to Article