• tharfagreinir (cs)

    I see dead people.

    Brain-dead, that is.

  • Matt (unregistered)

    From a n00bs perspective, if something is indented that far, you must be doing something wrong.

    CAPTCHA: "Ewww" Damn Straight :P

  • DOA (unregistered)

    "Else Continue For"

    When the end of the loop just isn't fast enough

  • vt_mruhlin (cs)
    If n = 0 Then n = n + 1
    n = n + 1 + 27 - 27 + (384 * 0) Useless arithmetic is fun!
  • dave (unregistered)

    If only VB had a way to break out of a for loop without a goto...

    Oh wait, it does.

  • jack (unregistered)

    wow.

    captcha: burned - i'm a witch?

  • zack (unregistered)

    ze goggles, zey do notting!

  • Mark (unregistered)

    Ow! My EYES!!

    When mom said I'd go blind, she didn't say it would be from looking at too many WTFs!

  • Will (unregistered)

    Question for someone who knows VB:

    If n = 0

    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?

  • WIldpeaks (cs)

    I see a gun to shoot yourself in the foot.. ^_^

  • burnmp3s (cs) in reply to dave
    dave:
    If only VB had a way to break out of a for loop without a goto...

    Oh wait, it does.

    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.

  • haldiggs (cs)

    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,

    • Hal Diggs
  • cruise (unregistered)

    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

  • rStacey (unregistered) in reply to Will
    Will:
    Question for someone who knows VB:
    If n = 0

    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?

    No, the = operator is overloaded for comparision and assignment depending on context.

  • forgeten (unregistered) in reply to Will

    if a = b 'conditional

    a = b 'assignment

    vb as lot of these weird quirks

  • dyslexia (unregistered) in reply to Will

    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.

  • KattMan (cs) in reply to Will
    Will:
    Question for someone who knows VB:
    If n = 0

    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?

    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.

  • VB (unregistered)

    Reason 1 : If ex.Message = "Invalid column name 'Result'." Then

    Reason 2 : GoTo CloseCmd

    Reason 3 : Continue For

    Reason 4 : it's VB

  • Volmarias (cs) in reply to forgeten
    forgeten:
    if a = b 'conditional

    a = b 'assignment

    vb as lot of these weird quirks

    s/wierd quirks/reasons to rue ever working with it/

  • jon (unregistered)

    haha, that's really bad :D

    1. It doesn't do anything with DbReader2
    2. Column name 'Result'
    3. The n = n + 1
    4. Breaking out of For
    5. I'ts VB

    not as bad as the name change but hey

  • jon (unregistered)

    I mean the way that they're breaking out ofc, not just "oh god, they're breaking a for :o!!"

    ...editing?

  • KattMan (cs) in reply to Volmarias

    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.

  • gruckiii (unregistered)

    looks like Marvin the Martians de-atomizer to me.

  • Licky Lindsay (cs)

    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?

  • Niall (unregistered)

    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

  • Niall (unregistered) in reply to Niall

    s/wait/weight/

    though it makes as much sense.

  • Will (unregistered)

    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.

  • Dave C. (unregistered) in reply to rStacey
    rStacey:
    No, the = operator is overloaded for comparision and assignment depending on context.
    A huge WTF right there.
  • lizardfoot (cs)

    Everytime you use a GoTo, God kills a puppy.

  • Dave C. (unregistered) in reply to cruise
    cruise:
    No one else think that basing the entire logic around a specfic exception is pretty barmy?

    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.

  • rdrunner (cs) in reply to Niall
    Niall:
    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

    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 ;)

  • Nat5an (cs) in reply to Dave C.
    Dave C.:
    rStacey:
    No, the = operator is overloaded for comparision and assignment depending on context.
    A huge WTF right there.

    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.

  • Aaron (unregistered)

    Just three reasons, you say?

    1. Mystery meat variables - "DbReader2" and "n";
    2. Eating the global Exception without any logging;
    3. Comparing the text of an exception message within a catch block;
    4. Comparing the text to a hard-coded string;
    5. Using an exception to detect a condition that could easily have been detected some other way (syscolumns, information_schema);
    6. Using "n = n + 1" when "n" is already known to be zero. In fact, "n" can never be anything other than 0 or 1, at least not in the code shown, so a boolean value should have been used instead.
    7. Use of "goto";
    8. Use of "goto" within an exception handler...!
    9. Use of "continue" when there is nothing to bypass.
    10. Overwriting the DB reader on each iteration without actually reading anything (just use ExecuteNonReader()).

    Maybe there's more... it really is like a Rorschach test - the more you look, the more errors start to appear.

  • Jojosh_the_Pi (cs)
    vb is shit why does it still exist *carves out eyes with rusty spoon*

    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.

  • RobertB (cs) in reply to Will
    Will:
    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.
    Why all the VB hate? A poster in a previous discussion summed it up nicely: "A poor workman blames his tools".

    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.)

  • Scott (unregistered) in reply to Licky Lindsay
    Licky Lindsay:
    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?

    GOTO is also still in all descendants of C, including C#.

    PEEK and POKE are gone though....

  • JTK (unregistered) in reply to Dave C.
    Dave C.:
    cruise:
    No one else think that basing the entire logic around a specfic exception is pretty barmy?

    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.

    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...

  • forgeten (unregistered) in reply to Volmarias

    heh , true especially if you try to use vb and another language. no good comes from that

  • Jeff S (cs)

    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 ....)

  • dyslexia (unregistered) in reply to RobertB

    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.

  • Will (unregistered) in reply to RobertB
    RobertB:
    Why all the VB hate? A poster in a previous discussion summed it up nicely: "A poor workman blames his tools".

    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.

  • SilentTim (unregistered)

    hmmm... is the guy using Option Strict On? I'm guessing not.

  • strickdd (unregistered) in reply to DOA

    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...

  • Marcin (unregistered) in reply to Nat5an
    Nat5an:
    Dave C.:
    rStacey:
    No, the = operator is overloaded for comparision and assignment depending on context.
    A huge WTF right there.

    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.

    Defend this statement. Please show me a valid sql query which has assignment.

  • GeneWitch (cs) in reply to Will
    Will:
    Question for someone who knows VB:
    If n = 0

    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?

    VB pretends (and usually is) smart enough that you never see "=="... at least if my memory serves

    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

  • Martin (unregistered)

    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...

  • w'ever (unregistered)

    no-one seems too bothered that none of the database connections are not getting closed explicity.

  • cowbert (unregistered) in reply to JTK
    JTK:
    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...

    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).

  • Jeff S (cs)

    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!

  • RobertB (cs) in reply to Marcin
    Marcin:
    Nat5an:
    Dave C.:
    rStacey:
    No, the = operator is overloaded for comparision and assignment depending on context.
    A huge WTF right there.

    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.

    Defend this statement. Please show me a valid sql query which has assignment.
    Here's an example of an assignment and a comparison in a simple SQL query.

    Select PseudoFieldName = 'Some value'
    From TableName
    Where Something = Nothing

    And don't forget stored procedures:

    Declare @x int, @y int
    Select @x = 2, @y = 2
    If @x + @y = 5
       Select RetVal = 'For sufficiently large values of 2'
    Else
       Select RetVal = 'You took the blue pill'
    

Leave a comment on “Visual Basic Triple Play”

Log In or post as a guest

Replying to comment #:

« Return to Article