• CPFC (unregistered) in reply to CPFC

    or even, for added obscurity: For i1 = sgn(m(1)) to m(1)

  • AlanGriffiths (unregistered)

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

    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!

  • (cs) in reply to Mike Caron
    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 (unregistered) in reply to Ilya Ehrenburg
    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 (unregistered) in reply to Grovesy
    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.

  • (cs) in reply to The General
    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.</div>
    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 (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....)

    Then they don't really understand TDD. I find it quicker to write something TDD than to not.

  • Paul A. Bean (unregistered) in reply to Swedish tard
    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 (unregistered) in reply to Paul A. Bean
    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.

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

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

    Wouldn't this code need to be converted to C++ first? VB5 code won't compile in a C++ compiler...

  • Adam McCormick (unregistered)

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

    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 (unregistered) in reply to Right Wing-Nut
    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 (unregistered)

    It looks kinda cool, kinda like the mothership from Homeworld.

  • Anonymously Yours (unregistered)

    Iiitttt... I... it's... so beautiful... grandp-- head explodes

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

    Screw you all thats my code and it is great just because you don't uhnderstand it your all useless coders anyway

  • rupert (unregistered) in reply to Jasmine

    what except reviews has to do anything with that code snippet ?! are you people still in undergraduate management course or something ?! :D

  • Silverwizard (unregistered)

    This WTF has now been cited on an University paper as an example of Bad Code. Thanks.

  • Manegement (unregistered) in reply to OMG
    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 (unregistered) in reply to Grovesy
    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 (unregistered) in reply to Neville Flynn
    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 (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.

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

    I wrote that. What part of it do you not understand?

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

  • (cs) in reply to Vince

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

    At least the code's indented...

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

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

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

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

    Whoa man! That's beardy!

  • Anyone (unregistered)

    These are not real stories, they're just creative writing.

  • Anyone (unregistered)

    CAPTCHA: fiction (everything)

  • WiSK (unregistered) in reply to Silverwizard
    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 (unregistered)

    Now this would make a really good programming praxis.

  • anton (unregistered) in reply to artie
    artie:
    it's not a sailboat, it's a schooner. Stupid!

    best quote ever! you win teh prize

  • Right Wing-Nut (unregistered) in reply to format-shmormat
    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?

  • (cs)

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

    Code works in mysterious ways.

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

Log In or post as a guest

Replying to comment #:

« Return to Article