• MP79 (unregistered)

    oh VB, when will they ever learn

  • moogletrop (unregistered)

    Line numbers? Are they mad? Surely labels are the way forward?

  • Mike (unregistered)

    This was obviously ported from Apple 2 BASIC. Not a wtf.

  • modo (unregistered)
    Learning Something New:
    Sub dwb_eng()
        ActiveSheet.Unprotect
        Let i = Range("a!Q7").Value
        If i = 1 Then GoTo 100 Else GoTo 200
    100 ActiveSheet.Shapes("Option Button 22").Visible = True
        GoTo 300
    

    200 ActiveSheet.Shapes("Option Button 22").Visible = False 300 ActiveSheet.Protect End Sub

    There is nothing wrong with using GoTo for an If statement if the language supports it. The sample code is clean and understandable, has a single entry point and a single exit point.

    That said, TRWTF is VBA.

  • Sean (unregistered) in reply to Mike

    Obviously with "Let i =" in there!

  • (cs)
    TFA:
    And line numbers, too. And for whatever reason, those are preferred to a simple If-Else block.
    Are you blind? It uses a simple if-else block.
    If i = 1 Then GoTo 100 Else GoTo 200
    See?
  • uxor (unregistered) in reply to moogletrop
    moogletrop:
    Line numbers? Are they mad? Surely labels are the way forward?
    VBA uses labels, so those aren't really line numbers, they are numeric labels.
  • anonymous_coder() (unregistered) in reply to uxor
    uxor:
    moogletrop:
    Line numbers? Are they mad? Surely labels are the way forward?
    VBA uses labels, so those aren't really line numbers, they are numeric labels.

    And that makes it better how?

    The only GOTOs that should be used are in very low level code - I mean C, Assembler, and those benighted languages that were designed for punch cards and coding sheets.

  • (cs) in reply to modo
    modo:
    There is nothing wrong with using GoTo for an If statement if the language supports it.
    Not if you're using the goto to emulate a control structure that the language already has. Not if you could replace all that crap with a single line that assigns the boolean result of a test directly.

    Sometimes people just work far too bloody hard.

  • (cs)
    Sub dwb_eng()
        ActiveSheet.Unprotect
        ActiveSheet.Shapes("Option Button 22").Visible = Range("a!Q7").Value * True
        ActiveSheet.Protect
    End Sub

    The slightly-less WTF version. Might not need that * True, not sure, haven't done BASIC in a while.

  • (cs) in reply to modo
    modo:
    Learning Something New:
    Sub dwb_eng()
        ActiveSheet.Unprotect
        Let i = Range("a!Q7").Value
        If i = 1 Then GoTo 100 Else GoTo 200
    100 ActiveSheet.Shapes("Option Button 22").Visible = True
        GoTo 300
    

    200 ActiveSheet.Shapes("Option Button 22").Visible = False 300 ActiveSheet.Protect End Sub

    There is nothing wrong with using GoTo for an If statement if the language supports it. The sample code is clean and understandable, has a single entry point and a single exit point.

    That said, TRWTF is VBA.

    How about using goto within an if statement in place of just putting the code there?

    If you think VBA is TRWTF, wait until they roll out C#A.

    Addendum (2010-11-24 12:17): Doh! Disregard that.

  • Jason Y (unregistered)

    One goto that I'm fine with is in a switch statement in C#, like this: http://www.cookcomputing.com/blog/archives/000385.html. This is safer than fall-through switch statements, I dare say.

    Anywhom, it looks like time to refactor, eh?

  • Brian Manahan (unregistered) in reply to modo
    modo:
    There is nothing wrong with using GoTo for an If statement if the language supports it.

    Yes, yes there is.

  • Carlos M (unregistered)

    We did some pretty complex things in VBA (Excel and Visio) that we are proud of. Of course, we only do VBA when it produces the best solution for the end user, unlike some people that do VBA because they fail at real languages like Java or Ruby and their corresponding architectures.

  • Whatever (unregistered) in reply to The MAZZTer
    The MAZZTer:
    Sub dwb_eng()
        ActiveSheet.Unprotect
        ActiveSheet.Shapes("Option Button 22").Visible = Range("a!Q7").Value * True
        ActiveSheet.Protect
    End Sub

    The slightly-less WTF version. Might not need that * True, not sure, haven't done BASIC in a while.

    From: user To: support<The [email protected]> Subject: Bug in CMCalc Description: One of my option buttons has dissappeared, and I get a warning pop-up that says "FILE_NOT_FOUND".

  • (cs) in reply to modo
    modo:
    There is nothing wrong with using GoTo for an If statement if the language supports it.
    Yes there is. Just because a language supports something doesn't mean it's okay to use it.
    modo:
    The sample code is clean and understandable, has a single entry point and a single exit point.
    Your idea of clean certainly differs from my own. I suppose since it's only a few lines, I'd agree that it's understandable. Though you'd probably agree that without the GoTo statements, it could easily be cleaner and more understandable, amirite?

    Still, if it's at all representative of the rest of the application (as the submitter implies it is), then you can bet there are probably larger modules using much more complex if-goto-else-goto spaghetti logic.

    modo:
    That said, TRWTF is VBA.
    Well, I do suppose we can agree on that.
  • The Ancient Programmer (unregistered)

    Obviously being paid by the number of lines of code.

  • airdrik (unregistered) in reply to Jason Y
    Jason Y:
    One goto that I'm fine with is in a switch statement in C#, like this: http://www.cookcomputing.com/blog/archives/000385.html. This is safer than fall-through switch statements, I dare say.

    Anywhom, it looks like time to refactor, eh?

    Yes, instead of using goto so that common code in different case blocks get executed by other cases, move the common code to simple methods which are called by the case blocks - no code duplication, no flowing between case blocks and no goto's.

  • (cs) in reply to dkf
    dkf:
    modo:
    There is nothing wrong with using GoTo for an If statement if the language supports it.
    Not if you're using the goto to emulate a control structure that the language already has. Not if you could replace all that crap with a single line that assigns the boolean result of a test directly.

    Sometimes people make their successors work far too bloody hard.

    FTFY.

  • CK (unregistered)

    Yeah, this is a fail. Trash goto statements all you want. I don't like them either.

    However, those aren't line numbers... those are labels.

    Face palm.

  • V.B.King (unregistered) in reply to Carlos M

    "they fail at real languages like Java or Ruby"

    Real languages? Don't listen, folks! Java and Ruby are just a fad! VB/VBA is still rockin' the kingdom!

  • MASSIVE SNIP (unregistered) in reply to uxor
    uxor:
    moogletrop:
    Line numbers? Are they mad? Surely labels are the way forward?
    VBA uses labels, so those aren't really line numbers, they are numeric labels.

    And most programming languages will support my calling functions adasdadasd() and func1002(). It doesn't make it a good idea.

  • (cs) in reply to Brian Manahan
    Brian Manahan:
    modo:
    There is nothing wrong with using GoTo for an If statement if the language supports it.

    Yes, yes there is.

    What is it? The only real issue with GOTO is that, if you use it incorrectly, it can result in some screwy logic (e.g 10 goto 20 goto 50 goto 40 goto 10) making the code error prone and hard to maintain.

    In this case it's perfectly linear, and reasonably clear. I certainly wouldn't complain if I saw it, though I'd probably think it was a little weird.

  • Spearhavoc! (unregistered)

    I still haven't found a language that supports the next big thing in flow control: WENTTO.

    As in, if WENTTO 100 then GOTO 300.

    Simple and easy to understand, just as best practices dictate.

  • refoveo (unregistered)

    I work a lot with legacy code, and the sample shown is actually pretty good for code over 10 years old.

    So, I tried to find where the WTF was in the article, and found it:

    Learning Something New:
    a spreadsheet designed by an end-user who knew too much that was coded by a developer who thought he knew a lot, and maintained over a decade by developers who mostly knew nothing.

    The problem is the developers maintaining the application that mostly know nothing, including the submitter, "Will".

  • moogletrop (unregistered)

    It was a joke, but since a couple of you insist on being smart arses, from MSDN:

    GoTo Statement

    Branches unconditionally to a specified line within a procedure.

    Syntax

    GoTo line

    The required line argument can be any line label or line number.

    Remarks

    GoTo can branch only to lines within the procedure where it appears.

    Note Too many GoTo statements can make code difficult to read and debug. Use structured control statements (Do...Loop, For...Next, If...Then...Else, Select Case) whenever possible.

    line label Used to identify a single line of code. A line label can be any combination of characters that starts with a letter and ends with a colon (:). Line labels are not case sensitive and must begin in the first column.
    line number Used to identify a single line of code. A line number can be any combination of digits that is unique within the module where it is used. Line numbers must begin in the first column.

    In case you missed it, the syntax does indeed differ.

  • SpudTater (unregistered)

    Oh wow! That's the sort of logic I wrote for BASIC on the BBC Master, back when I was about 8. There wasn't any ELSE or WHILE, or... pretty much anything really. I still thought it was fantastic, though.

    Ah, the nostalgia.

  • conventio (unregistered) in reply to MASSIVE SNIP
    MASSIVE SNIP:
    And most programming languages will support my calling functions adasdadasd() and func1002(). It doesn't make it a good idea.
    How are either of those better or worse than dwb_eng()?
  • (cs)

    Clearly, someone found out what the B in VB stands for and was being a smartass about it.

  • by (unregistered) in reply to modo
    modo:
    Learning Something New:
    Sub dwb_eng()
        ActiveSheet.Unprotect
        Let i = Range("a!Q7").Value
        If i = 1 Then GoTo 100 Else GoTo 200
    100 ActiveSheet.Shapes("Option Button 22").Visible = True
        GoTo 300
    

    200 ActiveSheet.Shapes("Option Button 22").Visible = False 300 ActiveSheet.Protect End Sub

    There is nothing wrong with using GoTo for an If statement if the language supports it. The sample code is clean and understandable, has a single entry point and a single exit point.

    That said, TRWTF is VBA.

    Clean an understandable? I think I need eye bleach after seeing that...

    Just because a language supports a certain construct, does not mean that you should use it especially if there is nothing to gain. In fact you loose readability and make it brittle because somewhere else there may be a line of code pointing to that GOTO (which for whatever reason you removed), but you'd never know until a runtime error is thrown.

  • Anonymous (unregistered) in reply to Spearhavoc!
    Spearhavoc!:
    I still haven't found a language that supports the next big thing in flow control: WENTTO.

    As in, if WENTTO 100 then GOTO 300.

    Simple and easy to understand, just as best practices dictate.

    How about COMEFROM? Lots of fun to be had!

    As for today's WTF, sometimes all you can do is sigh. Unless you work with these people, in which case "Horrific Workplace Shooting" should be dominating the headlines tomorrow.

  • Bob (unregistered) in reply to modo
    modo:
    There is nothing wrong with using GoTo for an If statement if the language supports it. The sample code is clean and understandable, has a single entry point and a single exit point.

    I was going to post your current score but I lost count.

    Anyway, modo wins.

  • Anonymous (unregistered) in reply to modo
    modo:
    There is nothing wrong with using GoTo for an If statement if the language supports it. The sample code is clean and understandable, has a single entry point and a single exit point.
    2/10 for this troll. Way too obvious. It would have been a 1 but you get an extra point for the fact that some people have actually bitten, amazingly.
  • inhibeo (unregistered) in reply to moogletrop
    moogletrop:
    It was a joke, but since a couple of you insist on being smart arses, from MSDN:
    GoTo Statement

    Branches unconditionally to a specified line within a procedure.

    Syntax

    GoTo line

    The required line argument can be any line label or line number.

    Remarks

    GoTo can branch only to lines within the procedure where it appears.

    Note Too many GoTo statements can make code difficult to read and debug. Use structured control statements (Do...Loop, For...Next, If...Then...Else, Select Case) whenever possible.

    line label Used to identify a single line of code. A line label can be any combination of characters that starts with a letter and ends with a colon (:). Line labels are not case sensitive and must begin in the first column.
    line number Used to identify a single line of code. A line number can be any combination of digits that is unique within the module where it is used. Line numbers must begin in the first column.

    In case you missed it, the syntax does indeed differ.

    Do you remember when every line of code in a Basic program was required to have a line number? I do.

    Since VBA line numbers are optional and can be used out of sequence, they are really nothing more than numeric labels, despite the name used in the MSDN documentation.

  • pel (unregistered) in reply to moogletrop

    groin kick

    That was NOT funny. I believe that you were aiming for 'funny' but all I got was feeling similar to chewing tinfoil and nails against a black board.

  • Jerry (unregistered)

    I know we're all adults here, but if anyone doesn't "get it" yet why gotos are bad, here's one reason:

    10 ...dostuff... goto 100

    40 ...otherstuff... goto 100

    ...blah... 100 ...more...

    Now... since we all know code expands to fill the available space (which is, for all practical purposes, infinite), this will eventually get too complicated to fit on one screen, or, perhaps, even into one brain. Then, as you're debugging the "...more..." stuff after 100, the question inevitably arises: how did I get here? Was it from "dostuff" or "otherstuff"?

    This is why every language with "goto" also needs "camefrom". As in:

    if camefrom = 40 then ... and so on...

  • moogletrop (unregistered) in reply to inhibeo
    inhibeo:
    moogletrop:
    It was a joke, but since a couple of you insist on being smart arses, from MSDN:
    GoTo Statement

    Branches unconditionally to a specified line within a procedure.

    Syntax

    GoTo line

    The required line argument can be any line label or line number.

    Remarks

    GoTo can branch only to lines within the procedure where it appears.

    Note Too many GoTo statements can make code difficult to read and debug. Use structured control statements (Do...Loop, For...Next, If...Then...Else, Select Case) whenever possible.

    line label Used to identify a single line of code. A line label can be any combination of characters that starts with a letter and ends with a colon (:). Line labels are not case sensitive and must begin in the first column.
    line number Used to identify a single line of code. A line number can be any combination of digits that is unique within the module where it is used. Line numbers must begin in the first column.

    In case you missed it, the syntax does indeed differ.

    Do you remember when every line of code in a Basic program was required to have a line number? I do.

    Since VBA line numbers are optional and can be used out of sequence, they are really nothing more than numeric labels, despite the name used in the MSDN documentation.

    Yep, my first foray into programming was BBC BASIC.

    I don't care what they compile to nor how the language uses them, there are two different constructs here, you were inaccurate.

  • Chelloveck (unregistered) in reply to conventio
    conventio:
    MASSIVE SNIP:
    And most programming languages will support my calling functions adasdadasd() and func1002(). It doesn't make it a good idea.
    How are either of those better or worse than dwb_eng()?

    dwb_eng() is a very clear mnemonic. It refers to the author, a DWeeB_ENGineer.

  • quibus (unregistered) in reply to Chelloveck
    Chelloveck:
    dwb_eng() is a very clear mnemonic. It refers to the author, a DWeeB_ENGineer.
    +1
  • (cs) in reply to Satanicpuppy
    Satanicpuppy:
    Brian Manahan:
    modo:
    There is nothing wrong with using GoTo for an If statement if the language supports it.

    Yes, yes there is.

    What is it? The only real issue with GOTO is that, if you use it incorrectly, it can result in some screwy logic (e.g 10 goto 20 goto 50 goto 40 goto 10) making the code error prone and hard to maintain.

    In this case it's perfectly linear, and reasonably clear. I certainly wouldn't complain if I saw it, though I'd probably think it was a little weird.

    One could easily place the lines one is GoingTo in the if-else itself. Here, the GoTo is completely unnecessary, demonstrates a lack of understanding of the language (specifically if-else blocks), and clutters up what would have been some pretty clear and concise code.

    Although, the code works, and that's all that really matters. I certainly would complain if I saw it, but I'd probably just leave it alone (though I'd certainly be inclined to send a copy to this site, as the submitter did).

  • (cs)

    I've been coding in VBA since Office for Windows 95 came out and, while I'm sure I have written my share of WTF, I have never written anything that stupid. I wonder if the original coder thought he was being funny.

  • saluto (unregistered) in reply to by
    by:
    Just because a language supports a certain construct, does not mean that you should use it especially if there is nothing to gain. In fact you loose readability and make it brittle because somewhere else there may be a line of code pointing to that GOTO (which for whatever reason you removed), but you'd never know until a runtime error is thrown.
    MSDN:
    GoTo Statement Branches unconditionally to a specified line within a procedure.
    The GOTO in VBA can only go to a line within the same procedure. If your procedure is so large that you can't find a line of code using GOTO in it, you have a much bigger problem than using GOTO.
  • nobis (unregistered) in reply to rudraigh
    rudraigh:
    I've been coding in VBA since Office for Windows 95 came out and, while I'm sure I have written my share of WTF, I have never written anything that stupid. I wonder if the original coder thought he was being funny.
    The construct is actually a good way to program in Assembly language, which may be where the original coder learned it.
  • by (unregistered) in reply to Anonymous
    Anonymous:
    modo:
    There is nothing wrong with using GoTo for an If statement if the language supports it. The sample code is clean and understandable, has a single entry point and a single exit point.
    2/10 for this troll. Way too obvious. It would have been a 1 but you get an extra point for the fact that some people have actually bitten, amazingly.

    I saw this too, but had to reply anyway because some "developer" will see those comments and think that this is the correct way of doing things... And with my luck, I'll have to maintain their steaming pile of GOTOs. :(

  • by (unregistered) in reply to saluto
    saluto:
    by:
    Just because a language supports a certain construct, does not mean that you should use it especially if there is nothing to gain. In fact you loose readability and make it brittle because somewhere else there may be a line of code pointing to that GOTO (which for whatever reason you removed), but you'd never know until a runtime error is thrown.
    MSDN:
    GoTo Statement Branches unconditionally to a specified line within a procedure.
    The GOTO in VBA can only go to a line within the same procedure. If your procedure is so large that you can't find a line of code using GOTO in it, you have a much bigger problem than using GOTO.

    I think you just highlighted the fact that I've never really developed in VBA, or used labels, but the original point stands... Just because it supports the construct, doesn't mean you should use it as it turns the code from ugly, to evil (IMO).

  • causa (unregistered) in reply to moogletrop
    moogletrop:
    Line numbers? Are they mad? Surely labels are the way forward?
    moogletrop:
    I don't care what they compile to nor how the language uses them, there are two different constructs here, you were inaccurate.
    Looks like moogletrop wins for accuracy. TRWTF is using line numbers instead of line labels.
  • validus (unregistered) in reply to by
    by:
    I saw this too, but had to reply anyway because some "developer" will see those comments and think that this is the correct way of doing things... And with my luck, I'll have to maintain their steaming pile of GOTOs. :(
    If anyone uses GOTOs in new code, they should be shot. On the other hand, I don't mind maintaining legacy code that is as easy to read as this sample.
  • (cs) in reply to modo
    modo:
    There is nothing wrong with using GoTo for an If statement if the language supports it. The sample code is clean and understandable, has a single entry point and a single exit point.
    I really hope that was sarcasm.
  • iToad (unregistered)

    Fortran written in VBA. Cool...

  • (cs) in reply to da Doctah
    da Doctah:
    Clearly, someone found out what the B in VB stands for and was being a smartass about it.
    Featured Comment!

Leave a comment on “Learning Something New”

Log In or post as a guest

Replying to comment #:

« Return to Article