Forums - Open Redstone Engineers
Everyone's worst code! - Printable Version

+- Forums - Open Redstone Engineers (https://forum.openredstone.org)
+-- Forum: Off-Topic (https://forum.openredstone.org/forum-4.html)
+--- Forum: Programming (https://forum.openredstone.org/forum-8.html)
+--- Thread: Everyone's worst code! (/thread-685.html)

Pages: 1 2 3 4


Everyone's worst code! - Xeomorpher - 08-01-2013

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.


RE: Everyone's worst code! - bannanalord - 08-01-2013

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.


RE: Everyone's worst code! - mort96 - 08-01-2013

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


RE: Everyone's worst code! - David - 08-02-2013

My exapmles will fill up the HDD of this server so I won't post them Smile


RE: Everyone's worst code! - mad1231999 - 08-02-2013

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);
}



RE: Everyone's worst code! - mort96 - 08-02-2013

blagpostified the post I wrote here: http://mortie.org/blog?post=my_worst_code
:3


RE: Everyone's worst code! - Chibill - 08-03-2013

My worest code was the first batea of AdditionalCrafting I will not post for it would burn Xeo's eyes out.


RE: Everyone's worst code! - Billman555555 - 08-03-2013

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.


RE: Everyone's worst code! - Xeomorpher - 08-03-2013

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


RE: Everyone's worst code! - VirtualPineapple - 08-04-2013

I thought text was 1 byte per character...