The "Who Knows?" Code

« Return to Article
  • Vince 2009-12-02 09:03
    wtf
  • Piet 2009-12-02 09:04
    If statements are the answer to all problems. If it's not working, you aren't using enough.
  • Rodnas 2009-12-02 09:04
    Oh my god it is full of code
  • Rene 2009-12-02 09:06
    The person who produced this code is a true genius!
  • frits 2009-12-02 09:06
    That is a work of art.
  • Alargule 2009-12-02 09:06
    At least it's properly indented.
  • Osno 2009-12-02 09:07
    So, is some brave soul going to run that and see what it does?
  • Grovesy 2009-12-02 09:09
    Easy, just look at the unit tests, they should tell you what the code does.
  • Pragmatopian 2009-12-02 09:09
    a system used daily by scores of users daily


    Evidently not a system to check for duplicated modifiers!
  • ounos 2009-12-02 09:10
    I didn't want to see this. Life is meaningless now. I want to die.
  • Inhibeo 2009-12-02 09:10
    My guess? This is an incredibly clever quine.
  • ounos 2009-12-02 09:11
    Please don't tell me this is looking for duplicates!!!
  • Steenbergh 2009-12-02 09:12
    OMG!!! And I thought the code here was bad...
  • CaptainOblivious 2009-12-02 09:13
    if m(1) = m(2) = m(3) = ... = m(15) = 15, then this code would find all permutations of the numbers 1 through 15, wouldn't it?
  • rocco 2009-12-02 09:14
    Basic code full of GoTo statements and layers of embedded loops with exits... and no comments. VB doesn't need to be this way. *sigh* It makes me sad to see justification for the anti-VB rants.
  • md5sum 2009-12-02 09:15
    TRWTF is that apparently Vladmir had the incredible, once-in-a-lifetime opportunity to do a full rewrite of a legacy application, and just sent it to hell by copying and pasting the code that he didn't know what did into the shiny new app...
  • DOA 2009-12-02 09:15
    Grovesy:
    Easy, just look at the unit tests, they should tell you what the code does.
    Funniest comment this week.
  • Zapp Brannigan 2009-12-02 09:17
    I bet a dime this was done by a COBOL programmer learning VB.
  • MC 2009-12-02 09:17
    If you scroll up and down really fast you can see a sailboat!
  • PSX 2009-12-02 09:17
    Wait... *jump into* a for loop? But... ha- ... whu- ... how is this even possible?
  • Name 2009-12-02 09:19
    I hope the developer followed the arrow created by that code.

    Exit Stage Right.
  • Wladimir 2009-12-02 09:20
    I'm not the submitter but this seems to generate all possible combinations of i1,i2,i3 where i1,i2,i3 are natural numbers between 1 and m(1),m(2),m(3) respectively. Only that there aren't a just three but 16 variables. Let's hope that most m() values are zero, the number of combinations grows exponentially. Otherwise - yes, some people never get recursion. And - sure, you can "flatten" every recursive algorithm assuming the depth is limited.
  • Crash Magnet 2009-12-02 09:22
    The guy who wrote this is a genius. This is a prime example why you should never let a genius anywhere near your code.
  • Ren 2009-12-02 09:25
    This looks awesome. But we'd need the m(x) values to make sense, sorry :(

    Could the original poster come clean about the approximate return values of the m() function?
  • Martin 2009-12-02 09:25
    "And - sure, you can "flatten" every recursive algorithm assuming the depth is limited."

    You can turn any recursive algorithm into an iterative one without any assumptions. You just need to maintain your own stack.
  • csdx 2009-12-02 09:29
    I got as far as figuring that it loops over i1 through i16, and before each loop it's checking to see if the number it's using as a max value m(1)-m(16) is 0, if it is, it skips the for statement (and the next statement at the end). Then it does some sort of checking to make sure some things don't equal each other and then creates a combination array that the sum of everything. Why it does any of this is still a mystery.
  • - 2009-12-02 09:29
    md5sum:
    TRWTF is that apparently Vladmir had the incredible, once-in-a-lifetime opportunity to do a full rewrite of a legacy application, and just sent it to hell by copying and pasting the code that he didn't know what did into the shiny new app...


    See above for truth.

    Crash Magnet:
    The guy who wrote this is a genius. This is a prime example why you should never let a genius anywhere near your code.


    Yeah, I hate smart peop... Wait, no, it's you I hate.
  • highphilosopher 2009-12-02 09:32
    PSX:
    Wait... *jump into* a for loop? But... ha- ... whu- ... how is this even possible?


    It's VB man, you can jump in anywhere you want.


    So I was sitting there getting ready to read TDWTF when just as I clicked the title of the latest post, Marcy Playground's "Vampires of New York" started on grooveshark <shamelessplug>LOVE GROOVESHARK!!!</shamelessplug>, at the same time I read the first sentence...

    "When Vladimir first received his orders, the blood drained from his face."

    Between the "Vampires of New York" song, the name VLAD-imir and the reference to draining blood I got the funniest image in my head of a somewhat comical vampire programmer named Vladimir (obviously a cover name). In retrospect, explaining a funny image in your head does not work well in a WTF comment post does it?

    Captcha: genitus -- Not touching this one with a ten foot pole.
  • Prosthetic Lips 2009-12-02 09:34
    PSX:
    Wait... *jump into* a for loop? But... ha- ... whu- ... how is this even possible?


    He jumps into the for loop, but then jumps OUT using the same condition. Even though m(x) is zero, he still assumes a minimum of 1. I think my first revision would be to find some way around the goto's with maybe a "... to max(m(1), 1)" instead, and see how it cleans up the code.

    catcha: amet - using it in a sentence, "It's good to be amet" (baseball team).
  • Mike Caron 2009-12-02 09:36
    Surely I'm not the only one who is wondering how he managed to paste a bunch of BASIC into a C++ source file and still have it work, am I?

    Then again, no one said it still compiled...
  • Patrick 2009-12-02 09:38
    It generates combinations of numbers, in sixteen two-digit blocks, where no two blocks are alike. It then stores them in a collection, presumably to be retrieved at random. This is a key generator for either licensing or encryption.

    The code could be a lot cleaner than that, though.
  • csdx 2009-12-02 09:40
    if m(1) = m(2) = m(3) = ... = m(15) = 15, then this code would find all permutations of the numbers 1 through 15, wouldn't it?

    Actually with everything at 15, the code would basically do nothing. At each for loop, there's an if statement checking if the current iteration is equal to any other iteration, and exiting the loop if it does. So with only 15 possible values (1-15) there isn't any way the code will ever get to the innermost statement since there are 16 variables which need to be unique to get there.

    If m(1) =...= m(15) = 16, then I beleive this should return the sum of the numbers of 1 through 16. It just would have to execute something on the order of 16^16 loops to do so.
  • Crash Magnet 2009-12-02 09:40

    [quote user="Crash Magnet"]The guy who wrote this is a genius. This is a prime example why you should never let a genius anywhere near your code.
    [/quote]

    Yeah, I hate smart peop... Wait, no, it's you I hate.[/quote]

    You need genius to solve problems nobody else can. I don't hate 'em. In fact, they are fun people to be around.

    As for your feeling for me, get in line.
  • Daan 2009-12-02 09:43
    Ahh... this code brings back good memories.

    See? It looks just like the Homeworld Hiigaran mothership. Good times were had with her.
  • Stark 2009-12-02 09:46
    I was trying to follow along, but after I got past i10, I began to feel a little i11.
  • artie 2009-12-02 09:48
    it's not a sailboat, it's a schooner. Stupid!
  • jim 2009-12-02 09:48
    Well, obviously he must have spent an afternoon porting it, line for line, trying not to introduce any bugs.



    also: shouldn't he have just checked the VC commit log?
  • Neville Flynn 2009-12-02 09:48
    The goggles, they don't work!!
  • noone 2009-12-02 09:48
    1. I guarantee that there is at least one bug in this code.

    2. +1 for using "uplift". :-)

    captcha: saepius. Opposite of sapient. See code above.
  • Oded 2009-12-02 09:48
    Its not that bad. Its just a (very) weird way of printing all the possible combinations of 1..m(1..16) (resulting in a two dimensional matrix). with the caveat that m(n) might be 0 so you have to take that into consideration.

    On the face of it it looks like some sort of scorecard generator for a "lotto" style betting game.
  • Zylon 2009-12-02 09:52
    My god... it's as if Duff's Device fell into a black hole, merged with an alien AI, then came back to Earth centuries later demanding to speak with its creator.
  • OMG 2009-12-02 09:54
    Mike Caron:
    Surely I'm not the only one who is wondering how he managed to paste a bunch of BASIC into a C++ source file and still have it work, am I?


    I was wondering this as well, but my working hypothesis is that the current verison of Migrantsoft(R) Vicious(C) Student(C)(R)(TM) lets you paste in code from any Migrantsoft(C) language, and translates it to Mangled(TM) C+/-(R) at runtime. Happy happy joy joy that I get to stay blissfully unaware of such horrors.
  • BSDGuy 2009-12-02 09:55
    You lost me at:


    If m(1) = 0 Then GoTo i2
    For i1 = 1 To m(1)
    ....
    Next...


    At first I was like...oh, just use a case statement, but the motive of the code is...somewhere.

    TRWTF is that buddy-boy copied and pasted code that he doesn't understand...that makes less sense than this code.

    Then again, this code reminds me of Jolitz's TCP stack code! Fast, but WTF does it do?
  • Anonymous Organ Donor 2009-12-02 09:56
    Neville Flynn:
    The goggles, they don't work!!

    The goggles, they don't work???
    Sorry... But... it's "The goggles, they do nothing!" - it's painful, like having my 6 year old use bad grammar, I have to correct her
  • SR 2009-12-02 09:56
    :oD Now you owe me a fresh coffee and a new monitor.
  • SR 2009-12-02 09:56
    I meant:

    Grovesy:
    Easy, just look at the unit tests, they should tell you what the code does.


    :oD Now you owe me a fresh coffee and a new monitor.
  • blindio 2009-12-02 09:59
    Ren:
    This looks awesome. But we'd need the m(x) values to make sense, sorry :(

    Could the original poster come clean about the approximate return values of the m() function?


    I think, actually, that m is an array. so it's just someone stepping through an array and as soon as a non-zero value repeats it exits the loop, if all values are 0 than it formats the values of the i values as two digit numbers. it's really quite.... magnificent, like car accidents on CHiPs.

    They appear to be using the for loops to assign the value at each position in the m array to the i values. Looks like someone didn't understand arrays maybe?
  • Rootbeer 2009-12-02 10:16
    Real WTFs:

    1. Giving the same developers that wrote bad VB5 code the task of rewriting it in C++, and expecting the result to be anything other than equally-bad C++ code.

    2. The source control system that can tell you who has made changes to the code, but not which changes they made.


  • BD 2009-12-02 10:16
    OMG:
    Migrantsoft(R) Vicious(C) Student(C)(R)(TM) lets you paste in code from any Migrantsoft(C) language, and translates it to Mangled(TM) C+/-(R)

    Oh, aren't you just precious.
  • Mz Name? 2009-12-02 10:17
    Anonymous Organ Donor:
    Neville Flynn:
    The goggles, they don't work!!

    The goggles, they don't work???
    Sorry... But... it's "The goggles, they do nothing!" - it's painful, like having my 6 year old use bad grammar, I have to correct her


    Maybe a psychotherapist can help you to stop suffering from that pain.

  • Gramma 2009-12-02 10:17
    Oh isn't that just precious.
  • Thg 2009-12-02 10:20
    Pragmatopian:
    a system used daily by scores of users daily


    Evidently not a system to check for duplicated modifiers!


    Evidently not a system to check for duplicated modifiers, *Evidently*!
  • Dave 2009-12-02 10:25
    Anonymous Organ Donor:
    Neville Flynn:
    The goggles, they don't work!!

    The goggles, they don't work???
    Sorry... But... it's "The goggles, they do nothing!" - it's painful, like having my 6 year old use bad grammar, I have to correct her

    Sorry... But... it's "My eyes! The goggles do nothing!"
  • Charles400 2009-12-02 10:31
    Dan Brown just cracked the code. Buried inside is Carmen Electra's phone number.
  • evilspoons 2009-12-02 10:32
    Daan:
    See? It looks just like the Homeworld Hiigaran mothership.


    I thought this too, and I didn't even play Homeworld that much!
  • bnx 2009-12-02 10:34
    Anonymous Organ Donor:
    Neville Flynn:
    The goggles, they don't work!!

    The goggles, they don't work???
    Sorry... But... it's "The goggles, they do nothing!" - it's painful, like having my 6 year old use bad grammar, I have to correct her


    "My eyes! The googles do nothing!"

    http://en.wikipedia.org/wiki/Radioactive_Man_%28The_Simpsons_episode%29
  • Tiresias 2009-12-02 10:34
    Kinda ASCII art :-)
  • fist-poster 2009-12-02 10:42
    I was going to say that it is a Duff's Device, except bigger and better, but:


    If m(1) = 0 Then GoTo i2
    For i1 = 1 To m(1)
    i2: If m(2) = 0 Then GoTo i3
    etc

    Isn't this in effect the same as

    For i1 = 0 To m(1)

    etc.?
  • SR 2009-12-02 10:43
    Tiresias:
    Kinda ASCII art :-)


    A load of Jackson Pollocks maybe
  • Patrick 2009-12-02 10:45
    Dave:
    Anonymous Organ Donor:
    Neville Flynn:
    The goggles, they don't work!!

    The goggles, they don't work???
    Sorry... But... it's "The goggles, they do nothing!" - it's painful, like having my 6 year old use bad grammar, I have to correct her

    Sorry... But... it's "My eyes! The goggles do nothing!"


    THANK You! I really HATE it when people get it wrong like that!
  • undefined 2009-12-02 10:49
    TRWTF is C++ as target language. Why they need to rewrite application to worser language than original?
  • c-- 2009-12-02 10:49
    c++ version: http://pastebin.com/f39ca0e55
  • anon 2009-12-02 10:53
    The time has come for an obfuscated VB contest...
    It's too easy to "[http://www.ioccc.org/years.html]do it in C[/url]"

  • realmerlyn 2009-12-02 10:57
    Zylon:
    My god... it's as if Duff's Device fell into a black hole, merged with an alien AI, then came back to Earth centuries later demanding to speak with its creator.


    This is more like a "Duff Beer Device".
  • Callin 2009-12-02 10:59
    The coder was OBVIOUSLY an artist trying to create an ASCII right-parenthesis )
  • Your Name 2009-12-02 11:01
    Looks like automatically translated code that someone ran through an automatic formatter.
  • A Nonny Mouse 2009-12-02 11:01
    Rodnas:
    Oh my god it is full of code

    :) thanks for that, i lol'd
  • Grovesy 2009-12-02 11:02
    SR:
    I meant:

    Grovesy:
    Easy, just look at the unit tests, they should tell you what the code does.


    :oD Now you owe me a fresh coffee and a new monitor.


    Prehapes this is what can happen if you follow TDD to the extreme...

    Keep writing if statements till all tests cases pass.
  • anon 2009-12-02 11:03
    The only true bug I can find is that after the line "kom = kom+1" there should be a line reading

    If m(16)=0 Then GoTo n16

    so that "Next i16" is skipped if "For i16 ..." is skipped.

    If m(1)=0, then i1 is never initialised; presumably the full code initialises i1, ..., i16 (and kom) to something sensible.

    I think the code is supposed to do this:

    Select all permutations of 16 numbers where the nth number is between 1 and m(n) (unless m(n)=0, in which case the nth number is equal to some default value), subject to the constraint that none of the numbers chosen be equal (unless m(n)=0, in which case the default value is chosen whether or not it is equal to one of i1, ..., i[n-1]; but none of i[n+1], ..., i16 can be equal to the default value (unless they also take their default value)).

    The format used suggests that m(n) should be between 0 and 99 inclusive.
  • PinkFloyd 2009-12-02 11:05
    I remember this code from the old days, now you would simply use the getDate() method!
  • c0rnh0l10 2009-12-02 11:07
    Patrick:
    This is a key generator for either licensing or encryption.
    The perfect copy protection: This code is simply too ugly to be incorporated in a keymaker.
  • PinkFloyd 2009-12-02 11:08
    The real WTF are these guy's actually trying out where things are incorrect in the code! How much time are you wasting with that! You are fired!
  • Anonymous 2009-12-02 11:10
    Anonymous Organ Donor:
    Neville Flynn:
    The goggles, they don't work!!

    The goggles, they don't work???
    Sorry... But... it's "The goggles, they do nothing!" - it's painful, like having my 6 year old use bad grammar, I have to correct her

    Then your six year old must be a retard because you are completely wrong. Muphry, anyone?
  • DCRoss 2009-12-02 11:12
    MC:
    If you scroll up and down really fast you can see a sailboat!

    You dumb bastard, it's a schooner not a sailboat!
  • Pink Floyd 2009-12-02 11:17
    Martin:
    You can turn any recursive algorithm into an iterative one without any assumptions. You just need to maintain your own stack.

    I'm alright, Jack, keep your hands off my stack.
  • Patrick 2009-12-02 11:23
    OK, so curiosity got the better of me and I looked again in the comments for a better solution. Nada. Apparently no-one else could read it. So here it is:

    Private Sub Dude(ByVal depth As Integer, ByRef m() As Integer, ByRef i() As Integer, ByRef combination As Collection)
    
    For i(depth) = 0 To m(depth)
    For u = 0 To depth - 1
    If i(u) = i(depth) Then Exit Sub
    Next
    If depth = UBound(m) Then
    Dim s As String
    s = ""
    For c = depth To 0 Step -1
    s = s + Format(i(c), "00")
    Next
    combination.Add(s)
    Else
    Dude(depth + 1, m, i, combination)
    End If
    Next
    i(depth) = m(depth)
    End Sub

    Private Sub CalculateTheNumbers(ByVal numbers As Integer, ByVal maxnumber As Integer, ByRef combination As Collection)
    Dim m() As Integer
    Dim i() As Integer
    ReDim m(numbers - 1)
    ReDim i(numbers - 1)
    For d = 0 To numbers - 1
    m(d) = maxnumber
    Next
    Dude(0, m, i, combination)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim combination As New Collection
    CalculateTheNumbers(16, 20, combination)
    For Each c In combination
    ListBox1.Items.Add(c)
    Next
    End Sub


    I kept it in VB6 just because, but it would have been easier in something else.

    Having seen the result, it looks like it's a lottery number generator. 16 two-digit numbers with no duplicates and only in ascending order.
  • highphilosopher 2009-12-02 11:24
    undefined:
    TRWTF is C++ as target language. Why they need to rewrite application to worser language than original?


    Ok, I don't think anyone LIKES c++, but worse than VB??? Really? You Really think so?
  • some other dude 2009-12-02 11:31
    BD:
    OMG:
    Migrantsoft(R) Vicious(C) Student(C)(R)(TM) lets you paste in code from any Migrantsoft(C) language, and translates it to Mangled(TM) C+/-(R)

    Oh, aren't you just precious.


    awww how cute! you get all offended when someone pokes fun at the only stuff you know!

    your insecurity is showing.
  • Anonymous 2009-12-02 11:35
    Patrick:
    OK, so curiosity got the better of me and I looked again in the comments for a better solution. Nada. Apparently no-one else could read it. So here it is:

    <snipped code>

    Having seen the result, it looks like it's a lottery number generator. 16 two-digit numbers with no duplicates and only in ascending order.

    A lottery with 16 numbers? Doesn't sound very likely to me. Lotteries don't usually go above 8 numbers or so because more numbers makes it appear to be less fair to numerically challenged individuals (ie. all lottery players). Obviously, the actual chance of winning is also dependant on the size of the set (the maximum value of each ball). But remember, these are lottery players, ie. idiots.
  • Anonymous 2009-12-02 11:41
    undefined:
    TRWTF is C++ as target language. Why they need to rewrite application to worser language than original?

    I nominate this comment for the "most incompetent troll of the day" award. So painfully obvious.
  • Henning Makholm 2009-12-02 11:43
    anon:
    Select all permutations of 16 numbers where the nth number is between 1 and m(n) (unless m(n)=0, in which case the nth number is equal to some default value), subject to the constraint that none of the numbers chosen be equal (unless m(n)=0,

    No -- subject to the constraint that the numbers are decreasing except for zeroes. Whenever a match with something is fount, that entire level of loop is broken out of, so no in ever gets a value that is higher than any of its predecessors.

    I'm assuming that the in's start out zero or undefined. (Anything else would be too horrible).

    Then all of the long disjunctions can be replaced by comparing once against "the i of the innermost enclosing loop where m(.) is nonzero". And then the entire thing can be made infinitely more readable by using recursion instead of nesting.
  • Patrick 2009-12-02 11:53
    Anonymous:
    Patrick:
    Having seen the result, it looks like it's a lottery number generator. 16 two-digit numbers with no duplicates and only in ascending order.

    A lottery with 16 numbers? Doesn't sound very likely to me. Lotteries don't usually go above 8 numbers or so because more numbers makes it appear to be less fair to numerically challenged individuals (ie. all lottery players). Obviously, the actual chance of winning is also dependant on the size of the set (the maximum value of each ball). But remember, these are lottery players, ie. idiots.


    "looks like".
    Can you think of any other reason to keep the numbers in ascending order (other than "by accident", of course)?

    But, since we don't know the initial values of the m array, it's entirely possible it has a completely unrelated purpose. We also don't know where that data ends up. That's another thing, was that function even being used at all, or was it just a relic of something used only once?
  • Bim Job 2009-12-02 11:53
    Patrick:
    OK, so curiosity got the better of me and I looked again in the comments for a better solution. Nada. Apparently no-one else could read it. So here it is:

    Private Sub Dude(ByVal depth As Integer, ByRef m() As Integer, ByRef i() As Integer, ByRef combination As Collection)
    
    For i(depth) = 0 To m(depth)
    For u = 0 To depth - 1
    If i(u) = i(depth) Then Exit Sub
    Next
    If depth = UBound(m) Then
    Dim s As String
    s = ""
    For c = depth To 0 Step -1
    s = s + Format(i(c), "00")
    Next
    combination.Add(s)
    Else
    Dude(depth + 1, m, i, combination)
    End If
    Next
    i(depth) = m(depth)
    End Sub

    Private Sub CalculateTheNumbers(ByVal numbers As Integer, ByVal maxnumber As Integer, ByRef combination As Collection)
    Dim m() As Integer
    Dim i() As Integer
    ReDim m(numbers - 1)
    ReDim i(numbers - 1)
    For d = 0 To numbers - 1
    m(d) = maxnumber
    Next
    Dude(0, m, i, combination)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim combination As New Collection
    CalculateTheNumbers(16, 20, combination)
    For Each c In combination
    ListBox1.Items.Add(c)
    Next
    End Sub


    I kept it in VB6 just because, but it would have been easier in something else.

    Having seen the result, it looks like it's a lottery number generator. 16 two-digit numbers with no duplicates and only in ascending order.
    I believe you are under a misapprehension. This algorithm is clearly intended for implementation in ValSpeak. Here's my first shot at it:
    Private Sub DudeInValley depth As If, like m() As If, like I() As If, like duh! As If)
    
    For why?
    So totally, for why?
    What-ever!
    Like, Next
    Like, Next

    As if, Deep
    Like, Dim
    For why?
    I know, right?
    Else something
    OK?
    Deep, like, deep
    Dude, duh!

    ‘ Totes …

    Major Dude (like numers As If, like maxnumber, duh!, like What-ever, like, So Totally)
    Like, Dim I – As If
    Like , Dim M – As If

    OK, Dim M As If, or something
    Dude, Dim M, totally

    Worst. Code. Evah!
    Dude(0, m, i, combination)

    Why?
    A suitable abstraction of Greenspun's Tenth Law should turn this into perfectly acceptable Common Lisp.
  • rfsmit 2009-12-02 11:59
    Patrick:
    It generates combinations of numbers, in sixteen two-digit blocks, where no two blocks are alike. It then stores them in a collection, presumably to be retrieved at random. This is a key generator for either licensing or encryption.

    I thought the same thing when I saw the innermost part assembling the two-digit blocks.
    Patrick:
    The code could be a lot cleaner than that, though.

    ...which would soundly destroy any security gained through this obscurity.
  • A Gould 2009-12-02 12:02
    md5sum:
    TRWTF is that apparently Vladmir had the incredible, once-in-a-lifetime opportunity to do a full rewrite of a legacy application, and just sent it to hell by copying and pasting the code that he didn't know what did into the shiny new app...


    I can sympathize: if you can't figure out what the hell it's doing, or why, but you know you need it, what else do you do? (And you don't always have the time necessary to puzzle it out).

    All you can do it move the code over, and put big WARNING comments around it.
  • Patrick 2009-12-02 12:15
    Bim Job:
    This algorithm is clearly intended for implementation in ValSpeak.

    HAHA. That almost looks like a real language. VB Valgol.

    And yes, it's deliberately bad code inspired by previous WTFs, thanks for noticing.
  • Sanderman 2009-12-02 12:18
    TRWTF is commenters flaming on C++. Just because you can't understands some of it's more complex aspects is no reason to depict it as being worse than VB, which one of the most abused languages in existance.

    Another WTF is that they choose to refactor the app to C++ while a higher abstracted and more maintainable language like java and (shudder) .NET and possibly python and ruby are much more suited to business logic.

    Using C or C++ is pretty much overkill for anything that doesn't require high performance. On the other hand, C is great for drivers and C++ is great for simulations, games and other high performance computing.
  • Mason Wheeler 2009-12-02 12:22
    highphilosopher:
    undefined:
    TRWTF is C++ as target language. Why they need to rewrite application to worser language than original?


    Ok, I don't think anyone LIKES c++, but worse than VB??? Really? You Really think so?


    Oh, definitely. C++ may not be the worst programming language ever created, but without a doubt it's the worst ever to be taken seriously.
  • Grovesy 2009-12-02 12:25
    Patrick:
    Bim Job:
    This algorithm is clearly intended for implementation in ValSpeak.

    HAHA. That almost looks like a real language. VB Valgol.

    And yes, it's deliberately bad code inspired by previous WTFs, thanks for noticing.


    Valgol kinda reminds me of LOLCODE (another esoteric language)

    e.g http://en.wikipedia.org/wiki/LOLCODE

    HAI
    CAN HAS STDIO?
    IM IN YR LOOP UPPIN YR VAR TIL BOTHSAEM VAR AN 10
    VISIBLE SUM OF VAR AN 1
    IM OUTTA YR LOOP
    KTHXBYE
  • Rick 2009-12-02 12:37
    highphilosopher:
    undefined:
    TRWTF is C++ as target language. Why they need to rewrite application to worser language than original?


    Ok, I don't think anyone LIKES c++, but worse than VB??? Really? You Really think so?


    There are only two kinds of languages: the ones people complain about and the ones nobody uses. Bjarne Stroustrup
  • Someone You Know 2009-12-02 12:44
    Zylon:
    My god... it's as if Duff's Device fell into a black hole, merged with an alien AI, then came back to Earth centuries later demanding to speak with its creator.


    Which is sadder: that you spent time and effort making a Star Trek: The Motion Picture reference, or that I understood it?
  • Franz Kafka 2009-12-02 12:46
    Mz Name?:
    Anonymous Organ Donor:
    Neville Flynn:
    The goggles, they don't work!!

    The goggles, they don't work???
    Sorry... But... it's "The goggles, they do nothing!" - it's painful, like having my 6 year old use bad grammar, I have to correct her


    Maybe a psychotherapist can help you to stop suffering from that pain.



    I was thinking about an english teacher, myself.
  • Gary 2009-12-02 12:49
    This is the first time I've commented on this site. I had to. This code made me say "WTF" out loud. It's a good thing no one heard me.

    This is truly awful. I thought getting 30 tons of coal delivered was hilarious, but this is better. Anyone who can code like this should be able to do it simpler.

    How does code like this get past a peer review?
  • Zylon 2009-12-02 12:53
    Someone You Know:
    Zylon:
    My god... it's as if Duff's Device fell into a black hole, merged with an alien AI, then came back to Earth centuries later demanding to speak with its creator.


    Which is sadder: that you spent time and effort making a Star Trek: The Motion Picture reference, or that I understood it?

    The saddest thing is that either could be considered sad on a forum that should be populated by geeks, rather than clone-stamped corporate code monkeys.
  • Heron 2009-12-02 12:54
    Ugh. How predictable... people get bored and stoop to pointless language bashing.

    Anyway: 1) Surely he didn't paste the VB code into his C++ code, but rather translated it from one to the other (perhaps without understanding it).

    2) Wouldn't "svn blame" do what he needed? Then again, they were probably using (shudder) Visual SourceSafe.
  • mh 2009-12-02 12:56
    Mike Caron:
    Surely I'm not the only one who is wondering how he managed to paste a bunch of BASIC into a C++ source file and still have it work, am I?


    #define! Let's implement VB6 in the C++ preprocessor!
  • Arancaytar 2009-12-02 13:02
    Dijkstra was understating - looking at that, "harmful" doesn't begin to describe it.

    Visual SourceSafe.


    I would like to tell myself you made that name up, but it does sound like an actual MS product.
  • cdosrun 2009-12-02 13:04
    Dave:
    Anonymous Organ Donor:
    Neville Flynn:
    The goggles, they don't work!!

    The goggles, they don't work???
    Sorry... But... it's "The goggles, they do nothing!" - it's painful, like having my 6 year old use bad grammar, I have to correct her

    Sorry... But... it's "My eyes! The goggles do nothing!"


    This comment is the winner. I would like to add one internet to your score. I am laughing out loud.
  • Zapp Brannigan 2009-12-02 13:08
    DCRoss:
    MC:
    If you scroll up and down really fast you can see a sailboat!

    You dumb bastard, it's a schooner not a sailboat!
    I don't see it. It looks like a booby to me.
  • fred 2009-12-02 13:08
    I poked out my eyes out, jut so could be sure not to see that code more
  • D-Coder 2009-12-02 13:12
    A Gould:
    md5sum:
    TRWTF is that apparently Vladmir had the incredible, once-in-a-lifetime opportunity to do a full rewrite of a legacy application, and just sent it to hell by copying and pasting the code that he didn't know what did into the shiny new app...


    I can sympathize: if you can't figure out what the hell it's doing, or why, but you know you need it, what else do you do? (And you don't always have the time necessary to puzzle it out).

    All you can do it move the code over, and put big WARNING comments around it.


    Well. You can leave the code out entirely and wait for a user to complain.

    If someone complains, they might (maybe) know what should be there.

    If no one complains, then you've won.
  • Bim Job 2009-12-02 13:19
    Franz Kafka:
    Mz Name?:
    Anonymous Organ Donor:
    Neville Flynn:
    The goggles, they don't work!!

    The goggles, they don't work???
    Sorry... But... it's "The goggles, they do nothing!" - it's painful, like having my 6 year old use bad grammar, I have to correct her


    Maybe a psychotherapist can help you to stop suffering from that pain.


    I was thinking about an english teacher, myself.
    Is she hot? Can we have her phone number?

    PS If she's male, I don't want to know.
    PPS Nurse! Has the psychotherapist brought the coggles yet?
  • WiSK 2009-12-02 13:22
    I think it probably did need to be this way, for optimisation reasons. It's not just VB either, but any function which has O(x^16) is going to need every optimisation trick squeezed out of it. Patrick's attempt at making it readable is actually just making the code run slower than it needs to. Even just calculating where x<20, Patricks code takes 8.6 seconds to run on my machine, and the original takes 5.1. But maybe speed isn't the important thing.

    Actually, I just looked at the output and Patrick's gives some different results. Also it doesn't work when you have a simple case such below. Obviously for rewriting an old app that many people rely on, it's important to cover regression.

    Patrick, try making yours work with this data.
    For i = 1 To 16: m(i) = 0: Next
    m(1) = 9
    m(4) = 9
    m(7) = 9
    m(10) = 9

    You should get:
    01020304
    01020305
    01020405
    01030405
    02030405
    ... (skipped a bunch)
    04070809
    05070809
    06070809

    So perhaps Vladimir has done the right thing to just copy-paste the code. Waste of time trying to understand it.
  • Jasmine 2009-12-02 13:22
    Unit tests? Source control? Peer reviews? Are you people still in college or something?!
  • Bim Job 2009-12-02 13:28
    Grovesy:
    Patrick:
    Bim Job:
    This algorithm is clearly intended for implementation in ValSpeak.

    HAHA. That almost looks like a real language. VB Valgol.

    And yes, it's deliberately bad code inspired by previous WTFs, thanks for noticing.


    Valgol kinda reminds me of LOLCODE (another esoteric language)

    e.g http://en.wikipedia.org/wiki/LOLCODE

    HAI
    CAN HAS STDIO?
    IM IN YR LOOP UPPIN YR VAR TIL BOTHSAEM VAR AN 10
    VISIBLE SUM OF VAR AN 1
    IM OUTTA YR LOOP
    KTHXBYE
    Well, we've had too many TDWTFs in languages that are easy to laugh at, like PHP or VBx or ASP.Net. (Note to the "It's possible to write..." nutters: we laugh at the hordes of idiots seduced into thinking that they can program; not at the syntax or other features of the language. With the possible exception of On Error Resume Next.)

    Isn't it about time we had a WTF submission written in LOLCODE? Go on, you can invent the surrounding details yourselves. Just add a few 2D cow-orkers into the mix, a headline quote, and some gratuitous spelling or grammar quotes. Alex would be none the wiser.

    Of course, it would still make more sense than the abortion under current discussion.
  • Wyrd 2009-12-02 13:35
    D-Coder:
    A Gould:
    md5sum:
    TRWTF is that apparently Vladmir had the incredible, once-in-a-lifetime opportunity to do a full rewrite of a legacy application, and just sent it to hell by copying and pasting the code that he didn't know what did into the shiny new app...


    I can sympathize: if you can't figure out what the hell it's doing, or why, but you know you need it, what else do you do? (And you don't always have the time necessary to puzzle it out).

    All you can do it move the code over, and put big WARNING comments around it.


    Well. You can leave the code out entirely and wait for a user to complain.

    If someone complains, they might (maybe) know what should be there.

    If no one complains, then you've won.


    Yeah, that's what I was thinking. You just replace that whole section with a msgbox() and/or maybe a general error handler (on the assumption that the code's absence might make something blow up). You give the user a message like, "This portion of the program has been disabled because the code made no sense. Please contact the engineers and we'll try to get the code working again just as soon as we can figure out what it's supposed to do."

    --
    Furry cows moo and decompress.
  • Bim Job 2009-12-02 13:39
    WiSK:
    I think it probably did need to be this way, for optimisation reasons. It's not just VB either, but any function which has O(x^16) is going to need every optimisation trick squeezed out of it.
    Let's pause and think about that.

    Let's not.

    Any function which has O(x^16) needs marinading in garlic sauce, a stake through the heart, and a convenient cross-roads for the grave. (Preferably somewhere in the Appalachians, where nobody will find it and dig it up again.)

    This is, unfortunately, where impedance mismatch with the PHB steps in.

    Me: Can I go down to the store and buy several garlic bulbs and a large pointy stick?
    Apparently not.
    Me Can I spend two weeks rewriting this so that it's only O(NlogN)?
    Why would you want to do that? We'll just buy some more hardware.
    Me: If I squeeze that point on the top of your head, will your brains spurt out?

    Optimisation tricks, two legs. Sanity, four legs.
  • YourNameHere 2009-12-02 13:41
    Anonymous:

    ...snip...
    Lotteries don't usually go above 8 numbers or so because more numbers makes it appear to be less fair to numerically challenged individuals (ie. all lottery players)... But remember, these are lottery players, ie. idiots.


    OK I admit I occasionally buy a single lottery ticket. If you don't buy a ticket, you can NEVER win. It does amaze me when I see someone buying multiple tickets to improve their odds. That is like climbing as six foot step ladder to get closer to the sun.
  • Bim Job 2009-12-02 13:43
    Gary:
    How does code like this get past a peer review?
    The question is the answer.

    You do know what "peer" means, don't you?
  • ratis 2009-12-02 13:44
    Crash Magnet:
    The guy who wrote this is a genius. This is a prime example why you should never let a genius anywhere near your code.
    omfg, this.
  • vulputate 2009-12-02 13:47
    OMG:
    Mike Caron:
    Surely I'm not the only one who is wondering how he managed to paste a bunch of BASIC into a C++ source file and still have it work, am I?


    I was wondering this as well, but my working hypothesis is that the current verison of Migrantsoft(R) Vicious(C) Student(C)(R)(TM) lets you paste in code from any Migrantsoft(C) language, and translates it to Mangled(TM) C+/-(R) at runtime. Happy happy joy joy that I get to stay blissfully unaware of such horrors.
    This thread just took a turn... for the douche.
  • Wheaties 2009-12-02 13:47
    At least there's another company out there that produces code of the same quality that I've had the pleasure of meeting at my current employer. I'm not saying my company wrote such code but our customers are proud of that their work is being used in our work...
  • Anonymous 2009-12-02 13:49
    Actually a person that plays the lottery has a much better chance of winning than one that does not. I'll take 1 in a billion over 0.
  • sino 2009-12-02 13:50
    Grovesy:
    SR:
    I meant:

    Grovesy:
    Easy, just look at the unit tests, they should tell you what the code does.


    :oD Now you owe me a fresh coffee and a new monitor.


    Prehapes this is what can happen if you follow TDD to the extreme...

    Keep writing if statements till all tests cases pass.
    lol, wut? TopCod3r, is that you?
  • smxlong 2009-12-02 14:10
    Okay, what the hell, people? This code was obviously generated by a program. The WTF is not this code (which is probably efficient at whatever it does in the context it is used), but the fact that nobody can remember WHAT it does or WHERE the program that generated it is kept.

    Have you seriously never seen generated code?
  • Dan 2009-12-02 14:13
    Jasmine:
    Unit tests? Source control? Peer reviews? Are you people still in college or something?!


    No, IBM
  • SDC 2009-12-02 14:13
    No college student is that stupid.

    Sounds like somebody's headhunter jazzed up the resume for them.
  • noob 2009-12-02 14:15
    Prosthetic Lips:

    catcha: amet - using it in a sentence, "It's good to be amet" (baseball team).


    Apparently you don't follow baseball.
  • Jonathan Collins 2009-12-02 14:22
    md5sum:
    Vladmir had the incredible, once-in-a-lifetime opportunity to do a full rewrite of a legacy application


    That.
  • Bim Job 2009-12-02 14:24
    smxlong:
    Okay, what the hell, people? This code was obviously generated by a program. The WTF is not this code (which is probably efficient at whatever it does in the context it is used), but the fact that nobody can remember WHAT it does or WHERE the program that generated it is kept.

    Have you seriously never seen generated code?
    It's too pretty for generated code.

    Seriously.
  • Anon E. Mouse 2009-12-02 14:24
    Wow. This brought me back to when I first learned the GOTO statement. I really miss that little word sometimes.

    The author of this beast is not nearly familiar enough with recursive methods. Or, did that version of BASIC even support them?
  • highphilosopher 2009-12-02 14:24
    Jasmine:
    Unit tests? Source control? Peer reviews? Are you people still in college or something?!


    No, just work for a shop that sticks closely to the Agile methodology in both deed and spirit.

    Unit tests. Ok, so you may not want to, but they're not hard to do when you're writing the code, and they really make a difference in quality.

    Source Control. Everyone uses source control. Probably 80% use it wrong, but everyone needs source control.

    Peer Reviews. Unless you're a perfect coder (which you're not), then you need peer reviews.
  • Bim Job 2009-12-02 14:28
    noob:
    Prosthetic Lips:

    catcha: amet - using it in a sentence, "It's good to be amet" (baseball team).


    Apparently you don't follow baseball.
    Die, pinstriped scum!

    Oh, I'm sorry. What I actually meant to say is:

    "It is possible to write horrible code in any language; not just VB5. It is even easier if you like to spend your free time in the Bronx, watching a bunch of hired millionaires who could care less whether your language is Turing-complete or not."

    Yup, that's about it. Eat beans and die.
  • Loren Pechtel 2009-12-02 14:32
    fist-poster:
    I was going to say that it is a Duff's Device, except bigger and better, but:


    If m(1) = 0 Then GoTo i2
    For i1 = 1 To m(1)
    i2: If m(2) = 0 Then GoTo i3
    etc

    Isn't this in effect the same as

    For i1 = 0 To m(1)

    etc.?


    No. Your code executes once for 0, twice for 1 and so on. This code executes once for 0, once for 1, twice for 2 and so on.
  • Bim Job 2009-12-02 14:36
    highphilosopher:
    Jasmine:
    Unit tests? Source control? Peer reviews? Are you people still in college or something?!


    No, just work for a shop that sticks closely to the Agile methodology in both deed and spirit.

    Unit tests. Ok, so you may not want to, but they're not hard to do when you're writing the code, and they really make a difference in quality.

    Source Control. Everyone uses source control. Probably 80% use it wrong, but everyone needs source control.

    Peer Reviews. Unless you're a perfect coder (which you're not), then you need peer reviews.
    I'm so glad that Agile came along. We've all been wasting our time over the last twenty or thirty years doing obvious things like unit tests, source control and peer reviews without drinking that supercalifragilistic Agile kool-aid.

    On the other hand, you could (a) not hire idiots and (b) fire idiots when you realise that they are idiots. But that would put the Agilistas out of business.

    Whatever. That's agile, baby!
  • BCS 2009-12-02 14:47
    Translate it to VHDL and compile it to a gate array. It might actually be easier to understand.
  • SOmeGuy 2009-12-02 14:56
    While there is a small chance I might win money there is a 100% chance I will have t pay for the lottery ticket, losing that money. By not buying the lottery ticket I give up a small chance of not winning money for a 100% chance of NOT losing money (on buying a losing ticket). Add to that that most lotteries pay out less than they take in (operating expenses, government taxes/etc.) and it's pretty much a lose-lose.
  • Patrick 2009-12-02 14:58
    The sad thing is, for whatever its exact purpose (as long as the number of digits stays the same) this is probably the fastest way to generate what it needs to generate. It's potentially a very slow procedure, so every cpu cycle counts.
  • justsomedude 2009-12-02 15:00
    rocco:
    Basic code full of GoTo statements and layers of embedded loops with exits... and no comments. VB doesn't need to be this way. *sigh* It makes me sad to see justification for the anti-VB rants.


    Agreed. The bulk of VB's repuation comes from poor implementations, not the language itself.

    CAPTCHA: nobis.
  • justsomedude 2009-12-02 15:02
    SOmeGuy:
    While there is a small chance I might win money there is a 100% chance I will have t pay for the lottery ticket, losing that money. By not buying the lottery ticket I give up a small chance of not winning money for a 100% chance of NOT losing money (on buying a losing ticket). Add to that that most lotteries pay out less than they take in (operating expenses, government taxes/etc.) and it's pretty much a lose-lose.


    The lottery is a hidden tax on people who are bad at math.
  • iToad 2009-12-02 15:09
    Gary:
    This is the first time I've commented on this site. I had to. This code made me say "WTF" out loud. It's a good thing no one heard me.

    This is truly awful. I thought getting 30 tons of coal delivered was hilarious, but this is better. Anyone who can code like this should be able to do it simpler.

    How does code like this get past a peer review?


    What is this "peer review" that you speak of?
  • Coyne 2009-12-02 15:09
    Rene:
    The person who produced this code is a true genius!


    You mean, "... a true evil genius!"
  • Amerrickangirl 2009-12-02 15:15
    Gary:
    This is the first time I've commented on this site. I had to. This code made me say "WTF" out loud. It's a good thing no one heard me.

    This is truly awful. I thought getting 30 tons of coal delivered was hilarious, but this is better. Anyone who can code like this should be able to do it simpler.

    How does code like this get past a peer review?


    Do most shops have peer reviews? Sadly I've never worked anywhere that actually did them.
  • Eric Howe 2009-12-02 15:21
    Looks sort of like a VB bastardization of Duff's Device.

    http://en.wikipedia.org/wiki/Duff's_Device
  • pegr 2009-12-02 15:51
    Unit tests? Source control? Peer review? You are obviously still in college! ;)
  • fist-poster 2009-12-02 15:52
    Loren Pechtel:
    fist-poster:
    I was going to say that it is a Duff's Device, except bigger and better, but:


    If m(1) = 0 Then GoTo i2
    For i1 = 1 To m(1)
    i2: If m(2) = 0 Then GoTo i3
    etc

    Isn't this in effect the same as

    For i1 = 0 To m(1)

    etc.?


    No. Your code executes once for 0, twice for 1 and so on. This code executes once for 0, once for 1, twice for 2 and so on.


    Oops. So how about this? (Depending on what are the values of booleans.) :)


    For i1 = m(1) > 0 To m(1)
  • Bim Job 2009-12-02 15:54
    Amerrickangirl:
    Gary:
    This is the first time I've commented on this site. I had to. This code made me say "WTF" out loud. It's a good thing no one heard me.

    This is truly awful. I thought getting 30 tons of coal delivered was hilarious, but this is better. Anyone who can code like this should be able to do it simpler.

    How does code like this get past a peer review?


    Do most shops have peer reviews? Sadly I've never worked anywhere that actually did them.
    Actually, it's a do-it-yourself process:

    (1) Find one or more peers
    (2) ???
    (3) Review!
  • Silentbob 2009-12-02 15:58
    And what happened next .... !?
    Punchline people, did it work? Did it fail ?
  • RogerInHawaii 2009-12-02 16:03
    undefined:
    TRWTF is C++ as target language. Why they need to rewrite application to worser language than original?


    Conjugate worse:

    Worse

    Worser

    Worstest

    Worcestershire
  • Zylon 2009-12-02 16:03
    Eric Howe:
    Looks sort of like a VB bastardization of Duff's Device.

    http://en.wikipedia.org/wiki/Duff's_Device

    This is why it's advisable to read the thread before posting.
  • Fabiano 2009-12-02 16:05
    When a guy is able (or left) to code this way for few years... finally he has the boss in his pocket, let's ask for pay rise!!

    P.s: It looks like an hiigarian mothership for real.
  • Mingo 2009-12-02 16:15
    justsomedude:
    SOmeGuy:
    While there is a small chance I might win money there is a 100% chance I will have t pay for the lottery ticket, losing that money. By not buying the lottery ticket I give up a small chance of not winning money for a 100% chance of NOT losing money (on buying a losing ticket). Add to that that most lotteries pay out less than they take in (operating expenses, government taxes/etc.) and it's pretty much a lose-lose.


    The lottery is a hidden tax on people who are bad at math.


    Perhaps, but it's about the only tax that has even the most remote chance of one day giving me a return...
  • Fla 2009-12-02 16:17
    RogerInHawaii:
    undefined:
    TRWTF is C++ as target language. Why they need to rewrite application to worser language than original?


    Conjugate worse:

    Worse

    Worser

    Worstest

    Worcestershire


    I think you missed worserer
  • Bim Job 2009-12-02 16:17
    RogerInHawaii:
    undefined:
    TRWTF is C++ as target language. Why they need to rewrite application to worser language than original?


    Conjugate worse:

    Worse

    Worser

    Worstest

    Worcestershire
    I come from Warwickshire, and I resent that remark.

    Hawaii the lads!

    Roger and out.
  • Jason Q 2009-12-02 16:18
    Is thissimilar to how Java implements 'Contains'?
  • mypalmike 2009-12-02 16:21
    It's much more clear if you use recursion:

    (In broken VB)


    def foo (m[], i[], depth)
    if depth = 17
    setresults(i)
    else if m[depth] = 0 then
    foo(m, i, depth+1)
    else
    for i[depth]=1 to m[depth]
    if same(i, depth) then exit for
    else
    foo(m, i, depth+1)
    if m[depth] = 0 then exit for
    next i[depth]


    Or not.

    * Disclaimer: This code is probably completely wrong.
  • Nuphsayd 2009-12-02 16:22
    Generate all possible drawings of numbers from jars with m(i) balls (in jar number i), where no two numbers are the same?
  • Tukaram 2009-12-02 16:32
    Jasmine:
    Unit tests? Source control? Peer reviews? Are you people still in college or something?!


    Have ever been in that thing called "real live"?

    Regards
  • someone put baby in the corner 2009-12-02 16:35
    College?
  • Mason Wheeler 2009-12-02 16:53
    justsomedude:
    The lottery is a hidden tax on people who are bad at math.


    Yeah, a friend of mine calls the lottery (well, gambling in general) "paying the IQ tax."
  • Mr.'; Drop Database -- 2009-12-02 16:56
    Zapp Brannigan:
    DCRoss:
    MC:
    If you scroll up and down really fast you can see a sailboat!

    You dumb bastard, it's a schooner not a sailboat!
    I don't see it. It looks like a booby to me.
    What? It doesn't look anything like a booby.
  • J. Pablo Fernández 2009-12-02 16:57
    How does people work at all without source control? I find sources control to be the easiest way to share code. What do they do, mail tarballs?
  • Anonymous 2009-12-02 17:13
    Wha...I...OW! Please, take it away. I'll do whatever you want! What did I do to deserve this? *cry* OK, I'll admit it. I'm the one that ran over the neighbor's cat. Please, just don't make me look at that code again!
  • password 2009-12-02 17:46
    J. Pablo Fernández:
    How does people work at all without source control? I find sources control to be the easiest way to share code. What do they do, mail tarballs?

    Well, the obvious way to share code (and for source control for that matter) would include a color printer, (preferably) a digital camera, and of course a (clean) wooden table.
  • unknown 2009-12-02 18:05
    Nice bow, btw...
  • PSWorx 2009-12-02 18:13
    Prosthetic Lips:
    PSX:
    Wait... *jump into* a for loop? But... ha- ... whu- ... how is this even possible?


    He jumps into the for loop, but then jumps OUT using the same condition. Even though m(x) is zero, he still assumes a minimum of 1. I think my first revision would be to find some way around the goto's with maybe a "... to max(m(1), 1)" instead, and see how it cleans up the code.

    catcha: amet - using it in a sentence, "It's good to be amet" (baseball team).


    Maybe this is a noob question then, but I wonder, if you e.g. jumped over the
    For i1 = 1 To m(1)
    line, what value would i1 have? also, what would happen if you didn't jump out of the loop again at the end?

    I have no problems using this on switch{} as Duff's Device does. But loops? oO
  • seebs 2009-12-02 18:29
    Trying to iterate combinations of up to 15 items?
  • ZZMike 2009-12-02 18:58
    It brings a tear to my eye. Such elegance. Such beauty. Such simplicity.

    Well, yes, there's the bit about violating just about every written and unwritten rule and lore about programming, but still ...

    I suspect this started life as a simple, single "if-then" construct, but then, over time, grew, like the Loch Ness monster.

    On the other hand, extending it to include m(17) is practically trivial. So then: extendible code? Yes, 2 marks.
  • Swedish tard 2009-12-02 19:07
    If I came across code like this where I work, I'd start working on refactoring it. With the full blessings of everyone that has a say on code quality. If it'd take me two weeks, I'd get two weeks. And daaamn, that feels so bloody good right now. >.<
    And srsly? How the fuck can he just sodomize his on stuff with that thing?
  • Anonymous 2009-12-02 19:32
    It's really straightforward, convert it to C++ and run it, benchmark it and see what kind of results you get, it's hard to believe he has the entire original program and can't figure out what's referencing it during execution.
  • On a roll !! 2009-12-02 19:39
    Two good WTFs in a row..
    Can Alex cap the week off with a hattrick ??

    <RandomRant>Why on earth do people put in a captcha below their posts, and call it exactly that. Call it a signature if you want, but captcha is just a wrong term.</RandomRant>
  • Edmunds 2009-12-02 19:43
    WTF?! Really...

    Excuse me, gonna go puke now.
  • BentFranklin 2009-12-02 19:46
    I find it hard to believe they have no idea what it does when they can see what's happening just before and just after.

    Also, I LOVED the use of "uplift".
  • beets 2009-12-02 20:07
    Might want to hit up youtube for the real wording. Hint: it's not what everyone thinks it is.
  • Jimmy McJimbo 2009-12-02 20:10
    No one would admit to any knowledge of that code.
    I dont think the writer of that code even remembers what it does. They were prolly possessed by satan himself when they wrote it.
  • Me 2009-12-02 20:11
    This looks like what happens when computers generate code.
  • DaveK 2009-12-02 20:30
    Mr.'; Drop Database --:
    Zapp Brannigan:
    DCRoss:
    MC:
    If you scroll up and down really fast you can see a sailboat!

    You dumb bastard, it's a schooner not a sailboat!
    I don't see it. It looks like a booby to me.
    What? It doesn't look anything like a booby.

    Well, there's clearly not going to be any little Bobby '; Drop Database -- coming along anytime soon if you don't get yourself better informed.

  • Marcin 2009-12-02 20:42
    HAHAHA.. I guess you've never worked in a corporate IT department :)

    Okay, sure, I guess some probably have decent processes, but most it's like the Wild West.
  • Falcon 2009-12-02 21:42
    I wonder how that code would react like this if it saw itself. Possibly somewhat like this:

    http://www.youtube.com/watch?v=Ka1PeNNi6dg
  • beltorak 2009-12-02 22:45
    J. Pablo Fernández:
    How does people work at all without source control? I find sources control to be the easiest way to share code. What do they do, mail tarballs?

    Actually, yes. But I'm not that smart, so I just use subversion.
  • Right Wing-Nut 2009-12-03 00:12
    WiSK:
    I think it probably did need to be this way, for optimisation reasons. It's not just VB either, but any function which has O(x^16) is going to need every optimisation trick squeezed out of it. Patrick's attempt at making it readable is actually just making the code run slower than it needs to. Even just calculating where x<20, Patricks code takes 8.6 seconds to run on my machine, and the original takes 5.1. But maybe speed isn't the important thing.

    Actually, I just looked at the output and Patrick's gives some different results. Also it doesn't work when you have a simple case such below. Obviously for rewriting an old app that many people rely on, it's important to cover regression.

    Patrick, try making yours work with this data.
    For i = 1 To 16: m(i) = 0: Next
    m(1) = 9
    m(4) = 9
    m(7) = 9
    m(10) = 9

    You should get:
    01020304
    01020305
    01020405
    01030405
    02030405
    ... (skipped a bunch)
    04070809
    05070809
    06070809

    So perhaps Vladimir has done the right thing to just copy-paste the code. Waste of time trying to understand it.


    You, sir are the only one whose posts demonstrate that you comprehend what the code is doing (but almost).

    The format(inn, '00')'s are unconditional, so there are a lot of
    '00's missing from your output.

    Here's a nearly-competent rendering of this code in Ruby:
    class Combinator
    Combinations = []

    def initialize(m)
    @m = m.dup
    setup_minimums
    end

    def setup_minimums
    @minimums[17] = 0
    (1..16).to_a.reverse.each do |i|
    @minimums[i] = @minimums[i + 1] + (@m[i] == 0 ? 0 : 1)
    end
    (1..16).to_a.each{|i| @minimums[i] = 0 if @m[i] == 0}
    end


    def combinations
    loop_stage(1, 0, '')
    end

    def loop_stage(stage, limit, string)
    max = limit == 0 ? @m[stage] : min(limit, @m[stage])
    (@minimums[stage] .. max).to_a.each do |i|
    s = ('%02d' % i) + string
    if stage == 16
    Combinations << s
    else
    loop_stage(stage + 1, i == 0 ? limit : i - 1, s)
    end
    end
    end

    # m is an 16-element array starting at 1 with integer elements from
    # 0 to 99
    def self.combinations(m)
    Combinations.clear
    new(m).combinations
    end

    private :initialize

    end

    Yes, all those limit compares can not only be moved to the loop, you only need to compare against ONE thing. Furthermore, in the event that you aren't actually going to print out anything, you can do that with fewer than 100 compares.

    The VB code is horribly unoptimized for the likely cases.

    Question: If m = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15], what would the original code output, and how many compares would it take?
  • Rick 2009-12-03 01:04
    The real wtf is that he expects he can copy VB code and have it compile in a C++ compiler...
  • Rick 2009-12-03 01:22

    ...pasted the code into the C++ app hoping that some day, it wouldn't come down to him having to explain what the code did.


    He's in for a surprise when he tries to compile that... unless the preprocessor is going to translate that :o
  • Jav 2009-12-03 02:01
    Martin:
    "And - sure, you can "flatten" every recursive algorithm assuming the depth is limited."

    You can turn any recursive algorithm into an iterative one without any assumptions. You just need to maintain your own stack.


    Yes, absolutely, and the Church-Turing thesis proves it if memory serves. In lay terms, it states that what is computable by recursive functions is computable by an iterative model (such as the Turing machine) and vice versa.

    HOWEVER, The thesis does not tell you precisely how to do the conversion, but it does say that it's definitely possible.

    In many cases, converting a recursive function is easy. Knuth offers several techniques in "The Art of Computer Programming". And often, a thing computed recursively can be computed by a completely different approach in less time and space. The classic example of this is Fibonacci numbers or sequences thereof. You've surely met this problem in your degree plan.

    http://stackoverflow.com/questions/931762/can-every-recursion-be-converted-into-iteration

  • Grunt 2009-12-03 02:12
    You are delusional...
  • Adam Thompson 2009-12-03 03:23
    You think Unit tests, source control, and peer reviews actually *happen* in most of the places code gets written in this world? Are you still in college or something?!

    (Actually, I don't think you are - you probably work in one of the LARGE software firms that actually does stuff like that. And have obviously never worked for a small consulting company that produces custom applications.)
  • stefan, rzeźnik 2009-12-03 04:13
    How would unit tests help you out here?

    Cheers,
    S.
  • the real wtf fool 2009-12-03 04:38
    highphilosopher:
    PSX:
    Wait... *jump into* a for loop? But... ha- ... whu- ... how is this even possible?


    It's VB man, you can jump in anywhere you want.


    So I was sitting there getting ready to read TDWTF when just as I clicked the title of the latest post, Marcy Playground's "Vampires of New York" started on grooveshark <shamelessplug>LOVE GROOVESHARK!!!</shamelessplug>, at the same time I read the first sentence...

    "When Vladimir first received his orders, the blood drained from his face."

    Between the "Vampires of New York" song, the name VLAD-imir and the reference to draining blood I got the funniest image in my head of a somewhat comical vampire programmer named Vladimir (obviously a cover name). In retrospect, explaining a funny image in your head does not work well in a WTF comment post does it?


    No afraid not. It's like trying to explain your really amazing dream to someone else - it never seems quite as good...
  • the real wtf fool 2009-12-03 04:45
    Anonymous Organ Donor:
    Neville Flynn:
    The goggles, they don't work!!

    The goggles, they don't work???
    Sorry... But... it's "The goggles, they do nothing!" - it's painful, like having my 6 year old use bad grammar, I have to correct her


    I own all your bases!
  • y 2009-12-03 05:00
    I think it calculates all combinations of the given set m.

    The if-for-if-next constructs in comination with the labels and goto's are to make sure all loops are executed at least once. Like a do-loop-while..
  • Grovesy 2009-12-03 05:12
    Adam Thompson:
    You think Unit tests, source control, and peer reviews actually *happen* in most of the places code gets written in this world? Are you still in college or something?!

    (Actually, I don't think you are - you probably work in one of the LARGE software firms that actually does stuff like that. And have obviously never worked for a small consulting company that produces custom applications.)



    Not sure if you're trolling or not, but I'll bite.

    Currently I work for a small 20man consultancy, on a project with around 6 of us.. so fairly small

    Yes we write unit tests, yes we have integrationt tests, yes we have BVT / deployment tests, yes we use source control, yes with have continuous build, integration builds and release builds.

    As a contractor, I often work on small projects on my own, and yes I do all that even when it's me on my own.

    Safe refactoring of code becomes very difficult without a good unit/integration tests suite.
  • AC 2009-12-03 05:37
    svn blame?
  • No1 2009-12-03 06:20
    Which part of "legacy code" and "vb5" did you miss? Pretty sure that the code was written before unit tests were invented.

    And as for the source control, that's probably how he discovered who had touched the code.
  • The General 2009-12-03 06:28

    If m(1) = 0 Then GoTo i2
    For i1 = 1 To m(1)
    i2: If m(2) = 0 Then GoTo i3
    etc



    Does a FOR loop always execute at least once in VB5? (ISTR this pitfall when learning BASIC many years ago.)
    In that case even a hard-coded "FOR i = 1 TO 0" would go through the loop once (i.e. it's more like a do...while loop), and to avoid that, you need the IF to skip the case where m(x) = 0.
    Therefore, after "pasting into C++" (and changing the syntax to suit, presumably) you could get rid of all these IFs, because in C++ "for (i=1 ; i<m(1) ; ++i)" skips the loop if m(1) < 1.
  • seriosuly? 2009-12-03 06:44
    No1:
    Which part of "legacy code" and "vb5" did you miss? Pretty sure that the code was written before unit tests were invented.

    And as for the source control, that's probably how he discovered who had touched the code.


    The original 'UnitTest' comment was in jest, some people picked up on that some didn't.

    A conversation then went onto to say that source control and and unit testing where not applicable in the read world and something that was just taught on courses.
  • Paul A. Bean 2009-12-03 06:53
    MC:
    If you scroll up and down really fast you can see a sailboat!


    Brenda?
  • StarLite 2009-12-03 06:54
    I accidentally this code, would this be a problem?
  • Paul A. Bean 2009-12-03 07:06
    Bim Job:
    highphilosopher:
    Jasmine:
    Unit tests? Source control? Peer reviews? Are you people still in college or something?!


    No, just work for a shop that sticks closely to the Agile methodology in both deed and spirit.

    Unit tests. Ok, so you may not want to, but they're not hard to do when you're writing the code, and they really make a difference in quality.

    Source Control. Everyone uses source control. Probably 80% use it wrong, but everyone needs source control.

    Peer Reviews. Unless you're a perfect coder (which you're not), then you need peer reviews.
    I'm so glad that Agile came along. We've all been wasting our time over the last twenty or thirty years doing obvious things like unit tests, source control and peer reviews without drinking that supercalifragilistic Agile kool-aid.

    On the other hand, you could (a) not hire idiots and (b) fire idiots when you realise that they are idiots. But that would put the Agilistas out of business.

    Whatever. That's agile, baby!


    Yawn. XP never claimed to be doing anything new. You've missed the point. Why complain about a process whilst simultaneously claiming to have been doing it all along anyway? Oh yeh, because old duffers like nothing more than a whinge.
  • Elvis 2009-12-03 07:31
    artie:
    it's not a sailboat, it's a schooner. Stupid!


    What you need is a fatty boom batty blunt. Then I guarantee you'll see a dolphin, a sail boat, and maybe some of those big titty mermaids doing some of that lesbian shit.
  • Swedish tard 2009-12-03 07:32
    stefan, rzeźnik:
    How would unit tests help you out here?

    Cheers,
    S.



    With unit tests you can poke the code with different inputs and see what it actually does. Then you write your own function and run the exact same unit tests on it and see if it works the same way. This is what you do every time you refactor code.
  • G 2009-12-03 07:45
    as if most companies did any of the above - god I wish they did. Sad truth is ppl use CVS and unit tests just take away development time (until they reach the end of a project and realize that the contract requires a shitload of tests. Then they start hacking in tests....)

    *sigh*

    wonder if I should switch to working in a totally computer unrelated business. Gardening.. Do ppl use computers for gardening?!? ;]

    G.
  • Anonymous 2009-12-03 07:46
    the real wtf fool:
    Anonymous Organ Donor:
    Neville Flynn:
    The goggles, they don't work!!

    The goggles, they don't work???
    Sorry... But... it's "The goggles, they do nothing!" - it's painful, like having my 6 year old use bad grammar, I have to correct her


    I own all your bases!

    Can I have a cheeseburger?!
  • Swedish tard 2009-12-03 08:10
    G:
    as if most companies did any of the above - god I wish they did. Sad truth is ppl use CVS and unit tests just take away development time (until they reach the end of a project and realize that the contract requires a shitload of tests. Then they start hacking in tests....)

    *sigh*

    wonder if I should switch to working in a totally computer unrelated business. Gardening.. Do ppl use computers for gardening?!? ;]

    G.


    I find that people dodge testing formally (and I know they do) when they do it anyway. I mean, its better to have a good testing base that can be run over and over when the need arises than to do it manually. And well, in my experience testing thoughroughly as you develop actually cuts developing time since you catch problems sooner. And the later you catch a problem the more expensive it is to fix it.
  • Zan 2009-12-03 08:13
    Feelin' stupid for writing something similar?

    ;-)
  • Zan 2009-12-03 08:15
    I can think of a few other things which require those same implements... Can't mention them here though
  • undefined 2009-12-03 08:17
    J. Pablo Fernández:
    How does people work at all without source control? I find sources control to be the easiest way to share code. What do they do, mail tarballs?


    In the modern Web 2.0 world everybody uses Wiki for this. Anonymous can write code for free!
  • Grovesy 2009-12-03 08:25
    Swedish tard:
    G:
    as if most companies did any of the above - god I wish they did. Sad truth is ppl use CVS and unit tests just take away development time (until they reach the end of a project and realize that the contract requires a shitload of tests. Then they start hacking in tests....)

    *sigh*

    wonder if I should switch to working in a totally computer unrelated business. Gardening.. Do ppl use computers for gardening?!? ;]

    G.


    I find that people dodge testing formally (and I know they do) when they do it anyway. I mean, its better to have a good testing base that can be run over and over when the need arises than to do it manually. And well, in my experience testing thoughroughly as you develop actually cuts developing time since you catch problems sooner. And the later you catch a problem the more expensive it is to fix it.


    I've also noticed another trait on systems with good tests.

    Systems with good test coverage, with sensible well written clean tests are less likley to suffer from 'big ball of mud', and many other anti-patterns (though bad brittle tests can introduce another kind of anti-pattern).

    I belive the reason is two-fold, can refactor easily with confidence, and good tests tend to produce well designed code. (complex tests tend to suggest complex-doing-to-much code underneath)


  • CPFC 2009-12-03 08:33
    Thanks for the belly laugh. Hilarious
  • wtf? 2009-12-03 08:38
    a system used daily by scores of users daily


    I didn't think anyone could use that monstrosity even weekly, but it appears that some people are daily cursed to use it daily. Does that mean that each day, they are forced to use it against their will, and that as a result they have to use it daily? Or was this whole article put through google translate from some foreign language, such as british, that has ridiculous constructs such as that?
  • CPFC 2009-12-03 09:01
    Loren Pechtel:
    fist-poster:
    I was going to say that it is a Duff's Device, except bigger and better, but:


    If m(1) = 0 Then GoTo i2
    For i1 = 1 To m(1)
    i2: If m(2) = 0 Then GoTo i3
    etc

    Isn't this in effect the same as

    For i1 = 0 To m(1)

    etc.?


    No. Your code executes once for 0, twice for 1 and so on. This code executes once for 0, once for 1, twice for 2 and so on.


    How about:

    For i1 = iif(m(1)=0,0,1) to m(1)

    ?
  • CPFC 2009-12-03 09:04
    or even, for added obscurity:
    For i1 = sgn(m(1)) to m(1)
  • AlanGriffiths 2009-12-03 09:10
    This reminds me of the day that Dennis (the project manager) came to me asking what some obscurely written code did. I walked him through the logic and that led to some related code, I explained that too.

    Nigel asked about the very different styles of code *I'd* used. Then I explained the first bit was written by Robb and the second bit by Rob (yes that did cause confusion - they were both still on the team).

    He looked confused - "but Robb sent me to you because he didn't understand the first bit!"...
  • Patrick 2009-12-03 09:34
    WiSK:
    Patricks code takes 8.6 seconds to run on my machine, and the original takes 5.1.
    ...
    So perhaps Vladimir has done the right thing to just copy-paste the code. Waste of time trying to understand it.

    Yeah, I figured. But I had time to waste.
  • Mike Caron 2009-12-03 09:37
    Jeez, I feel sorry for all you rubes who are limited by your recursive-descent language parsers that get hung up over a detail like a repeated word.

    I, with my full natural language parser, didn't even notice the problem until attention was called to it!
  • Ilya Ehrenburg 2009-12-03 10:28
    Mike Caron:
    Jeez, I feel sorry for all you rubes who are limited by your limited recursive-descent language parsers that get hung up over a detail like a repeated word.

    I, with my full natural language parser,I didn't even notice the problem until attention was called to it even, I didn't!
  • Christopher 2009-12-03 10:48
    Ilya Ehrenburg:
    Mike Caron:
    Jeez, I feel sorry for all you rubes who are limited by your limited recursive-descent language parsers that get hung up over a detail like a repeated word.

    I, with my full natural language parser,I didn't even notice the problem until attention was called to it even, I didn't!
  • Swedish tard 2009-12-03 10:50
    Grovesy:
    Swedish tard:
    G:
    as if most companies did any of the above - god I wish they did. Sad truth is ppl use CVS and unit tests just take away development time (until they reach the end of a project and realize that the contract requires a shitload of tests. Then they start hacking in tests....)

    *sigh*

    wonder if I should switch to working in a totally computer unrelated business. Gardening.. Do ppl use computers for gardening?!? ;]

    G.


    I find that people dodge testing formally (and I know they do) when they do it anyway. I mean, its better to have a good testing base that can be run over and over when the need arises than to do it manually. And well, in my experience testing thoughroughly as you develop actually cuts developing time since you catch problems sooner. And the later you catch a problem the more expensive it is to fix it.


    I've also noticed another trait on systems with good tests.

    Systems with good test coverage, with sensible well written clean tests are less likley to suffer from 'big ball of mud', and many other anti-patterns (though bad brittle tests can introduce another kind of anti-pattern).

    I belive the reason is two-fold, can refactor easily with confidence, and good tests tend to produce well designed code. (complex tests tend to suggest complex-doing-to-much code underneath)




    YEah, also, using TTD you have to think things through before you start hacking away, so less patchwork programming. Hopefully.
  • Ilya Ehrenburg 2009-12-03 10:56
    The General:

    If m(1) = 0 Then GoTo i2
    For i1 = 1 To m(1)
    i2: If m(2) = 0 Then GoTo i3
    etc



    Does a FOR loop always execute at least once in VB5?
    I think not. But that's not the point of the Ifs.
    (ISTR this pitfall when learning BASIC many years ago.)
    In that case even a hard-coded "FOR i = 1 TO 0" would go through the loop once (i.e. it's more like a do...while loop), and to avoid that, you need the IF to skip the case where m(x) = 0.
    Therefore, after "pasting into C++" (and changing the syntax to suit, presumably) you could get rid of all these IFs, because in C++ "for (i=1 ; i<m(1) ; ++i)" skips the loop if m(1) < 1.

    And you would have changed what the code does. With that, if one m(k) is 0, none of the inner loops is executed, and that's what the
    If m(k-1) = 0 Then GoTo ik

    are for, regardless of any prior 0s, the inner loops shall be executed.
    We can't know whether i1, ..., i16 are initialized before, if so to what; and I don't know what VB5 does with uninitialized variables, but if they're initialized to 0 or uninitialized and default to 0, you'd get the effect in C++ by
    for(i2 = m[2]?0:1; i2 <= (m[2] < 0)?0:m[2]; ++i2)

    if they're initialized to something other than 0, replace 0 by i2 in "?0:m[2]".
  • Paul A. Bean 2009-12-03 11:46
    G:
    as if most companies did any of the above - god I wish they did. Sad truth is ppl use CVS and unit tests just take away development time (until they reach the end of a project and realize that the contract requires a shitload of tests. Then they start hacking in tests....)


    Then they don't really understand TDD. I find it quicker to write something TDD than to not.
  • Paul A. Bean 2009-12-03 11:49
    Swedish tard:
    Grovesy:
    Swedish tard:
    G:
    as if most companies did any of the above - god I wish they did. Sad truth is ppl use CVS and unit tests just take away development time (until they reach the end of a project and realize that the contract requires a shitload of tests. Then they start hacking in tests....)

    *sigh*

    wonder if I should switch to working in a totally computer unrelated business. Gardening.. Do ppl use computers for gardening?!? ;]

    G.


    I find that people dodge testing formally (and I know they do) when they do it anyway. I mean, its better to have a good testing base that can be run over and over when the need arises than to do it manually. And well, in my experience testing thoughroughly as you develop actually cuts developing time since you catch problems sooner. And the later you catch a problem the more expensive it is to fix it.


    I've also noticed another trait on systems with good tests.

    Systems with good test coverage, with sensible well written clean tests are less likley to suffer from 'big ball of mud', and many other anti-patterns (though bad brittle tests can introduce another kind of anti-pattern).

    I belive the reason is two-fold, can refactor easily with confidence, and good tests tend to produce well designed code. (complex tests tend to suggest complex-doing-to-much code underneath)




    YEah, also, using TTD you have to think things through before you start hacking away, so less patchwork programming. Hopefully.


    On the other hand, shitty developers can claim to be using TDD, ergo their must be "bug-free", and they've got the coverage reports to prove it. Don't laugh, I see it all the time. There's 2 ways to raise test coverage, pushing it up and pulling it up. But all a manager wants to see is a high figure, he doesn't give a toss that it's completely artificial. I'm much more likely to trust code with 80% coverage than something that claims to have 95% coverage.
  • Bim Job 2009-12-03 11:53
    Paul A. Bean:
    Yawn. XP never claimed to be doing anything new. You've missed the point. Why complain about a process whilst simultaneously claiming to have been doing it all along anyway? Oh yeh, because old duffers like nothing more than a whinge.
    XP != Agile.

    Sensible software practice ~ either. Maybe.

    Sip that kool-aid, stop yawning, and explain why this drivel never claimed to be doing anything new. Then explain to me what point I've missed.

    You're due for a libel suit if you claim once more that I've "simultaneously been claiming to do it all along." I claimed no such thing. XP is a ludicrous cult. Agile is a slippery eel that redefines itself whenever a practitioner feels the need.

    You're evidently too close-minded to save, but for anybody else: download Mr Ed.

    It's always helpful to prepare your position against these dimwits.
  • danixdefcon5 2009-12-03 12:20
    highphilosopher:
    undefined:
    TRWTF is C++ as target language. Why they need to rewrite application to worser language than original?


    Ok, I don't think anyone LIKES c++, but worse than VB??? Really? You Really think so?


    Just the WTF programmers.

    In fact, this gives credence on why VB is a bad idea. :)
  • brianguy 2009-12-03 13:16
    something tells me Jasmine has never worked in any kind of fly-by-night startup or dealt with much legacy code before. sure, all those controls (you forgot documentation) are great. even better, they're generally put in place...eventually.
  • brianguy 2009-12-03 13:20
    MC:
    If you scroll up and down really fast you can see a sailboat!



    and here I thought I was the only one who was busy watching the pretty boat go by!
  • Monte 2009-12-03 13:39
    Wouldn't this code need to be converted to C++ first? VB5 code won't compile in a C++ compiler...
  • Adam McCormick 2009-12-03 16:04
    That isn't particularly complicated or difficult to understand. It's actually really simple: each index is a pair in a numeric sequence, each loop simply increments the pair until the higher order pair is equal to its lower neighbors or some predetermined maximum per value. so if all the m values were 16 then:

    Combination:
    00000000000000000000000000000001
    00000000000000000000000000000002
    00000000000000000000000000000102
    00000000000000000000000000000003
    00000000000000000000000000000103
    00000000000000000000000000000203
    00000000000000000000000000010203
    00000000000000000000000000000004
    00000000000000000000000000000104
    00000000000000000000000000000204
    00000000000000000000000000010204
    00000000000000000000000000000304
    00000000000000000000000000010304
    00000000000000000000000000020304
    00000000000000000000000001020304
    etc...

    This gives a list of all possible combinations of values with less 16 or less unique values with 2 or less digits each. Now why you'd want to do that I have no idea.
  • Adam McCormick 2009-12-03 16:16
    Of course if the & in vb5 is a logical AND and not concatenation and if Format just pads with 0s then this generates the logical AND of each pair with is then 1,2,3,3,4,5,6,4,5,6,7,7,8,9,10,5, etc... which i guess could be useful for something maybe?
  • format-shmormat 2009-12-03 16:49
    Right Wing-Nut:

    [snip]

    The format(inn, '00')'s are unconditional, so there are a lot of
    '00's missing from your output.

    [snip]


    I pasted the code into VB6 and ran it with "gaps" in the m() values. The output does not include "00" for each of the ix variables corresponding to an m(x) that equals zero.

    (It scares me that the last sentence actually makes sense.)

    This is because the code - as posted - did not include any variable declaration or initializiation which may have existed in the original. VB can run in a mode that does not require variables to be declared or initialized. In this case, all variables are of the variant data type and have a default value of "" (empty string). So, Format(ix, "00") will produce an empty string when ix is an empty string.

    If, however, the "i" variables were declared as integers, then the output would include "00" for each m(x) equal to zero.
  • bork 2009-12-03 16:54
    It looks kinda cool, kinda like the mothership from Homeworld.
  • Anonymously Yours 2009-12-03 18:05
    Iiitttt... I... it's... so beautiful... grandp-- *head explodes*
  • Jasmine 2009-12-03 19:04
    brianguy:
    something tells me Jasmine has never worked in any kind of fly-by-night startup or dealt with much legacy code before. sure, all those controls (you forgot documentation) are great. even better, they're generally put in place...eventually.


    OK I'll respond to that... my post before was a joke. However, it would not be funny if it didn't have an element of truth. I have been coding for 30 years, and have worked in many shops, from small start-ups to multi-billion dollar international companies. I've seen it all.

    We all know that best practices are so named for a reason. However, what I see in most companies is a feeble attempt at a proper development process, and a heavy focus on "just get it the hell done already" - and surprisingly, this does not always lead to major problems.

    In the places where I've seen TDD and SC systems used properly, and a good attempt at peer reviews, I've only seen a marginal increase in the quality of code. I could name names... there is a vendor I'm working with right now - on their web site they claim to use Agile, claim to use "best practices", claim this and that - but their code quality is some of the worst I've ever seen. Their product costs over 1 million dollars, without customizations... it isn't worth $39.95. There are snippets of code in their product which resemble the WTF in the article. On the other hand, I've also seen products that cost $20, developed by one guy, using no practices anywhere near best, which were done very well and worth way more than the $20.

    I am often on the phone with this vendor discussing their code, and I'm known to say things like "why don't you pull that from source control" or "just send me the documentation for this code, and I'll figure it out from that" - and I fully know that their source control is out of date and there is no documentation.

    Certainly there are places where good practices are followed, but they are fewer than you might think... and in many cases, simply using the process doesn't result in a better product.

    So that's why the joke is funny... and also why it's a joke.
  • Grovesy 2009-12-03 19:13
    In the places where I've seen TDD and SC systems used properly, and a good attempt at peer reviews, I've only seen a marginal increase in the quality of code.


    As much as I am an advocate for practices such as TDD yada yada, I godda agree.. I've seen some really bad code that 'obeys the practice', but comes short of being anything near 'ok'.. (though I have noticed when you see bad tests (with 95% coverage or whatever) you tend to see bad code under it..

    in short, no practice, pattern or language results in better code if the developer is crap.
  • Genitus 2009-12-03 19:59
    Screw you all thats my code and it is great just because you don't uhnderstand it your all useless coders anyway
  • rupert 2009-12-04 00:32
    what except reviews has to do anything with that code snippet ?!
    are you people still in undergraduate management course or something ?!
    :D
  • Silverwizard 2009-12-04 01:36
    This WTF has now been cited on an University paper as an example of Bad Code. Thanks.
  • Manegement 2009-12-04 02:12
    OMG:
    I was wondering this as well, but my working hypothesis is that the current verison of Migrantsoft(R) Vicious(C) Student(C)(R)(TM) lets you paste in code from any Migrantsoft(C) language, and translates it to Mangled(TM) C+/-(R) at runtime. Happy happy joy joy that I get to stay blissfully unaware of such horrors.


    Please could everybody try to be as acidically witty as this poster? Thanks so much.
  • Swedish tard 2009-12-04 04:58
    Grovesy:
    In the places where I've seen TDD and SC systems used properly, and a good attempt at peer reviews, I've only seen a marginal increase in the quality of code.


    As much as I am an advocate for practices such as TDD yada yada, I godda agree.. I've seen some really bad code that 'obeys the practice', but comes short of being anything near 'ok'.. (though I have noticed when you see bad tests (with 95% coverage or whatever) you tend to see bad code under it..

    in short, no practice, pattern or language results in better code if the developer is crap.


    I agree, with crap developers you get crap code. If a crap developer writes the code, and a crap developer reviews it, its gonna pass the review.
    Gotta have a good dev that doesnt mind stepping on toes doing code review. Its completely wasted otherwise.
    No process ever will make bad devs good, thats what experience is for. (And yeah, some people are immune to experience).
    I had a friend that wanted to be a programmer, but his code was downright awful. He asked me for help with a private project once and in a weak moment I said I'd help. He sent me the code and it was just a big clusterfuck. Indentation was wrong all over. He had 2 methods or something of some seriously retarded code. I looked at the code, sa what it was supposed to do and rewrote it from scratch and sent it back to him. He couldnt understand what my code did. I did things like break it up into classes and, ooh, methods! And separate things in a decentish way.
    Anyway, he is one of those that cant write good code if his life depended on it. And he never learned.
  • dr memals 2009-12-04 05:37
    Neville Flynn:
    The goggles, they don't work!!

    "the googles, they do nothing"
    there, fixed it for you.

    Now go and watch the simpsons episode with Bart as fallout boy.
  • methinks 2009-12-04 08:18
    rocco:
    Basic code full of GoTo statements and layers of embedded loops with exits... and no comments. VB doesn't need to be this way. *sigh* It makes me sad to see justification for the anti-VB rants.


    Well... some parts of those anti-VB rants are justified, because any decent structured language simply does not have a "goto"-statement and does not allow for such WTFs in the first place... which does not mean that you can't create massive WTFs in such a language, but a whole class of them simply isn't possible.

    Captcha: inhibeo. indeed, indeed... ;o)
  • Arnold 2009-12-04 08:42
    I wrote that. What part of it do you not understand?
  • Grovesy 2009-12-04 09:16
    methinks:

    Well... some parts of those anti-VB rants are justified, because any decent structured language simply does not have a "goto"-statement and does not allow for such WTFs in the first place...


    Just wondering what you classify as a decent structured programming language. A large number of mainstream languages have 'goto'.

    Not that a I like goto or use it (other than in batch files, SQL error handling, and having to touch some VB6 a couple of years ago)
  • savar 2009-12-04 10:46
    This is probably used in e-voting software to steal votes, and its ingeniously obfuscated to create plausble deniability. Just watch. If Sarah Palin is elected in 2012, we'll all know why.
  • Chris 2009-12-04 10:53
    At least the code's indented...
  • Fred 2009-12-04 22:44
    No1:
    Which part of "legacy code" and "vb5" did you miss? Pretty sure that the code was written before unit tests were invented.


    O yes, I was there back in 1999 when uNIT tests were invented. Before then we had to use tNIT tests (VB5), and pNIT tests (UCSD Pascal). I even worked on DEC FORTRAN accounting system that was built and tested using only fNIT tests. Used to get the NITs out of computer programs (We didn't call them 'Bugs' back then).

    Of course, at the beginning computers were only for hobbyests, so testing wasn't important.
  • Anonymous 2009-12-05 11:25
    The use should be obvious, it's a GUID generator that takes the last GUID in a DB as the input and generates a random, larger GUID.
  • spikeysnack 2009-12-05 13:19
    It appears to be that the writer of this code figured out how to remove null entries in an array by drinking vanilla extract and staring at his clothes in the washing machine at the laundromat.
  • Dan 2009-12-06 19:02
    Whoa man! That's beardy!
  • Anyone 2009-12-06 21:47
    These are not real stories, they're just creative writing.
  • Anyone 2009-12-06 22:24
    CAPTCHA: fiction (everything)
  • WiSK 2009-12-07 06:26
    Silverwizard:
    This WTF has now been cited on an University paper as an example of Bad Code. Thanks.

    Did you explain in your paper why it is "Bad Code"?

    The real WTF is that almost everyone in this thread (and of course submitter Vladimir) has jumped on the bandwagon of 'this has a lot of if statements, it must be bad code'. It is not so difficult to understand why it's not implemented as a recursive function. No one actually gave a correctly working example of how to perform the same computation more elegantly, and if they had I would expect it would either run at half the speed, or be significantly more complex.
  • spleurgh 2009-12-07 08:43
    Now _this_ would make a really good programming praxis.
  • anton 2009-12-07 19:19
    artie:
    it's not a sailboat, it's a schooner. Stupid!


    best quote ever! you win teh prize
  • Right Wing-Nut 2009-12-07 21:01
    format-shmormat:
    Right Wing-Nut:

    [snip]

    The format(inn, '00')'s are unconditional, so there are a lot of
    '00's missing from your output.

    [snip]


    I pasted the code into VB6 and ran it with "gaps" in the m() values. The output does not include "00" for each of the ix variables corresponding to an m(x) that equals zero.

    (It scares me that the last sentence actually makes sense.)

    This is because the code - as posted - did not include any variable declaration or initializiation which may have existed in the original. VB can run in a mode that does not require variables to be declared or initialized. In this case, all variables are of the variant data type and have a default value of "" (empty string). So, Format(ix, "00") will produce an empty string when ix is an empty string.

    If, however, the "i" variables were declared as integers, then the output would include "00" for each m(x) equal to zero.


    Yikes! Now we know why TRWTF is VB 5, I guess.

    It also just makes this example that much more bad. I'm not going to try to refine my version until I can guess exactly wtf this code is supposed to do. Sure, it generates unique combinations of an obscure sort in a way that will guarantee it a sort of immortality. But WHAT IN THE WORLD is this list going to do for us?
  • Muir_Bear 2009-12-12 02:10
    The code snippet puts me in mind of those infamous tests that end with :
    ##) Ignore all of the above instructions except for the first one.

    The main problem is the "Exit For" clauses. If more than one of the "m" array terms is non-zero then you may get either few results or garbage. If the "Exit For" clauses were "Continue For" clauses then you might get something useful. Then there is the problem of the excessive nesting. My FORTRAN teachers would hang those who exceed three levels by their thumbs.

    "Continue For" a la Python

    # NOT INSTALLED #! /opt/ActivePython-2.5/bin/python
    #
    # PCombine16.py
    #
    # http://thedailywtf.com/Articles/The-Who-Knows-Code.aspx
    #
    import string
    import time
    #
    def Combine(Xmax, zCombos) :
    NewCombos = []
    NewTerms = ["00"]
    zLen = len(zCombos)
    print "Xmax = %d | Combo list length = %d" % (Xmax, zLen)
    #
    # In most languages one loops from start to end. Python combines zero-based
    # indexing with near-miss termini. So the following range is effectively zero
    # thru "Xmax - 1" . Hence the "101" in the zero padding trick with slicing
    # ("[1:]") instead of substring or mid$.
    #
    for X in range(0, Xmax) :
    NewX = (str(101 + X))[1:]
    NotFound = True
    for Z in range(0, zLen) :
    Xpos = string.find(zCombos[Z], NewX)
    if Xpos > -1 and Xpos % 2 == 0 :
    NotFound = False
    break
    if NotFound :
    NewTerms.append(NewX)
    if len(NewTerms) > 1 :
    del NewTerms[0] # Peel off the "00" seed for duplicate-free, non-zero Mikes.
    if zLen == 0 :
    NewCombos = NewTerms
    else :
    for NT in range(0, len(NewTerms)) :
    for Z in range(0, zLen) :
    NewCombos.append(zCombos[Z] + NewTerms[NT])
    return NewCombos
    #
    def LPrint(zFP, zList) :
    Space32 = 32 * " "
    for Li in range(0, len(zList)) :
    CurrTerm = zList[Li] + Space32
    # print CurrTerm
    # The print command (Python 2.x) prefers its slicing broken out.
    #
    Quad_1 = CurrTerm[0:8]
    Quad_2 = CurrTerm[8:16]
    Quad_3 = CurrTerm[16:24]
    Quad_4 = CurrTerm[24:32]
    print >> zFP, "%s | %s | %s | %s" % (Quad_1, Quad_2, Quad_3, Quad_4)
    return
    #
    # Unit test section
    #
    if __name__ == "__main__" :
    Mikes = range(1, 16)
    Mikes[7] = 0
    Mikes.append(0)
    for Li in range(0, len(Mikes)) :
    Mikes[Li] = Mikes[Li] * 2
    #
    Part_1 = Combine(Mikes[0], [])
    Part_2 = Combine(Mikes[1], Part_1)
    Part_3 = Combine(Mikes[2], Part_2)
    Part_4 = Combine(Mikes[3], Part_3)
    Part_5 = Combine(Mikes[4], Part_4)
    Part_6 = Combine(Mikes[5], Part_5)
    Part_7 = Combine(Mikes[6], Part_6)
    Part_8 = Combine(Mikes[7], Part_7)
    Part_9 = Combine(Mikes[8], Part_8)
    Part_10 = Combine(Mikes[9], Part_9)
    Part_11 = Combine(Mikes[10], Part_10)
    Part_12 = Combine(Mikes[11], Part_11)
    Part_13 = Combine(Mikes[12], Part_12)
    Part_14 = Combine(Mikes[13], Part_13)
    Part_15 = Combine(Mikes[14], Part_14)
    Part_16 = Combine(Mikes[15], Part_15)
    #
    # print "Contents of the 'Mikes' list :\n", Mikes
    # print "Length of 'Part_16' - ", len(Part_16)
    # The following didn't work so it was broken into two parts.
    # Final = Part_16.sort()
    Final = Part_16
    Final.sort()
    # print "Length of 'Final' - ", len(Final)
    LogFile = open("zCombos.txt", "w")
    print >> LogFile, "Curr. date :", time.strftime("%d %b %y", time.localtime())
    print >> LogFile, "Curr. time :", time.strftime("%H:%M", time.localtime())
    print >> LogFile, "*" + 39 * "-" + "*"
    #
    LPrint(LogFile, Final)
    #
    print >> LogFile, "*" + 39 * "-" + "*"
    print >> LogFile, "Curr. date :", time.strftime("%d %b %y", time.localtime())
    print >> LogFile, "Curr. time :", time.strftime("%H:%M", time.localtime())
    LogFile.close()
    #
    # End of PCombine16.py
  • cindy 2010-12-22 08:52
    find for all kinds of watches and women handbags

    A Lange & Sohne watches
    http://replica038.com/a-lange-sohne-watches.html

    Audemars Piguet watches
    http://replica038.com/audemars-piguet-watches.html

    Ulysse Nardin watches
    http://replica038.com/ulysse-nardin-watches.html
  • apoc9 2011-11-07 19:53
    Code works in mysterious ways.