• Mr.'; Drop Database -- (unregistered) in reply to Zapp Brannigan
    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. [image]
  • J. Pablo Fernández (unregistered)

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

    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 (unregistered) in reply to J. Pablo Fernández
    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 (unregistered)

    Nice bow, btw...

  • (cs) in reply to Prosthetic Lips
    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

  • (cs)

    Trying to iterate combinations of up to 15 items?

  • ZZMike (unregistered)

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

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

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

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

    WTF?! Really...

    Excuse me, gonna go puke now.

  • (cs)

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

    Might want to hit up youtube for the real wording. Hint: it's not what everyone thinks it is.

  • Jimmy McJimbo (unregistered) in reply to Jasmine

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

    This looks like what happens when computers generate code.

  • (cs) in reply to Mr.'; Drop Database --
    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. [image]
    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 (unregistered) in reply to Jasmine

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

    I wonder how that code would react like this if it saw itself. Possibly somewhat like this:

    http://www.youtube.com/watch?v=Ka1PeNNi6dg

  • (cs) in reply to J. Pablo Fernández
    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 (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. 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 (unregistered)

    The real wtf is that he expects he can copy VB code and have it compile in a C++ compiler...

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

    You are delusional...

  • Adam Thompson (unregistered) in reply to Jasmine

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

    How would unit tests help you out here?

    Cheers, S.

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

  • (cs) in reply to Anonymous Organ Donor
    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 (unregistered)

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

  • (cs) in reply to Adam Thompson
    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 (unregistered)

    svn blame?

  • No1 (unregistered) in reply to Jasmine

    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.

  • (cs)
    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? (unregistered) in reply to No1
    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 (unregistered) in reply to MC
    MC:
    If you scroll up and down really fast you can see a sailboat!

    Brenda?

  • StarLite (unregistered)

    I accidentally this code, would this be a problem?

  • Paul A. Bean (unregistered) in reply to Bim Job
    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 (unregistered) in reply to artie
    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 (unregistered) in reply to stefan, rzeźnik
    stefan:
    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 (unregistered) in reply to Jasmine

    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 (unregistered) in reply to the real wtf fool
    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 (unregistered) in reply to G
    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 (unregistered) in reply to Jasmine

    Feelin' stupid for writing something similar?

    ;-)

  • Zan (unregistered) in reply to password

    I can think of a few other things which require those same implements... Can't mention them here though

  • undefined (unregistered) in reply to J. Pablo Fernández
    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!

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

    Thanks for the belly laugh. Hilarious

  • wtf? (unregistered)
    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 (unregistered) 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.

    How about:

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

    ?

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

Log In or post as a guest

Replying to comment #292275:

« Return to Article