- 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 see dead people.
Brain-dead, that is.
Admin
From a n00bs perspective, if something is indented that far, you must be doing something wrong.
CAPTCHA: "Ewww" Damn Straight :P
Admin
"Else Continue For"
When the end of the loop just isn't fast enough
Admin
Admin
If only VB had a way to break out of a for loop without a goto...
Oh wait, it does.
Admin
wow.
captcha: burned - i'm a witch?
Admin
ze goggles, zey do notting!
Admin
Ow! My EYES!!
When mom said I'd go blind, she didn't say it would be from looking at too many WTFs!
Admin
Question for someone who knows VB:
Is this use of the = operator an assignment in VB, as it would be in C? If so, what is the truth value of an assignment in VB?
Admin
I see a gun to shoot yourself in the foot.. ^_^
Admin
Yeah, that would be "Exit For". The funny thing is, before VB.NET 2005 (which this code obviously uses), there was no "Continue For".
I've seen VB code where they use gotos instead of loops. Throw in a bunch of global variables and you have some fun code to maintain.
Admin
Assuming that n (possibly an error counter?) starts out as 0, then the first time it's incremented would be the last, as it then GoTo CloseCmd: which then kills the whole thing. However, maybe n is already > 0, in which case, for some unknown reason, it's ok to just keep running the loop?? I don't get it. I wish there was more to look at but then again I have finished my coffee,
Admin
No one else think that basing the entire logic around a specfic exception is pretty barmy? Or is that sort of thing so common in a wtf that we don't blink anymore? :P
Admin
No, the = operator is overloaded for comparision and assignment depending on context.
Admin
if a = b 'conditional
a = b 'assignment
vb as lot of these weird quirks
Admin
Will: (re: 'If n = 0' ...)
This is not an assignment. In VB (and VB.NET, which is what this WTF is written in), = is either assignment or equality depending on the context.
If Foo = 1 Then ' <-- Equality Foo = 2 ' <-- Assignment End If
Perhaps not the best idea, but historically it's been that way, and they kept it in the move to .NET.
Admin
In this context the = is a comparison operator. Basically the first = you find is a assignment all others are comparisons, but this happens only within their own context.
If x = y and a = b
The context for each is separate so they are both comparison operators, the IF precedes the first operation.
It is overloaded as a comparison and an assignment and can lead to some really strange code. i.e.
dim x as boolean = false dim y as int = 1 dim z as int = 2
x = y = z x = (y = z)
Just try to grok that and tell me what the value of x is in each case.
Admin
Reason 1 : If ex.Message = "Invalid column name 'Result'." Then
Reason 2 : GoTo CloseCmd
Reason 3 : Continue For
Reason 4 : it's VB
Admin
s/wierd quirks/reasons to rue ever working with it/
Admin
haha, that's really bad :D
not as bad as the name change but hey
Admin
I mean the way that they're breaking out ofc, not just "oh god, they're breaking a for :o!!"
...editing?
Admin
Boy, talk about hard to explain VB quirks.
I totally messed up the If statement in my explanation. The correct part, The first operation is always an assignment all others are comparisons.
If x = y and a = b
The If statement is the first operation that wraps the other two giving the rvalue an assignment of either true or false. This makes the other two fall into the second category of comparison operators.
In my examples: x = y = z x = (y = z)
x is false in both cases as the first equals is the assignment and the second is always a comparison regardless of the parentheses.
Admin
looks like Marvin the Martians de-atomizer to me.
Admin
Someone enlighten this old-schooler.
Are you seriously telling me that GOTO has not been removed from the BASIC language in the last 20 years?
Can you also still PEEK and POKE?
Admin
dbreader2 is never used.
from memory n is only in scope in the exception clause so n=1 would have done just fine. Nothing is done with n either.
compare with message rather than error code - an interesting approach m'lud.
Even if it had worked iterating through a collection of database statements and 'randomly' throwing some away. I can only guess at the logic "If no customers found don't show their details, now query db for orders belong to the customers I didn't find earlier, now compute average delivery time by parcel wait for the orders i didn't find for the customers who didn't exist'.
Niall
Admin
s/wait/weight/
though it makes as much sense.
Admin
Thanks, everyone, for clearing up the comparison/assignment thing and for confirming that my decision not to use VB for anything ever was a good one.
Admin
Admin
Everytime you use a GoTo, God kills a puppy.
Admin
No, that stood out more than the rest of it for me. Bonus: The logic isn't based on an error code, but on the text. Oh, I'm sure that won't change when you upgrade MDAC, connect to a different server, etc.
Admin
Well... Since it is a code snipped, you cannot tell whats (realy) happening to the reader. Also n is not defined in the context of that snipped, so it means its scope must be bigger then that what was posted here.
Another point is that not the statements are thrown away... Its only the results that noone cares about.
Besides that, the code is still stupid ;)
Admin
Meh, SQL does the same thing, as do other languages, I'm sure. It's not that big of a WTF. Just because it's not like C or Java doesn't make it completely crazy.
Admin
Just three reasons, you say?
Maybe there's more... it really is like a Rorschach test - the more you look, the more errors start to appear.
Admin
Right, like this code is awful because it's VB, not because the coder didn't know what he was doing. You could do the same thing in, say, C#.
I'm not quite sure what the big deal is about overloading = is. Sure, I prefer the C-like == vs =, but it's not like the statement If a = b Then a = 2 is going to confuse a whole lot of people.
Admin
If there's one thing I've learned from this site, it's this: There hasn't been a language developed in which bad code can not be written.
In fact -- and this ought to give you C elitists indigestion -- I'm currently converting several C-language programs TO Visual Basic. Why? Because they are unmaintainable garbage with constructions that would make Kernighan and Ritchie turn to GOTO for better clarity.
You use the tool that works best for the job.
(Proud VB coder since 1992. TRS-80 BASIC before that.)
Admin
GOTO is also still in all descendants of C, including C#.
PEEK and POKE are gone though....
Admin
Yeah -- I was so stunned by the attempt to actually do something useful with an exception thrown by the database that I missed the whole goto/continue wierdness. I mean, if your database code is so whacked that you consider exceptions as non-catastrophic and part of your typical process flow, then that's truly Worse Than Failure...
Admin
heh , true especially if you try to use vb and another language. no good comes from that
Admin
Enough with the VB bashing, kids, lets try something a little more original. And remember: if you truly, honestly feel that if you are forced to use VB that you will be forced to write bad code, then that pretty much says it all about your programming skills.
It's the programmer, not the language, let's all try to focus on what the programmer did, stop blaming the tools and making excuses, and move on.
I am issuing a challenge to all subsequent posters to actually be relevant, intelligent, creative and original. Let's see how that works out. (Based on this forum's history, I suspect not so good, but maybe I'll be surprised ....)
Admin
RobertB: I'm with you. People on this site love to think they're witty when they pull out the old "the real WTF was using VB!" chestnut. Frankly, it's an old, tired joke that says more about the (often ill-conceived) preconceptions of the person who posts it than the inherent goodness or badness of the language.
The fact is, this code could exist easily in C++, C#, or Java, just to name a few -- there is nothing about it that is specific to VB.
VB is simply a tool, and people do terrible things with all sorts of tools all the time. When that happens, it's not the tool's fault, especially not in this case -- everything that's wrong with this relies on language features available in most modern languages.
Admin
Well, I've never used VB, so I can't say that I hate it. I can say that what I've seen of it makes me not want to start using it.
Admin
hmmm... is the guy using Option Strict On? I'm guessing not.
Admin
I don't know if you realized, the "Continue For" was in the catch block. If you didn't include it, then the loop would automatically exit.
Still, not the best programming...
Admin
Admin
dim j as string = "wtf" dim k as string = "omg" if (j = k) then writeline("equal") else writeline("not equal" end if
is the same as If (j.equals(k)) then 'etc ...
:-D
Admin
I'd love to see the first time thezy deploy this program in a language other than English and the text of the error message changes. And, having been a support tech myself, I pity the support people who try to reproduce the problem on their machines with an English locale...
Admin
no-one seems too bothered that none of the database connections are not getting closed explicity.
Admin
Uhm, there is no real(tm) exception handling in VB. So using goto to write an exception handler is perfectly fine. Of course, in that case you're supposed to use goto in the context of OnError Goto, so it really doesn't excuse this particular wtf, but as a BASIC practice (harhar) it is a favorable pattern (it's obviously worse to stick your error handler smack in the middle of the loop or if block).
Admin
VB BASHING RULES
If you'd like to be "witty" and "original" and "clever" and bash VB in a response, you MUST first answer this question before your post:
If you are forced to use VB.NET (or VB6 or VBA or even VBScript) to write a fairly complex program, would you be able to write code that not only works reliably but that is also clean, maintainable and efficient?
Answer that question first ( a simple yes or no is fine), and then bash away with your original, witty anti-VB statements.
(hint: if you say "no", then that says it all about your programming skills -- you are either a pretty horrible programmer, or you don't have sufficient knowledge of VB so you have no business criticizing it. If you say "yes", then you have no business bashing VB because you just demonstrated that it is the programmer, not the language.)
Thanks!
Admin
And don't forget stored procedures: