• ACoward (unregistered)

    This was probably (originally) machine-generated code and never meant for human maintenance.  

  • Rick Scott (unregistered) in reply to ACoward

    This one strikes me as fake.

  • anon (unregistered) in reply to ACoward

    hmm? all code is meant for human maintenance.

  • Anonymous (unregistered)

    maybe he read somewhere that he shouldn't use magic numbers... but that 0 and 1 were generally accepted as exceptions to that rule.

  • Pavel (unregistered)

    Indenting was added by the editor?

    Damn. I can't even imagine the original. I wonder if it was all on one line.

  • James (unregistered)
    Alex Papadimoulis:
    } //ED: Indenting added



  • (cs)

    Was he trying to draw some ascii art?

  • (cs)
    Alex Papadimoulis:

    void RstPccoLv(int curIdx) {

    if (sysobjs[curIdx * (ZERO + ONE + ONE + ONE ...)] == OEXOOOOOOFOURE - OXOOOOOOTHREETWO)
    {
    ... } } //ED: Indenting added


  • (cs) in reply to Alexis de Torquemada

    Make that OHEXOHOHOHOHOHOHTHREETWO, it's more readable.

  • (cs)

    aaargh!

  • (cs) in reply to AndrewVos

    MENTAL NOTE : Dont pay this guy per hour!

  • (cs) in reply to AndrewVos
    AndrewVos:
    MENTAL NOTE : Dont pay this guy per hour!


    Pay him per character
  • (cs)

    W! T! F!!! [:|]

    Best one I've seen in a while...

  • (cs)

    Uhhhhhhhhhhh.....

    Its obvious the author of this excrement piece of code was just being an asshat. The only  excuse for writing code like this is to make life for people behind him or her difficult. Must have known a pink slip was coming down the pike when he/she wrote this.

     

  • Anonymous Coward (unregistered)

    What movie is that quote from?!?!  "...things...terrible things...unspeakable things..."  It's driving me insane.

  • (cs)

      Even if you take out all of the crazy "0 + 1 + 1 + 1 ..." garbage, I still cannot figure out what this code is supposed to be doing. It looks to me like the overall design here should be called into question.

       The other issue here is that this code takes a number that is passed in as an argument and uses it to produce an index for an array and then tries to access the value of that array index without first checking to see if it is out of range.

        Out of sheer curiosity about what this code is doing, I refactored it into something more readable. After which, I looked at it and thought, "WTF!"


        Here is the refactored version. All comments are obviously my own.

    void RstPccoLv(int curIdx)
            {

                if (sysobjs[curIdx * 10] == 0x1c && sysobjs[curIdx * 9] > -1)    // condition must be true for any other code to execute
                {
                    sysobjs[curIdx * 8] = 0;
     
                    if (sysobjs[sysobjs[curIdx * 9] * 13] < 0)
                        sysobjs[sysobjs[curIdx * 9] * 13] += 4;

                    // the following two sections check the value of a given index of the array
                    // it looks like they really could be 'if...else if' statements since they appear
                    // to be mutually exclusive
       
                    ///////////////////////////////////////////////////////////////////
                    // First section - when sysobjs[sysobjs[curIdx * 9] * 10] == 0x18
                    ///////////////////////////////////////////////////////////////////
                    if (sysobjs[sysobjs[curIdx * 9] * 10] == 0x18)
                    {
                        sysobjs[sysobjs[curIdx * 9] * 8] = 0;
                        XPos2 = sysobjs[curIdx * 9];
           
                        if (XPos2 + 1 < nbObj)
                        {
                            while (sysobjs[(XPos2 + 1) * 10] == 0x18)
                            {
                                sysobjs[(XPos2 + 1) * 8] = 0;
                                XPos2++;
                            }
                        }
                    }
                    ///////////////////////////////////////////////////////////////////
                    // Second section - when sysobjs[sysobjs[curIdx * 9] * 10] == 0x1b
                    ///////////////////////////////////////////////////////////////////
                    if (sysobjs[sysobjs[curIdx * 9] * 10] == 0x1b)
                    {
                        if ((sysobjs[curIdx * 11] & (1 << 4)) == 0)
                            sysobjs[curIdx

    • 8] = 0;
                          else
                              sysobjs[curIdx
    • 8] = 1;
                      }
                  }
              }
  • JohnO (unregistered)

    He probably came from my old student job, a data entry clerk getting paid by the keystroke...

    I wouldn't say this is machine generated, the variables have (almost) meaningful names.

    Also it can't be for compiler optimisation (assuming x86) where INC is faster than ADD in some cases, 'cos he's doing curIdx*8 instead of curIdx<<3.

    It's manipulating a linked list of 8-byte (I'm assuming bytes) structures stored in the byte array sysobjs.  The index of the next structure linked is stored in (stucture offset)+1 and it's setting the (structure offset)+0 byte to zero depending on the value of some of the others.

    My guess goes to low-level microcontroller code... if this is in a high level system, I say WTF?!

  • (cs) in reply to skicow
    skicow:

    W! T! F!!! [:|]



    I would say that even if you fixed the obvious top-level WTF, namely the bizarre numeric constants, the code that remained would be no less of a WTF.

    That is quite an achievement.

  • (cs) in reply to Anonymous Coward
    Anonymous Coward:
    What movie is that quote from?!?!  "...things...terrible things...unspeakable things..."  It's driving me insane.


    A quick google search shows it to apparently be from an episode of Babylon 5 titled "Comes the Inquisitor".

    More of the quote:  "In the pursuit of my holy cause, I... did things, terrible things, unspeakable things. The world condemned me, but it didn't matter because I believed I was right and the world was wrong."
  • (cs) in reply to stevekj

    Ah, I see that limelight is all over that... didn't post fast enough!

  • christoofar (unregistered) in reply to stevekj

    No way this is C code to do optimizations... the computer is still doing work just to calculate what 0+1 is (fruitless since that doesn't do anything).

    I'd hate to see how this guy does a NOP.

  • tako (unregistered)

    one must replace duplicating code with variables, and it is good if name of the variable explains code it replacing. for example:

    zeroPlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOne = 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1;
    zeroPlusOnePlusOne = 0 + 1 + 1;
    zeroPlusOne = 0 + 1;
    one = 1;
    zero = 0;
    if (sysobjs[curIdx * zeroPlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOne + zeroPlusOnePlusOne] == 0x0000004e - 0x00000032)
    {
        if (sysobjs[curIdx * zeroPlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOne +zeroPlusOne] > -one)
       {
            sysobjs[curIdx * zeroPlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOne + zero] = zero;

    and so on...

  • (cs) in reply to Ytram

    The person in question was Jack the Ripper who had been employed by the Vorlons.

    No, seriously.

  • (cs)

      I've fallen victim to this code's entrancing addition and forgot to pay attention to the order of operations. So, after posting my own WTF above, let me try this one more time. Here is a quick refactor of the code with operations in parenthesis for clarity. It now becomes clear that the array contains some kind of eight byte long structures as JohnO pointed out above. Perhaps the designer never heard of a class or struct before? It would be much easier to deal with an array of structs than it would be to deal with this mess.

    void RstPccoLv(int curIdx)
            {
                if (sysobjs[(curIdx * 8) + 2] == 0x1c && sysobjs[(curIdx * 8) + 1] > -1)    // condition must be true for any other code to execute
                {
                    sysobjs[(curIdx * 8)] = 0;
         
                    if (sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 5] < 0)
                        sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 5] += (4);

                    // the following two sections check the value of a given index of the array
                    // it looks like they really could be 'if...else if' statements since they appear
                    // to be mutually exclusive
       
                    ///////////////////////////////////////////////////////////////////
                    // First section - when sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 2] == 0x18
                   ///////////////////////////////////////////////////////////////////

                    if (sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 2] == 0x18)
                    {
                        sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 0] = 0;
                        XPos2 = sysobjs[(curIdx * 8) + 1];
           
                        if ((XPos2 + 1) < nbObj)
                        {
                            while (sysobjs[((XPos2 + 1) * 8) + 2] == 0x18)
                            {
                                sysobjs[(XPos2 + 1) * 8] = 0;
                                XPos2++;
                            }
                        }
                    }
                    ///////////////////////////////////////////////////////////////////
                    // Second section - when sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 2] == 0x1b
                    ///////////////////////////////////////////////////////////////////
                    if (sysobjs[(sysobjs[(curIdx * 8) + 1] * 8) + 2] == 0x1b)
                    {
                        if ((sysobjs[(curIdx * 8) + 3] & (1 << 4)) == 0)
                            sysobjs[curIdx

    • 8] = 0;
                          else
                              sysobjs[curIdx
    • 8] = 1;
                      }
                  }
              }
  • (cs)

    Interesting that the 1's are in groups of eight.  This is just a spelled-out version of octal notation.

  • Andir (unregistered) in reply to Maurits

    Of course!!

    It's Binary math.

  • Aim Here (unregistered)

    Obviously this coder has got advance warning of a sneaky plot by those sickos at ANSI to change the default number base for C and C++ from denary to ternary, so he's future-proofing his code. We can mock now, but when every single number in every single line of source code has to be rewritten to conform to the new spec just in order to compile, he'll have the last laugh...


  • (cs) in reply to limelight

    limelight:
      Even if you take out all of the crazy "0 + 1 + 1 + 1 ..." garbage, I still cannot figure out what this code is supposed to be doing. It looks to me like the overall design here should be called into question.

    <FONT face="Courier New" size=2>if this is straight up C, then danger will robinson.  but in C++, you can overload the operators, right?  maybe they were thinking spelled out bitmasks were easier to understand.  of course, why they'd do that and then throw hex values in there seems odd.</FONT>

    <FONT face="Courier New" size=2>conclusion: this is a more quiet and shy jed.</FONT>

  • (cs) in reply to emptyset
    emptyset:

    <font face="Courier New" size="2">conclusion: this is a more quiet and shy jed.</font>



    There is good Jed and evil Jed. This is Evil Jed.
  • (cs)

    My eyes! They bleed!

  • vhawk (unregistered)

    They got a monkey to hit a keyboard at random right ?  No one with 2 live brain cells will write cr*p like this !

  • John Doe (unregistered) in reply to vhawk

    Wow, what a nice piece of maintainable code! I wonder what they do when they need to add a new field to that 8 byte "structure". That, and RstPccoLv... I mean, WTF is Rest Picco Lev stand for?

  • (cs)

    It all makes sense now! I now understand how managers are created, because if this guy had been promoted to management he'd be too busy playing golf to have time to write code...... any code.

  • Mario (unregistered) in reply to stevekj
    stevekj:
    skicow:

    W! T! F!!! [:|]



    I would say that even if you fixed the obvious top-level WTF, namely the bizarre numeric constants, the code that remained would be no less of a WTF.

    That is quite an achievement.

    What, a meta-WTF?

  • Chekov (unregistered) in reply to Anonymous Coward

    Anonymous:
    What movie is that quote from?!?!  "...things...terrible things...unspeakable things..."  It's driving me insane.

    He put creatures in our bodies... made us... do things... terrible things...

  • (cs) in reply to Chekov
    Anonymous:

    Anonymous:
    What movie is that quote from?!?!  "...things...terrible things...unspeakable things..."  It's driving me insane.

    He put creatures in our bodies... made us... do things... terrible things...



    http://www.imdb.com/title/tt0084726/
  • (cs) in reply to Mike R

    This code isn't so bad -- you guy just don't understand the brillance of sysobjs.

  • Metasheep (unregistered) in reply to JohnO

    The code is from a J2ME project.  While J2ME forces you to do some nasty, ugly, horribly un-Java things to save on jar size, this went above and beyond anything that I or my workmates have ever done.

  • Fletch (unregistered) in reply to tako

    Anonymous:
    zeroPlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOnePlusOne = 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1;
    zeroPlusOnePlusOne = 0 + 1 + 1;
    zeroPlusOne = 0 + 1;
    one = 1;
    zero = 0;

    You forgot:

    zeroXZeroZeroZeroZeroZeroZeroFourE = 0x0000004e
    zeroXZeroZeroZeroZeroZeroZeroThirtyTwo  = 0x00000032

    Because there should be no bias.

  • yxhuvud (unregistered)

    This guy is a pure genius. I am very impressed with that code, it would take a genius to concoct such a thing and make it work.

    Only problem is that he is the evil kind of genius :)

  • Nate (unregistered)

    Don’t you think this was run through some sort of obfuscator utility? I doubt he actually wrote that himself.

  • (cs) in reply to ACoward

    ACoward:
    This was probably (originally) machine-generated code and never meant for human maintenance.  

    Yeah, generated by a machine that can't add.

  • Diep-Vriezer (unregistered) in reply to Nate

    Remove the indenting, and you might see Satan pissing on the world.

  • (cs) in reply to limelight

    Okay, I'm going to try to refactor at least a little bit.. using advanced features like "functions".  It looks like sysobjs is an 8

    • n array of integers...  This might be done better with operator overloading or something...


    // returns sysobjs[idx1][idx2], without bounds checking.
    int getSysObj(int idx1, int idx2)
    {
      return sysobjs[idx1*8 + idx2];
    }

    // sets sysobjs[idx1][idx2] to newval, without bounds checking.
    void setSysObj(int idx1, int idx2, int newval)

    {

      sysobjs[idx1*8 + idx2] = newval;

    }


    void RstPccoLv(int curIdx)
            {
                if (getSysObj(curIdx, 2) == 0x1c  &&  getSysObj(curIdx, 1) > -1)    // condition must be true for any other code to execute
                {
                    setSysObj(curIdx, 0, 0);
         
                    if (getSysObj(getSysObj(curIdx, 1), 5) < 0)
                        setSysObj(getSysObj(curIdx, 1), 5, getSysObj(getSysObj(curIdx, 1), 5) + 4);  // I know.. this is ugly..

                    // the following two sections check the value of a given index of the array
                    // it looks like they really could be 'if...else if' statements since they appear
                    // to be mutually exclusive
       
                    ///////////////////////////////////////////////////////////////////
                    // First section - when sysobjs[sysobjs[curIdx][1]][2] == 0x18
                   ///////////////////////////////////////////////////////////////////

                    if (getSysObj(getSysObj(curIdx, 1), 2) == 0x18)
                    {
                        setSysObj(getSysObj(curIdx, 1), 0, 0);
                        XPos2 = getSysObj(curIdx, 1);
           
                        if ((XPos2 + 1) < nbObj)
                        {
                            while (getSysObj(XPos2 + 1, 2) == 0x18)
                            {
                                setSysObj(XPos2 + 1, 0, 0);
                                XPos2++;
                            }
                        }
                    }
                    ///////////////////////////////////////////////////////////////////
                    // Second section - when sysobjs[sysobjs[curIdx][1]][2] == 0x1b
                    ///////////////////////////////////////////////////////////////////
                    if (getSysObj(getSysObj(curIdx, 1), 2) == 0x1b)
                    {
                        if ((getSysObj(curIdx, 3) & (1 << 4)) == 0)
                            setSysObj(curIdx, 0, 0);
                        else
                            setSysObj(curIdx, 0, 1);
                    }
                }
            }


    There.  If anyone wants to clean that up, go ahead.  I am at work and have spent 15 minutes on this and really shouldn't spend any more... or my boss will be saying "WTF"  :)

    Also, there's a good chance I've made some typos and/or that that this will not compile...

  • Sean Fisher (unregistered)

    The movie line that came to me when reading the code was:

    All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy. All work and no play makes Jack a dull boy.

  • josh (unregistered) in reply to christoofar
    Anonymous:
    No way this is C code to do optimizations... the computer is still doing work just to calculate what 0+1 is (fruitless since that doesn't do anything).


    The *compiler* is doing work to calculate 0+1.  Only the most brain-dead compiler for any language would actually write out those additions.

    emptyset:
    but in C++, you can overload the operators, right?


    Only when a user-defined type is involved.  0 and 1 both have type int, and you can't override operator+(int, int).
  • (cs) in reply to dubwai

    dubwai:
    Yeah, generated by a machine that can't add.

    <FONT face="Courier New" size=2>your machine is an accumulator with only two instructions:</FONT>

    <FONT face="Courier New" size=2>and(b) : takes the value in the accumulator and performs </FONT><FONT face="Courier New" size=2>an 'and' (&) on the bit b.  ex. '5' and(1) leaves '4' in the register.</FONT>

    <FONT face="Courier New" size=2>clear : takes the value in the accumulator and clears it.</FONT>

    <FONT face="Courier New" size=2>takeshi_kagav("allez cuisine!") ;</FONT>

    <FONT face="Courier New" size=2></FONT> 

  • Mr VacBob (unregistered) in reply to josh
    Anonymous:
    The *compiler* is doing work to calculate 0+1.  Only the most brain-dead compiler for any language would actually write out those additions.

    Sun javac will.

  • (cs)

    I'm willing to be that this is C++ with operator overloading for the indexing operator.
    They are using some sort of bit twiddling with the index in the operator, and wanted to have an explicit way to see the bit fields.


  • (cs) in reply to emptyset
    emptyset:

    dubwai:
    Yeah, generated by a machine that can't add.

    <font face="Courier New" size="2">your machine is an accumulator with only two instructions:</font>

    <font face="Courier New" size="2">and(b) : takes the value in the accumulator and performs </font><font face="Courier New" size="2">an 'and' (&) on the bit b.  ex. '5' and(1) leaves '4' in the register.</font>

    <font face="Courier New" size="2">clear : takes the value in the accumulator and clears it.</font>

    <font face="Courier New" size="2">takeshi_kagav("allez cuisine!") ;</font>

    <font face="Courier New" size="2"></font> 



    While your machine is interestingly similar to brainfuck, I don't think it's quite the same type of stupid as the stupid machine to which dubwai alludes.

    What method of bit-numbering leads to '5' and(1) == '4', anyway? The sanest choices would be 1-based octal or 0-based hex, which should give you some idea just how little sanity there is to be had here.

Leave a comment on “Alone In The Code”

Log In or post as a guest

Replying to comment #45754:

« Return to Article