• (cs) 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.

    VBA was written in C/C++, so True for it is just 1. Which does nothing.

  • Gary (unregistered)

    Uh, even VB can handle this easy to understand oneliner. Hate the = for both comparison and assignment but what can you do?

    ActiveSheet.Shapes("Option Button 22").Visible = (Range("a!Q7").Value=1)

    TRWTF lies thoroughly with the developers for not understanding even the most basic patterns of the language.

  • (cs) in reply to Carlos M
    Carlos M:
    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.
    I use VBA when I'm forced to, or when I want dynamic column generation on a transformed and pivoted query (and am thus forced to use Access unless I want to roll my own transformer sp).
  • Andrew (unregistered) in reply to Spearhavoc!

    http://en.wikipedia.org/wiki/COME_FROM

    Close enough?

    Other gems are the "maybe" and "please do" flow control words.

    http://en.wikipedia.org/wiki/INTERCAL#Control_structures

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

    VBA was written in C/C++, so True for it is just 1. Which does nothing.

    Actually True is 0xffffffff. And is &. Or is |.

  • (cs)

    A more idiomatic VBA sub would look more like:

    Sub dwb_eng()
        With ActiveSheet
            .Unprotect
            .Shapes("Option Button 22").Visible = _
                (1 = Range("a!Q7").Value)
            .Protect
        End With
    End Sub
    

    Note the line continuation operator _

  • (cs) in reply to nobis
    nobis:
    The construct is actually a good way to program in Assembly language, which may be where the original coder learned it.

    The game of "leapfroggin' line numbers" in the code example isn't very good practice in assembly, either -- at least, if you're favoring raw performance over readability, and if you're not why are you writing assembly code anyway?

  • (cs)

    Looks like Dijkstra died in vain then...

  • silent d (unregistered) in reply to Anonymous
    Anonymous:
    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!

    Just use the BEENTHEREDONETHAT keyword.
  • immitto (unregistered) in reply to Maurits
    Maurits:
                (1 = Range("a!Q7").Value)
    
    +1

    Nice use of transposing the constant and the variable so the = sign can only compare values instead of accidentally assigning a value.

  • A Gould (unregistered) in reply to validus
    validus:
    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.

    Well, VBA requires GoTos to some extent for error handling ("On Error GoTo [label]"), but that's the only place I'd ever think of using it.

    As for the VB haters, while I'll happily agree that it's not my favorite language (I'd rather be working in one of the three or four other languages I know), it does have one undeniable advantage - it's baked in to Office, which makes it an easy choice when you need a smarter Excel sheet. And since the user still sees Excel, you don't get that "I don't want to learn something" pushback.

  • trwtf (unregistered) in reply to silent d
    silent d:
    Anonymous:
    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!

    Just use the BEENTHEREDONETHAT keyword.

    I usually prefer the "SSDD" keyword for setting up an infinite loop.

  • Oldtimer (unregistered) in reply to trwtf
    trwtf:
    silent d:
    Anonymous:
    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!

    Just use the BEENTHEREDONETHAT keyword.

    I usually prefer the "SSDD" keyword for setting up an infinite loop.

    What about ALTER in COBOL? This one was a real feature of a "serious" languange...

  • Nome de Plume (unregistered) in reply to Gary
    Gary:
    Uh, even VB can handle this easy to understand oneliner. Hate the = for both comparison and assignment but what can you do?

    ActiveSheet.Shapes("Option Button 22").Visible = (Range("a!Q7").Value=1)

    TRWTF lies thoroughly with the developers for not understanding even the most basic patterns of the language.

    I dislike the sound "to" for both two (2) and too (also). Yet, I can always tell them apart by parsing the grammar!

  • (cs) in reply to Oldtimer
    Oldtimer:
    What about ALTER in COBOL? This one was a real feature of a "serious" languange...

    some serious WTFs could come about from ALTERs, especially when you had a 'GO TO DEPENDING ON XXX' in the program where the targets were also targets of other ALTERs.

    It made for some hairy debugging.

  • (cs) in reply to Nome de Plume
    Nome de Plume:
    I dislike the sound "to" for both two (2) and too (also). Yet, I can always tell them apart by parsing the grammar!
    Fair enough, but some languages return a value from assignments as well as from comparisons*. In such cases it's really hard or even impossible for the computer to know exactly which you mean based on surrounding context. Since I don't write code as a means to communicate with people, that is kind of an important detail.
      • But I'm not sure how many also reuse the same operator for comparisons and assignments.
  • Todd Lewis (unregistered) in reply to Anonymous
    Anonymous:
    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!

    I like the GODO, as in "GODO 300,10" It goes to line 300, executes 10 statements, then returns here. Looking at the code at lines 300 and following, there's no hint that line 311 wouldn't be executed, or that some places may "GODO 300,10" while others would "GODO 300,5". wO0t.

  • patrick2901 (unregistered)
    Sub dwb_eng()
        ActiveSheet.Unprotect
        ActiveSheet.Shapes("Option Button 22").Visible = (Range("a!Q7").Value = 1)
        ActiveSheet.Protect
    End Sub

    does the job completely without any if-statement... I am so sad that most of the so-called software developers cannot handle simple boolean expressions.

  • Anonymous coward (unregistered) in reply to iToad

    looks just like some of the old (originally fortran 66) numerical modelling system I maintain every now and then. Much fun to be had with replacing similar code with if-then-else constructs that you get in fortran 77 (and no fortran 95 isn't allowed....)

  • (cs)

    Reminds me of the days when I wrote my first program on an Apple II...

    Except for the "else" part it was too advanced for basic. :)

  • Someone (unregistered)

    Where I work we have to maintain a multi thousand line excel monstosity. Essentially it allows fast maintenance of records in an oracle system. It has web connections to a servlet which returns xml which is parsed dumped into sheets, then formatted and placed on other sheets for people to edit. It also does the reverse.

    Some of the "cooler" features include a homemade XML parser which breaks if you pass it valid XML and full AD integration.

    I once found a comment in the code base along the lines of

    ' Be Afraid

    To which I added,

    ' I am. Very!

  • me (unregistered)

    10 PRINT "WHAT" 20 PRINT "THE" 30 PRINT "FUCK?" 40 GOTO 10 RUN

  • (cs)

    "for whatever reason, [IF x GOTO n] are preferred to a simple If-Else block"

    Because how would you indent the blocks without the line numbers looking messy?

  • SteveR (unregistered) in reply to Jerry

    "I know we're all adults here..." - I'm not sure on what evidence you based that statement. It is not at all clear from the actual discussion.

  • (cs)

    Today's WTF is somewhat subtle, but don't worry if you've missed it:

    an end-user who knew too much

    Enjoy your Thanksgiving holiday.

  • Mark Draughn (unregistered) in reply to validus
    validus:
    If anyone uses GOTOs in new code, they should be shot.
    Sometimes careful use of GOTO can really simplify a piece of code, especially when the language is lacking in modern error-handling control structures such as labeled loop exits, exceptions, or Finally blocks.
  • Luiz Felipe (unregistered) in reply to Jason Y

    why use a switch afer all?

    int x = 3; if (x==0) { // do something with 0 } if (x==1 || x==0) { // do something in common with 0 } // do something in common with 0, 1, and anything else

  • Luiz Felipe (unregistered)

    in reply for

        int x = 3; 
        switch (x)
        {
            case 0:
                // do something
                goto case 1;
            case 1:
                // do something in common with 0
                goto default;
            default:
                // do something in common with 0, 1, and anything else
            break;
        }
    
  • (cs) in reply to SpudTater
    SpudTater:
    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.

    You are wrong, sir. On the Internet, no less!

    BBC BASIC had ELSE (as long as it was on the same line as the IF), and its REPEAT ... UNTIL is basically a backwards WHILE loop. And it had real named subroutines (PROCs and FNs), which is more than you can say for pretty much any other 8-bit BASIC.

    I expect a full retraction, or I shall be forced to demand satisfaction.

  • Linda Kaioh (unregistered)

    Ok! Lt's continue anti VB hollywar! It's so professional and funny!

  • SurturZ (unregistered)

    Once upon a time in Microsoft BASIC (definitely for QuickBasic, not sure about pre-.NET VB), if your compiled program crashed, it would display the last line NUMBER that had been encountered by the runtime. Line labels didn't work.

    As such, if you found a piece of code where every line was numbered, rather than feeling some nostalgia for the days of the VIC-20, you would shiver in fear. It meant that a programmer had been trying to debug an intermittent crash that only occurred in the compiled executable.

  • Nitish (unregistered)

    Maybe someone's already said this above, but this is actually a decent alternative to convoluted Case-Switch statements I have had to use in VBA. Cleaner and you don't have to worry about how the statements might fall through. Goes to show that you can learn something from everything.

  • ysth (unregistered)

    Block? What is this "block" you mention?

  • ysth (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.

    Perl's Positronic::Variables module supports something like that. It hasn't reached CPAN yet (I think observers keep stopping it), but you can see most of the code in Damian Conway's "Temporally Quaquaversal Virtual Nanomachine Programming In Multiple Topologically Connected Quantum-Relativistic Parallel Timespaces...Made Easy!" talk.

  • tradie (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.

    That's clever. Wrong, but clever. The cleverness kind of hides the wrongness, doesn't it?

    Although actually, if we want to go for wrong, we could save even more typing, and achieve less cleverness and better clarity:

    Sub dwb_eng()
    End Sub
  • Anonymous Coder (unregistered)

    Yep, C64 and with its build in BASIC - well remembered. All line numbers plus GOTO and GOSUB - no control structures, not even an ELSE. And then there were these dreaded constructs: ON X GOTO 100, 200, 300 .... or even "better" ON X GOOSUB 100, 200, 300 .... Jumping in and out of sub-routines? Yes no problem, no problem at all. :)

    Along came the ATARI ST and the all new GFA-BASIC. Remember anyone? What a joy! GFA did away with line numbers all together. They added PASCAL like control stuctures and propper PROCEDUREs with declared parameters and return values. Was there a GOTO or a GOSUB? I don't remember, I never missed any of them - never. Not in any language I have encountered since.

  • DC (unregistered) in reply to A Gould
    A Gould:
    Well, VBA requires GoTos to some extent for error handling ("On Error GoTo [label]"), but that's the only place I'd ever think of using it.

    Actually, no it doesn't. You use 'On Error Resume Next' instead, and test for the error inline.

    Not quite Try..Catch but it sure beats those stupid GoTo error blocks.

  • Kempeth (unregistered)

    You can implement your own CAMEFROM like this:

    DIM camefrom AS INT(128)
    LET camefromi = -1;
    
    10: LET camefromi = camefromi + 1;
        LET camefrom(bar) = 10;
        GOTO dostuff
        LET camefromi = camefromi - 1;
        'do more stuff
    
    
        GOTO dostuffend
    dostuff:
        'do some stuff
        GOTO camefrom(camefromi)
    dostuffend:
    
  • Anonymous Coder (unregistered) in reply to Jerry

    Oh, the scope for abuse was virtually limitless:

    10 ...dostuff... 20 gosub 100 30 ...bla

    100 ...more...

    110 if a = 42 goto 10

    120 return

    or:

    10 for i=1 to 10 20 .. somt code 30 if a = 42 goto 100 40 next i .... 100 ... more nonsense 150 if x = 0 goto 20 ... (oh joy!)

    So the million dollar questions are: How long will it take before the stack overflows? When it happens, how to find the root cause and how to fix it? How can one be sure to spot something like that during "testing" - apart from running the program an infinite period of time?

    Hint: Lack of scope, lack of context.

  • UK_Aspie (unregistered)

    A real programmer can write FORTRAN in any language ...

  • Niels Rasmussen (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.

    TRWTF is C#

  • Matt Westwood (unregistered) in reply to moogletrop
    moogletrop:
    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.

    IIRC, BBC BASIC was a grown-up version which was evolving away from line numbers. There were techniques for writing it line-less. It also had better-structured IF and FOR.

    Bear in mind that all these constructs evolved ultimately from the Old Fortran (4?) construct "IF (condition) label1, label2, label3" where the labels were where the flow went to if condition was less than, equal to, greater than (in some combination, can't remember the details) the result of the condition.

    So I can easily understand where the code construct came from - someone had taught him/herself against an archaic programming manual from the days before these new-fangled structures had been invented.

    Also bear in mind that languages have evolved rapidly enough that someone whose career started way before the currently accepted structures were invented may not have had the time or opportunity to keep up with the industry. Kudos for anyone not a professional programmer for getting anything to work - may they be applauded.

    That being said, it ought to go without saying that when a professional programmer encounters such code, it is mandatory to replace such constructs as instanced in today's WTF with something a little more "contemporary". It's part of your maintenance remit. Go on, get on with it, stop whingeing about it. If you don't like what you've been requested to do, that's what Monster's for.

  • PleaseStopWritingCode (unregistered) in reply to DC
    DC:
    A Gould:
    Well, VBA requires GoTos to some extent for error handling ("On Error GoTo [label]"), but that's the only place I'd ever think of using it.

    Actually, no it doesn't. You use 'On Error Resume Next' instead, and test for the error inline.

    Not quite Try..Catch but it sure beats those stupid GoTo error blocks.

    If you're trying to emulate try..catch in VB then "On Error Goto <label>" is much closer than "On Error Resume Next"!

    I hope your boss doesn't see what you wrote!

  • moogletrop (unregistered) in reply to Matt Westwood
    Matt Westwood:
    IIRC, BBC BASIC was a grown-up version

    Which version?

    (I started on BASIC II on an Acorn Electron)

    I'm pretty sure line numbers were required, but am ready to be corrected - it is a VERY long time ago!

  • (cs) in reply to moogletrop
    moogletrop:
    Matt Westwood:
    IIRC, BBC BASIC was a grown-up version

    Which version?

    (I started on BASIC II on an Acorn Electron)

    I'm pretty sure line numbers were required, but am ready to be corrected - it is a VERY long time ago!

    Nothing much changed from BBC BASIC 1 to 2:

    http://en.wikipedia.org/wiki/BBC_BASIC

    (I happen to start on the much earlier Acorn Basic, which was somewhat more primitive)

    There's a whole website dedicated to BBC BASIC:

    http://www.bbcbasic.co.uk/bbcbasic.html

    Line numbers were part of the editor and thus automatically inserted, but you didn't have to rely on them.

  • Design Pattern (unregistered) in reply to Matt Westwood
    Matt Westwood:
    IIRC, BBC BASIC was a grown-up version which was evolving away from line numbers.
    Dear Microsoft,

    In case you can’t tell, BBC BASIC already was a grown-up language. The fact that you insist on supporting line numbers in your VBA clearly shows that you’re too young and too stupid to be offering software.

    Go away and grow up.

    Sincerely, Bert Glanstron

  • Matt Westwood (unregistered) in reply to Gary
    Gary:
    Uh, even VB can handle this easy to understand oneliner. Hate the = for both comparison and assignment but what can you do?

    ActiveSheet.Shapes("Option Button 22").Visible = (Range("a!Q7").Value=1)

    TRWTF lies thoroughly with the developers for not understanding even the most basic patterns of the language.

    Interestingly, nobody's complained about "Option Button 22" yet. Let me be frist. Would it not make sense for it to be renamed to something more descriptive? IMO this is more of a concern than the use of GOTOs, which are easily (in theory) replaced with something more compact and maintainable.

    CAPTCHA: quibus: question about public transport.

  • moogletrop (unregistered) in reply to ochrist
    ochrist:
    Nothing much changed from BBC BASIC 1 to 2:

    http://en.wikipedia.org/wiki/BBC_BASIC

    (I happen to start on the much earlier Acorn Basic, which was somewhat more primitive)

    There's a whole website dedicated to BBC BASIC:

    http://www.bbcbasic.co.uk/bbcbasic.html

    Line numbers were part of the editor and thus automatically inserted, but you didn't have to rely on them.

    Earlier than 1983?! You make me feel so young! :-P

    Data? Rewind tape? (remember rewinding and adjusting the volume?!)

  • (cs) in reply to moogletrop
    moogletrop:
    Earlier than 1983?! You make me feel so young! :-P

    Data? Rewind tape? (remember rewinding and adjusting the volume?!)

    Actually my first programs were written on a TI59 around 1978 and a bit later some version of BASIC (on a technical school via acoustic modem).

    But yeah, I remember all that tape stuff. Actually my old BBC model B is still working but packed away somewhere. Thought about getting rid of it last year, but didn't do it (probably for nostalgic reasons). No tapes, but I still have some 5 1/4" disks somewhere...

  • Tanuki (unregistered) in reply to validus
    validus:
    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.
    Ho hoo. It was over 50 messages before this. I'm positively surprised by yall people.
    Silfax:
    Oldtimer:
    What about ALTER in COBOL? This one was a real feature of a "serious" languange...
    some serious WTFs could come about from ALTERs, especially when you had a 'GO TO DEPENDING ON XXX' in the program where the targets were also targets of other ALTERs.

    It made for some hairy debugging.

    People shouldn't be told, but isn't GnuC's ability to goto an address stored in a void* -typed variable pretty much analogous?

Leave a comment on “Learning Something New”

Log In or post as a guest

Replying to comment #:

« Return to Article