Comment On Alone In The Code

It can be a pretty frightening prospect to take the helms, full time, as the Sole Maintainer of a system. Being all alone in the system ... it can ... it can make programmers do things .... terrible things ... unspeakable things. Let's hope J Rojas doesn't succumb to the same fate as his predecessor, who proudly concocted this twisted tally system for indices of object arrays throughout the system ... [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Alone In The Code

2005-10-03 11:56 • by ACoward
This was probably (originally) machine-generated code and never meant for human maintenance.  

Re: Alone In The Code

2005-10-03 12:01 • by Rick Scott
45732 in reply to 45730
This one strikes me as fake.

Re: Alone In The Code

2005-10-03 12:01 • by anon
45733 in reply to 45730
hmm? *all* code is meant for human maintenance.

Re: Alone In The Code

2005-10-03 12:03 • by Anonymous
maybe he read somewhere that he shouldn't use magic numbers... but that
0 and 1 were generally accepted as exceptions to that rule.

Re: Alone In The Code

2005-10-03 12:08 • by Pavel
Indenting was added by the editor?



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

Re: Alone In The Code

2005-10-03 12:09 • by James
Alex Papadimoulis:

} //ED: Indenting added






Re: Alone In The Code

2005-10-03 12:10 • by spotcatbug
Was he trying to draw some ascii art?

The obligatory version without magic numbers

2005-10-03 12:16 • by Alexis de Torquemada
Alex Papadimoulis:

void RstPccoLv(int curIdx) {

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




Re: The obligatory version without magic numbers

2005-10-03 12:19 • by Alexis de Torquemada
45740 in reply to 45739
Make that OHEXOHOHOHOHOHOHTHREETWO, it's more readable.



Re: Alone In The Code

2005-10-03 12:33 • by AndrewVos
aaargh!

Re: Alone In The Code

2005-10-03 12:33 • by AndrewVos
45742 in reply to 45741
MENTAL NOTE : Dont pay this guy per hour!

Re: Alone In The Code

2005-10-03 12:42 • by Beek
45744 in reply to 45742
AndrewVos:
MENTAL NOTE : Dont pay this guy per hour!




Pay him per character

Re: Alone In The Code

2005-10-03 12:43 • by skicow

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


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

Re: Alone In The Code

2005-10-03 12:53 • by Mike R

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.


 

What movie is that from?

2005-10-03 13:01 • by Anonymous Coward
What movie is that quote from?!?!  "...things...terrible things...unspeakable things..."  It's driving me insane.

Re: Alone In The Code

2005-10-03 13:03 • by 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.



   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;

                }

            }

        }

Re: Alone In The Code

2005-10-03 13:03 • by JohnO
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?!

Re: Alone In The Code

2005-10-03 13:08 • by stevekj
45752 in reply to 45745
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.



Re: What movie is that from?

2005-10-03 13:08 • by Ytram
45753 in reply to 45748
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."

Re: Alone In The Code

2005-10-03 13:09 • by stevekj
45754 in reply to 45752
Ah, I see that limelight is all over that... didn't post fast enough!

Re: Alone In The Code

2005-10-03 13:15 • by christoofar
45755 in reply to 45754
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.

Re: Alone In The Code

2005-10-03 13:25 • by tako
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...

Re: What movie is that from?

2005-10-03 13:27 • by RobbieGee
45757 in reply to 45753
The person in question was Jack the Ripper who had been employed by the Vorlons.

No, seriously.

Re: Alone In The Code

2005-10-03 13:32 • by limelight
  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;

                }

            }

        }

Re: Alone In The Code

2005-10-03 13:38 • by Maurits
Interesting that the 1's are in groups of eight.  This is just a spelled-out version of octal notation.

Re: Alone In The Code

2005-10-03 13:41 • by Andir
45761 in reply to 45759

Of course!!


It's Binary math.

Re: Alone In The Code

2005-10-03 13:48 • by Aim Here
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...





Re: Alone In The Code

2005-10-03 13:50 • by emptyset
45764 in reply to 45749

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.


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.


conclusion: this is a more quiet and shy jed.

Re: Alone In The Code

2005-10-03 13:56 • by Mike R
45765 in reply to 45764
emptyset:

conclusion: this is a more quiet and shy jed.





There is good Jed and evil Jed. This is Evil Jed.

Re: Alone In The Code

2005-10-03 14:03 • by res2
My eyes! They bleed!

Re: Alone In The Code

2005-10-03 14:14 • by vhawk
They got a monkey to hit a keyboard at random right ?  No one with 2 live brain cells will write cr*p like this !

Re: Alone In The Code

2005-10-03 14:17 • by John Doe
45770 in reply to 45769
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?

Re: Alone In The Code

2005-10-03 14:25 • by retnuh
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.

Re: Alone In The Code

2005-10-03 14:40 • by Mario
45773 in reply to 45752
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?

Re: What movie is that from?

2005-10-03 14:42 • by Chekov
45775 in reply to 45748

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

Re: What movie is that from?

2005-10-03 14:43 • by Maurits
45776 in reply to 45775
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/

Re: Alone In The Code

2005-10-03 14:52 • by JohnO
45778 in reply to 45765

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

Re: Alone In The Code

2005-10-03 15:01 • by Metasheep
45780 in reply to 45778
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.

Re: Alone In The Code

2005-10-03 15:15 • by Fletch
45781 in reply to 45756

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.

Re: Alone In The Code

2005-10-03 15:31 • by yxhuvud
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 :)

Re: Alone In The Code

2005-10-03 15:41 • by Nate
Don’t you think this was run through some sort of obfuscator utility? I doubt he actually wrote that himself.

Re: Alone In The Code

2005-10-03 16:02 • by dubwai
45786 in reply to 45730

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


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

Re: Alone In The Code

2005-10-03 16:05 • by Diep-Vriezer
45788 in reply to 45784
Remove the indenting, and you might see Satan pissing on the world.

Re: Alone In The Code

2005-10-03 16:19 • by kipthegreat
45790 in reply to 45758
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...

Re: Alone In The Code

2005-10-03 16:26 • by Sean Fisher
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.

Re: Alone In The Code

2005-10-03 16:28 • by josh
45793 in reply to 45755
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).

Re: Alone In The Code

2005-10-03 16:29 • by emptyset
45794 in reply to 45786

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


your machine is an accumulator with only two instructions:


and(b) : takes the value in the accumulator and performs an 'and' (&) on the bit b.  ex. '5' and(1) leaves '4' in the register.


clear : takes the value in the accumulator and clears it.


takeshi_kagav("allez cuisine!") ;


 

Re: Alone In The Code

2005-10-03 16:39 • by Mr VacBob
45795 in reply to 45793
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.

Re: Alone In The Code

2005-10-03 16:44 • by Ayende Rahien
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.





Re: Alone In The Code

2005-10-03 16:58 • by emurphy
45797 in reply to 45794
emptyset:

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


your machine is an accumulator with only two instructions:


and(b) : takes the value in the accumulator and performs an 'and' (&) on the bit b.  ex. '5' and(1) leaves '4' in the register.


clear : takes the value in the accumulator and clears it.


takeshi_kagav("allez cuisine!") ;


 





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.

« PrevPage 1 | Page 2 | Page 3Next »

Add Comment