- 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
I believe it's real ... there is no way anyone could make this up.
Admin
I swear I worked with a guy that wrote code like this.
Admin
SQL Server 2000: $1850
Priceless.Visual Studio 6: $750
1 Year MSDN Universal: $3500
Writing this line of "code:"
Admin
i'm still working with one of those :)
Mike R, rotfl :D
Admin
Who knows maybe you two are colleagues!
Admin
I think people who have been found to be writing this type of code should be blackballed from I/T, it (and consulting) give I/T workers a bad reputation.
Ugh, I need a Percoset after looking at that.
Admin
<FONT face="Courier New">On Error Resume Next</FONT> -- Helping bad VB progammers ignore their errors for 12 years.
I'm surprised it even compiled! Is there no type checking in that compiler?
Admin
Okay... there's only one possible way that someone exhibiting such utter stupidity can continue to breathe: he's used to scripting languages. In fact, he's so used to them, that his default state is:
state = 'breathe()'
exec(state)
Admin
OMG ME TOO!
hahah
Admin
Visual Basic programmers who use On Error Resume Next on everything are also found to have high incidents of:
1-800-GET-HELP
Admin
Public Function CloseConnection(ByVal connectionNum As Integer) As Integer
On Error Resume Next
Dim ReturnStatus As Integer
ReturnStatus = "sqlConnection" & CStr(connectionNum) & ".Close()"
If ReturnStatus <> 0 Then
Return False <----- WHAT THE FUCK THIS WONT EVEN COMPILE RETURN ISN'T A KEYWORD!!!!!
End If
Return True
Exit Function
End Function
Admin
No, since version 4, VB has freely converted between integers and strings. This is alternately referred to as "Implicit Type Conversion" and "Evil Type Conversion". I take advantage of the shortcut, since I figure I've lost type safety, anyway.
The string from the original post will always evaluate to 0. Even if the "On Error" wasn't there, this function would always return success.
Admin
Exit function, exit function, exit function....
Admin
OMG nevermind, this is VB.NET code.... oy vey brand new language, and now brand new WTFs to be generated every day.
Admin
Now... how in the hell in VB.NET (assuming that since RETURN is only a keyword in VB.NET).... can you possibly execute that sh** and expect it to hit a method? ?!?!?!!?
Admin
VB.Net has "On Error..."? I thought it was supposed to use try/catch/finally.
Admin
OMG nevermind this thing will never be able to execute anyway, starting at the first line of executable code. Look at what the type of "ReturnStatus" is....
Admin
Ya know, this doesn't look so much like a coding error to me, but the result of an automated merge that no one checked. I'll bet half a Coke that there was a line executing the string at some point, and the merge mangled it. ClearCase, anyone?
Admin
Further, I'd bet he came from a dBase -like language, where stuff like that actually worked! (Since FoxPro is one such language, I wonder if that code would work there....)
Admin
Those two lines in particular remind of an application that was written with exactly that kind of code all the way through it, costing near to $1k. Can't name it unfortunately because the author might (though probably not) be reading this. :-)
Admin
At last.
At last we are bequeathed a WTF that harkens back to the days of old, when the glory of WTF was at its prime. When code so putrid, so insepid, so utterly devoid of anything resembling logic, experience or basic programming rears its ugly head, causing us to shout in ardent disbelief: "WHAT THE FUCK!????"
And of course, its in Visual Basic...
Admin
Admin
yay for backwards compatibility!!
Admin
So many things wrong with this small piece of code ... I can't even imagine what the rest is like...
head hurts ... must lie down...
Admin
Examples like this should be on a different site named thedailyOMG.com. Stunning.
Admin
excellent! *
Admin
If no one checked it, why is it in the program? You can't just put junk in your code and expect the computer to know what you mean!
Admin
I love this...
<FONT color=#000000>What happens if the End Function doesn't work? Shouldn't there be a fourth layer of redundancy in this method?</FONT>
Admin
Just to be picky, "End Function" isn't an executable statement. It's like a closing curly bracket in C or Java.
Admin
It's not bad enough that this is returning booleans as integers. Then again, we couldn't expect Option Strict to be set to On.
If I ever needed an excuse to switch to C#, I now have one--to avoid being grouped with this example.
Admin
In the car this morning I was wondering if VB had singlehandedly provided the world with the biggest number of WTFs, both in absolute terms and relatively to, say, the installed code base. This site seems to confirm my fear.
Admin
Thanks for the reminder, I tried purging all VB knowledge a few years back, it appears I was more successful than I thought.
Admin
Most languages just give you enough rope to hang yourself.
VB without Option Strict allows you to implicitly convert everyday household objects into EVEN MORE rope.
Admin
Aw, c'mon, Richard. Name it! How about the initials? At that price and code quality, they should be out of business soon.
Admin
Admin
oh yes, it does have try/catch/finally, but you can't expect VB 'programmers' to give up their most useful command. Why write decent code, when you can just pretend it works fine all the time?!
Admin
And he's only 1 line away from having code that does something useful, too.
Admin
If only he were using vbscript instead of vb.net he'd have been oh so very close.
Just adding
Execute(ReturnStatus)
in the empty line would have done the job. Ah what a pity.
Actually, I wonder if it's possible that this could have been migrated over from a vbscript, and the line above removed by a dimwitted programmer in order to get it to compile without complaining. Worth a thought.
Admin
I almost missed the best part -- look at the argument of the function. At first I thought he was passing in a reference to a connection object ... but, nope .... it's an integer -- the "connection number" ! The index to a global array of connection objects, you might think? That would be bad enough, but again, no ... apparently he has the global variables "sqlConnection1", "sqlConnection2", etc all declared and opened in his application !
And of course, since this code actually does NOTHING, and none of these ever get closed, that makes it all even worse.
A true classic.
I'd love to see more of this code ... it's amazing how there's not even a shred of understanding about the most basic of programming concepts present in this code ...
Admin
Why do so many people have a problem with a tool which admittedly can be abused, but not half as much as dozens of things in C++ and other languages?
Let's look at an example - log all the attributes of a bunch of files in a directory as you try to move them elsewhere.
Try/Catch scenario psuedocode:
try (get list of files)
try (loop through files)
try (log some file attributes)
try (log some more attributes)
try (log permissions)
try (copy file)
try (delete file)
end loop
Also remember that those 'try()'s expand into full Try/Catch structures where essentially all you do is discard the error and carry on. Surely there's a better and quicker way to do that with the same result?
Resume next scenario pseudocode:
on error resume next
get list of files
loop through files
log all details
copy file
delete file
end loop
Now isn't that a hell of a lot easier? Yes. Any problems caused? Not really, since we were discarding errors anyway. Before anyone moans that I'm making more work in the Try/Catch case, remember how granular NTFS permissions are. You may very well have permissions to some file info but not something else. Resume next means not having to read and discard errors for things like that.
It's not how you should do everything, but it has very valid reasons, the above being just one and probably not one of the best examples, either. Now, let's have less stupidity from elitist morons.
Admin
Just one little change to the project would have prevented this from compiling - turn Strict On. No VB.NET project should be without it!! [;)]
Admin
It's like C code I run into where the return type of the function is void.
void foo()
{
.
. miles of bad code
.
return;
}
Admin
Way, way back in the day (circa 1979), on a DEC RSTS/E OS, returning a string to execute a system dispatch Was The Way Things Were Done, like:
A$=SYS(CHR$(13)+...)
IF A$="" THEN PRINT "SYSTEM CALL ERROR" ELSE...
Yes, RSTS used BASIC for system utilities. Doubt that the author of the original code knew that, but it explains more about VB than I wanted to know: Microsoft's original business was writing BASIC interpreters using DEC hardware to cross-compile.
Admin
I'm pretty sure this is just code migrated from ASP to ASP.NET. There was probably a call to Exec() around the string. When they tried to compile it in .NET they saw the error "Name 'Exec' is not declared" and took out the Exec. Voila, it compiles!
Of course, it should have occurred to whoever took out the Exec that this function was no longer doing anything. Still, the variable naming is an even bigger WTF. Somewhere in that app, there's a set of global variables declared like:
Dim sqlConnection1
Dim sqlConnection2
Dim sqlConnection3
Dim sqlConnection4
Dim sqlConnection5
Dim sqlConnection6
...
Dim sqlConnection255
...
Yeah. We really need to see some more of this code.
Admin
Meant to say "Eval", not "Exec".
Admin
Plausible scenario, like the earlier theory that it came from VBScript, but what about the fact that ReturnStatus is declared as integer? Either in porting they changed it from string (WTF!), or it never worked in ASP to start with (WTF^2!). Right?
--RA
Admin
WTF??? If I saw the above C code I would assume the programmer is a stupid VB coder.
Lets analyse your example.
try (get list of files) --- if this fails, we shouldn't loop
try (loop through files) --- why would this fail? oh yes because we didn't check the error on the previous line
try (log stuff) --- Hmmm, logging didn't work, we'll ignore it
try (copy file) --- Hmmm, copy didn't work, we'll ignore it
try (delete file) --- But the delete did work, so now we have no log, no copy, no original and no explanation
end loop
Gee you're right, bad programmers can write bad code in any language.
Admin
vomit
Admin
It's not VB.NET, mind you. It's Visual Basic 6.
Admin
Sadly .. it actually is VB.NET ... I have another example from this project I'll be posting sometime later. One tell-tale sign is the use of the Return keyword. VB6 does not support it.