Forums - Open Redstone Engineers

Full Version: Everyone's worst code!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Here is a new thread, where we must post the bits of code everyone is embarrassed about! I'll start
Code:
###RSW's code for finding the colour of a ranking
def colour(colour):
    return {0:'f',
              1:'e',
              2:'a',
              3:'5',
              4:'0'}[colour]
### Silly RSW
###He could just have used
def colour(colour):
    return 'fea50'[colour]
###<3

This is an excert from my TofuJumper game, which was made mainly to annoy mort.
Code:
global loc, vel, clox, plat, l, r, jumpwait, highest, m, plats, cv, cloc, mplats, mplat, powerups, ability, abilityc, jumppower, sinit, gent, score, gravity, size, Xrange, Poslist, squish, squishv, cubes

loc, vel, cloc, plat, mplat, l, r, jumpwait, highest, m, cv, abilityc, sinit, gent, score, Xrange, squish, squishv, cubes = ([10,10], [0,0], 0, 1, '<3Red', 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, (0,300), 0, 0, 30)
it seems late nights cause you to forget about the existence of classes.
Code:
def message(message):
    output = []
    for i in message:
        output.append(i)
    print(str(output))

message = ['h','i']
message(message)

This is the worst I could think of.
TequilaJumper!
Made for Ludum Dare with minimal amounts of experience, it's not of my prettiest of works. It did however spawn some offspring in the form of xeo's TofuJumper.

Because of open sourceness, the source code can be found here: https://github.com/mortie/tequilaJumper

So, let's have a look at it shall we?

You don't even have to look at any of the source code to find the first horrible decision. Everything in one file. One index.html, containing almost 800 lines of source code. Yeeah.

