• D-Coder (cs) in reply to A Gould
    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 (unregistered) in reply to Franz Kafka
    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 (unregistered) in reply to rocco

    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 (unregistered)

    Unit tests? Source control? Peer reviews? Are you people still in college or something?!

  • Bim Job (unregistered) in reply to Grovesy
    Comment held for moderation.
  • Wyrd (unregistered) in reply to D-Coder
    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 (unregistered) in reply to WiSK
    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 (cs) in reply to Anonymous
    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 (unregistered) in reply to Gary
    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 (unregistered) in reply to Crash Magnet
    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 (unregistered) in reply to OMG
    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 (unregistered)

    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 (unregistered) in reply to Anonymous

    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 (unregistered) in reply to Grovesy
    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 (cs)

    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 (unregistered) in reply to Jasmine
    Jasmine:
    Unit tests? Source control? Peer reviews? Are you people still in college or something?!

    No, IBM

  • SDC (unregistered)

    No college student is that stupid.

    Sounds like somebody's headhunter jazzed up the resume for them.

  • noob (unregistered) in reply to Prosthetic Lips
    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 (unregistered) in reply to md5sum
    md5sum:
    Vladmir had the incredible, once-in-a-lifetime opportunity to do a full rewrite of a legacy application

    That.

  • Bim Job (unregistered) in reply to smxlong
    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 (unregistered)

    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 (unregistered) in reply to Jasmine
    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 (unregistered) in reply to noob
    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 (unregistered) in reply to fist-poster
    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 (unregistered) in reply to highphilosopher
    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 (unregistered)

    Translate it to VHDL and compile it to a gate array. It might actually be easier to understand.

  • SOmeGuy (unregistered) in reply to Anonymous

    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 (unregistered)

    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 (unregistered) in reply to rocco
    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 (unregistered) in reply to SOmeGuy
    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 (unregistered) in reply to Gary
    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 (cs) in reply to Rene
    Rene:
    The person who produced this code is a true genius!

    You mean, "... a true evil genius!"

  • Amerrickangirl (unregistered) in reply to Gary
    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 (unregistered)
    Comment held for moderation.
  • pegr (unregistered) in reply to Jasmine

    Unit tests? Source control? Peer review? You are obviously still in college! ;)

  • fist-poster (cs) in reply to Loren Pechtel
    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 (unregistered) in reply to Amerrickangirl
    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 (unregistered) in reply to Jasmine

    And what happened next .... !?
    Punchline people, did it work? Did it fail ?

  • RogerInHawaii (cs) in reply to undefined
    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 (cs) in reply to Eric Howe
    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 (unregistered) in reply to Coyne

    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 (unregistered) in reply to justsomedude
    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 (unregistered) in reply to RogerInHawaii
    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</div></BLOCKQUOTE>
    

    I think you missed worserer

  • Bim Job (unregistered) in reply to RogerInHawaii
    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</div></BLOCKQUOTE>I come from Warwickshire, and I <i>resent</i> that remark.
    

    Hawaii the lads!

    Roger and out.

  • Jason Q (unregistered)

    Is thissimilar to how Java implements 'Contains'?

  • mypalmike (unregistered)

    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 (unregistered)

    Generate all possible drawings of numbers from jars with m(i) balls (in jar number i), where no two numbers are the same?

  • Tukaram (unregistered) in reply to Jasmine
    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 (unregistered) in reply to Jasmine

    College?

  • Mason Wheeler (cs) in reply to justsomedude
    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."

Leave a comment on “The "Who Knows?" Code”

Log In or post as a guest

Replying to comment #:

« Return to Article