- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Perhaps
<script src="chrome://greasemonkey/content/scripts/1106572873125"></script>
Admin
1) Error checking bypassed and then cleared
2) Going to the db multiple times.
3) Comparing a string return to numerical 0
Admin
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.
Admin
Dim s As String As Long ?
Admin
he was probably looking for
If len(SelectSQL("LastUpdateSQL")) = 0 Then
Admin
executing the same query 3 times
Admin
er I mean two times
Admin
Dim s As String As Long
Umm, what?
Admin
Uhmmm...
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.This code makes me uneasy.
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?
Admin
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]
Admin
There are almost too many WTFs to count.
In the immortal word's of Southpark's Cartman: "Lame!"
Admin
>><FONT color=#0000ff>Dim</FONT> s As String As Long
I suspect that's a "typo" when Alex edited the code ....
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
You're right, my bad ... as you may or may not know, I generally change business entity names and pull out unecessary stuff ...
Admin
<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>
Admin
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?
Admin
"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.
Admin
Admin
Admin
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.
Admin
Comparing "3.14" = 3.14 will result in true in VB6. Try it.
Admin
Admin
This is a TROLL. Accept it, ignore it, and move past it.
Admin
Comparing "3.14" = 3.14 will result in true in VB6. Try it.
Admin
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
Admin
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.
Admin
"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.
Admin
> 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
Admin
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....
Admin
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.
Admin
How about the fact that the first function is calling an empty function stub?
Admin
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)
Admin
... 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.
Admin
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.
Admin
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
Admin
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.
Admin
Did I mention that I like yams?
Admin
Settle down, It's not so Hard. It might take one or two more lines but neh. shrugs
Ben.
Admin
Sorry, I refer to this poster.
Cheers,
Ben.
Admin
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...
Admin
using VB is the most obvious one.
Admin
> 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).
Admin
Whut? Speak up son, we can't hear you!
Admin
<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
Admin
<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>
Admin
Actually I think Return is a Fortran-ism. Nothing so new and modern as Algol.