Opening the file, we see even more disastrous code. Take for instance this draw code:[line 218]
Code:
gameCtx.fillStyle = "rgba(0, 0, 0, 0.5";
gameCtx.beginPath();
gameCtx.moveTo(Math.floor(platformStartX[i]+platformWidth[i]/2), Math.floor(drawYModifier(platformStartY[i]+platformHeight[i]/2, 0)));
gameCtx.lineTo(Math.floor(platformEndX[i]+platformWidth[i]/2), Math.floor(drawYModifier(platformEndY[i]+platformHeight[i]/2, 0)));
gameCtx.stroke();
Beautiful innit? That was the code for drawing lines marking the path of moving platforms (play it for yourself, and you'll see what I mean).

This one-liner is quite extraordinary too:[line 271]
Code:
gameCtx.fillRect (Math.floor(platformX[i]), Math.floor(drawYModifier(platformY[i], platformHeight[i])), Math.floor(platformWidth[i]), Math.floor(platformHeight[i]));
Yup, that's one line, even tho the forums' word wrap make it look like multiple.

In the code for handling the movement of platforms (which is a complex mess of work too by the way, starting at line 283 and ending at 349): [line 324]
Code:
//HAAAAAACK!
platformMovementInvertedX[i] = platformMovementInvertedY[i];

Yup. Encountered a bug I didn't manage to fix, so I simply hacked my way around it using an extremely dirty trick.

Another thing, which isn't as clearly expressed in the code, but maybe is worst of them all:
When a platform is disappearing off of the screen, it doesn't disappear. It's still stored in memory - it doesn't get overwritten by new platforms. This leads to a very ugly memory leak. That's right. Platforms never despawn.

That's a selection of the worst parts of the code. Other ineresting areas are:
  • character controls [line 411]
  • collision detection [line 451]
  • hack to get the player to stick to the platform [line 511]
  • init [line 685]

Oh, and I almost forgot:
Almost all variables are global. Just look at the variable declaration part [line 7-73] :S

EDIT:
to my defence, it _was_ made for Ludum Dare, AND I attended a party which took most of my weekend. The time was therefore very limited. It's also very fun to hack away on code, not spending a single thought on structure, and just see where you end up. The code becomes extremely horrible and unreadable, but it's still very fun ;P
My exapmles will fill up the HDD of this server so I won't post them Smile
The worst code I have in my current project:

Code:
void kprintf(char *format, ...)
{
    char *p;
    int i;
    uint64_t i64;
    unsigned u;
    char *s;
    va_list argp;

    va_start(argp, format);

    p = format;
    for(p = format; *p != '\0'; p++)
    {
        if(*p != '%')
        {
            putch(*p);
            continue;
        }
        p++;

        switch(*p)
        {
            case 'c':
                i = va_arg(argp, int);
                putch(i);
                break;
            case 'd': case 'i':
                i = va_arg(argp, int);

                if(i < 0)
                {
                    i = -i;
                    putch('-');
                }

                puts(convert(i, 10));
                break;
            case 'l':
                i64 = va_arg(argp, uint64_t);
                puts(convert_u(i64, 10));
                break;
            case 'o':
                i = va_arg(argp, int);
                puts(convert(i, 8));
                break;
            case 's':
                s = va_arg(argp, char*);
                puts(s);
                break;
            case 'u':
                u = va_arg(argp, unsigned int);
                puts(convert_u((uint64_t) u, 10));
                break;
            case 'x':
                i64 = va_arg(argp, uint64_t);
                puts(convert_u(i64, 16));
                break;
            case 'b':
                u = va_arg(argp, unsigned int);
                puts(convert(u, 2));
                break;
            case '%':
                putch('%');
                break;
        }
    }

    va_end(argp);
}
blagpostified the post I wrote here: http://mortie.org/blog?post=my_worst_code
:3
My worest code was the first batea of AdditionalCrafting I will not post for it would burn Xeo's eyes out.
My turn:
Code:
!break!
//Bills code for trying to identify a varible change in Java
//and C++ w/Script port for Arduino
##Start##
idf.change.var.(portvar1)
serial.change.ping.(20ms)
<port>
##End##
//C++
int portvar1 ;
int portserial = 20 ;
varible = portvar1, portvar1
Could of called portvar1 anything.
int portserial = 20 ; Not needed also.
STUPID PORT SYSTEM FOR JAVA.
PS. this is one of 250gb of bad code I have D:

Just remembered that the //arduino bit isn't needed.
'250gb of bad code'

If a gb contained 1,000,000,000 bits, and plain text was 2 bytes per character,
that would be 125,000,000 characters. if a line of code was on average 50 lines long (We're assuming this is bad code),
then that would be 25,000,000 lines of code... do you have magic fingers?

oh, and you have 250 of those gb... that makes a total of 6,250,000,000 lines of code.
I thought text was 1 byte per character...
^ yea it is
Anywho: 250gb is over exaggerated, more like 100gbs and half of that is deleted.
So 50gbs is about it.
ASCII text is 1 byte per char. In Unicode, the amount of bits per char isn't specified AFAIK, but it's often set to 16 bits per char.
The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaannnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnddddddddddddddddddddddddddddddddddddd........................ He is gone. Dingding.
Code:
#Bounce off paddles with VERY sucky collision detection
        if self.pos[0] <= PADDLE_WIDTH + BALL_RAD:
            if (self.pos[1] >= playerPaddle.pos[1]) and (self.pos[1] <= playerPaddle.pos[1] + PADDLE_HEIGHT):
                self.velocity = (-(self.velocity[0] + angle_mod), self.velocity[1] + angle_mod)        
                self.pos = (PADDLE_WIDTH + BALL_RAD + 1, self.pos[1])
        if (self.pos[0] >= screen.get_size()[0] - (PADDLE_WIDTH + BALL_RAD)):
            if (self.pos[1] >= aiPaddle.pos[1]) and (self.pos[1] <= aiPaddle.pos[1] + PADDLE_HEIGHT):
                self.velocity = (-(self.velocity[0] + angle_mod), self.velocity[1] + angle_mod)
                self.pos = (screen.get_size()[0] - (PADDLE_WIDTH + BALL_RAD + 1), self.pos[1])

Whut.
Code:
a=[1,2,3,4,5]
print([a[i+1] for i in range(len(a)-1)])

I honestly have no clue. This outputs [2,3,4,5]
(08-05-2013, 09:16 PM)JeremyG Wrote: [ -> ]
Code:
a=[1,2,3,4,5]
print([a[i+1] for i in range(len(a)-1)])

I honestly have no clue. This outputs [2,3,4,5]

hmmmmmm.......
Code:
a=[1,2,3,4,5]
println.(a[i+1] for i in range(len(a)-1))

?? that did 1,2,3,4,5??????????

I failed Sad Sad Meh ive all ways been crappy at Java>>V
Code:
println.(a[i-2])
See ^
(08-05-2013, 09:16 PM)JeremyG Wrote: [ -> ]
Code:
a=[1,2,3,4,5]
print([a[i+1] for i in range(len(a)-1)])

I honestly have no clue. This outputs [2,3,4,5]

It's because the a array is zero indexed. The i value itself starts at zero, but because of this bit here:
a=[1,2,3,4,5]
print([a[i+1] for i in range(len(a)-1)])
it starts the array's index at 1 instead of zero. Lucky that the range comes out to 4, otherwise you might end up trying to access a nonexistent element.
I will post my java code from my mod that was derpy.
Then why not post it q_q
I will I have to decompile my old old version and hope its not obsfated.
InvisibleGrammaNazi Wrote: [ -> ]
(08-09-2013, 08:34 PM)Chibill Wrote: [ -> ]I will I have to decompile my old old version and hope its not obsfated.<<Obsufacated.
SpellingNazi Wrote: [ -> ]
InvisibleGrammaNazi Wrote: [ -> ]
(08-09-2013, 08:34 PM)Chibill Wrote: [ -> ]I will I have to decompile my old old version and hope its not obsfated.<<Obsufacated.
**Obfuscated

Grammar Nazi's should NEVER try to correct spelling.

OT: I would post something of mine here, but I'm not really sure what of mine would be considered bad. I mean sure, I've got old programs that could have been written better, but I wrote them with what I knew at the time.
Code:
        try {
            URL url = new URL("https://raw.github.com/chibill/AdditionalCrafting/master/Version_Control/1.5.txt");


            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            int str;
            int str1;
            int str2;
            int str3;




              str = in.read();
              str1 = in.read();
              str2 = in.read();
              str1 = in.read();
              str3 = in.read();
              System.out.println(in);
              System.out.println(str);
              if(in != null){
                  No_Internet = false;
              if(str == 49 && str2 == 48 && str3 == 48){
                  Up_to_Date = true;
                System.out.println("[AdditionalCrafting] Additional Crafting up to date!");
              }else
              {
                System.out.println("[AdditionalCrafting] Additional Crafting is out of date for this verison of Minecraft!");
              }
              }
           in.close();
      } catch (MalformedURLException e) {
          } catch (IOException e) {
              No_Internet = true;
              System.out.println("[AdditionalCrafting] Additional Crafting has no internet conection!");
          }
No one cares about my worst code. :-C
(08-07-2013, 12:43 AM)Thor23 Wrote: [ -> ]
(08-05-2013, 09:16 PM)JeremyG Wrote: [ -> ]
Code:
a=[1,2,3,4,5]
print([a[i+1] for i in range(len(a)-1)])

I honestly have no clue. This outputs [2,3,4,5]

It's because the a array is zero indexed. The i value itself starts at zero, but because of this bit here:
a=[1,2,3,4,5]
print([a[i+1] for i in range(len(a)-1)])
it starts the array's index at 1 instead of zero. Lucky that the range comes out to 4, otherwise you might end up trying to access a nonexistent element.

I mean I know why it does that, I just don't know why I have that code
Why has xeo not come a rages about my worest java code I have?
Step aside noobs. Let me tell you about Apocalyptic Minefield. Let the pro at bad coding step forward and teach you all a few things.

https://docs.google.com/file/d/0B1Iapcb8FjwcR0hWLXFGZUJOeTg/edit?usp=sharing

It's a GDocs zipped file with a single .exe in it.

This is my first ever coding project that I made back in high school. Not only does it not work for shit, but every single action loads a different form. At the time, I had no idea how to code or use arrays, so it's pretty brutal.
I'd also like to point out that the minefield part is incredibly horrible. There are red squares with one blue one mixed in. Click on a red and you lose, click on blue and you win.


Oh and one last thing...

GET ON MY LEVEL, NOOBS
Hoeraay For self expression @Neo. And, i don't program (Yet), So im one of the few peeps who doesn't have bad code. Ha!
This topic cannot die!

... i tried to code an mcedit filter
Code:
#Generate redstone wiring
                    level.setBlockAt(pos[0], pos[1], pos[2], 137)
                    level.setBlockAt(pos[0], pos[1] + 1, pos[2], 55)
                    level.setBlockAt(pos[0], pos[1] - 1, pos[2] - 1, wirBlk.ID)
                    level.setBlockDataAt(pos[0], pos[1] - 1, pos[2] - 1, wirBlk.blockData)
                    level.setBlockAt(pos[0], pos[1], pos[2] - 1, 149)
                    level.setBlockAt(pos[0], pos[1], pos[2] - 2, wirBlk.ID)
                    level.setBlockDataAt(pos[0], pos[1], pos[2] - 2, wirBlk.blockData)
                    level.setBlockAt(pos[0], pos[1] + 1, pos[2] - 2, 75)
                    level.setBlockAt(pos[0], pos[1] + 2, pos[2] - 2, wirBlk.ID)
                    level.setBlockDataAt(pos[0], pos[1] + 2, pos[2] - 2, wirBlk.blockData)
                    level.setBlockAt(pos[0], pos[1] + 3, pos[2] - 2, 55)
list(str(list(X)))

Yeaaaa
Best example of bad code: Minecraft Beta 1.8. Its performance was HORRENDOUS.
How about the whole of MC?
In 1.6.4 they fixed many bugs that starved threads.