/r/programminghorror

Photograph via snooOG

Share strange or straight-up awful code.

RULES:

  • All posts MUST show terrible code. There are no exceptions.

  • No Editor Themes - If it's just your editor that looks bad, it doesn't belong here.

  • No Advertisement Code. This is generally written by people in marketing who only know what "code" looks like from other ads. It's not real code, so it doesn't belong.

  • No Student Code. Yes, they're learning, but bad code is part of the process.

  • No Generated Code. If it's minified JS, generated XML, or what have you, we don't want it here. Yes, the YouTube homepage has an extra right-angle bracket. We know.

  • No Asking for Help. Go to r/learnprogramming. What are you doing here?

  • No Spamming/Advertising. We don't care about your shitty Youtube video or new crypto that will "change the world".

  • Be Nice. No hate speech of any kind is allowed, as well as generally being a jerk. Talk about the code, not eachother.

  • No Direct Contact of the Mods. Please use the modmail, we don't want to be contacted directly.

  • Please direct stories without code to /r/talesfromtechsupport, and programming questions to /r/learnprogramming

Programming Horror is where developers come together to revel in the idiocy of our peers.

This subreddit is meant for sharing funny programming related stories and strange or straight-up awful code.


For the sake of not being mauled by rabid lawyer bears, please make sure to anonymize your stories - changing the names of people and companies.

For code examples, indent all your lines with 4 spaces to make it more readable:

foo = 'bar'

Sister subreddits

  • talesfromtechsupport - Not everything that involves a computer is a programming horror story. For IT support related submissions, head on over here.
  • talesfromdesigners - For our more artistically inclined brothers and sisters.
  • badcode - When you don't have a story to go along with the horrible, horrible code.
  • shittyprogramming - ninjas that only write in the <b>BEST</b> code
  • usemysoftware - A subreddit for software developers to come post their software and for users to test it.

/r/programminghorror

340,749 Subscribers

0

From Math to Basic, to C, to Assembly, to Machine Code

0 Comments
2024/04/03
09:40 UTC

56

Function to read an account from a database.

18 Comments
2024/04/02
20:49 UTC

48

Bad isEven functions: a thread

I'm sure everyone has seen joke code at some point in their career of an exhaustive if/else block checking if an int equals every possible even value for an isEven() function. Now, obviously, in C/C++ the best way to determine if a value is even doesn't even involve calling a function: just !(val&1). However, I thought it would be fun if we try to take on an algorithmic approach to writing bad isEven functions in a thread. Here are 3 to start:

This takes an int in flips a bool every time it decrements. When the int is 0, the bool will be returned:

bool isEven(int val) {
    bool isEven = true;

    while (val != 0) {
        isEven = !isEven;
        val--;
    }

    return isEven;
}

Here's another fun one one. This relies on the integer overflow and continuously increments the value by two until it equals either 0 or 1:

bool isEven(int val) {
    while(1) {
        if (val == 0) return true;
        if (val == 1) return false;
        val += 2;
    }
}

Recursion is always fun. This returns true if the value is equal to 0, or returns the inverse of the value minus one if its not:

bool isEven(int val) {
    return val == 0 ? true : !isEven(val - 1);
}

So how about it? What are your guy's bad isEven()?

21 Comments
2024/04/02
18:36 UTC

48

Generalized prime factor FFT... it just works

10 Comments
2024/04/02
15:06 UTC

0

I'm not proud of this. I WAS YOUNG AND IMMATURE

I just found this screenshot in my google drive. I remember PROUDLY sending this to all my friends via a GOOGLE DOC thinking I was comedy legend

https://preview.redd.it/9iz1y5p1uxrc1.png?width=1215&format=png&auto=webp&s=01aa5da2fc736a2dccd5b83dcd35ce0340b6349d

I was like 12 or smth don't judge

22 Comments
2024/04/01
22:01 UTC

0

My professor displaying his usual coding practices

45 Comments
2024/04/01
19:58 UTC

300

I’ve been told I deserve to be in hell for my code

62 Comments
2024/04/01
17:56 UTC

133

we all love sleeping to deal with entropy

13 Comments
2024/03/31
15:50 UTC

1,179

theHorror

62 Comments
2024/03/30
22:07 UTC

23

Not sure if it's horror-y enough, but still

6 Comments
2024/03/28
17:52 UTC

1,356

//filter

73 Comments
2024/03/27
21:44 UTC

0

When you suffer from "missing bracket"-PTSD

2 Comments
2024/03/27
15:32 UTC

298

Do you split your components

34 Comments
2024/03/27
00:00 UTC

0

The little you know...

13 Comments
2024/03/26
15:58 UTC

1,114

Asked my friend to fix the memory leak that out game has. We ran the numbers and its actually not that bad. But still, a weird solution.

112 Comments
2024/03/26
14:55 UTC

60

You never have the key

Found this code when investigating a bug and yes it was used in several locations.

https://preview.redd.it/r07vfb8gzmqc1.png?width=589&format=png&auto=webp&s=2eb14ea4d1d4b6d5533945c1553b6834df09a059

9 Comments
2024/03/26
08:16 UTC

278

Me in 2018: I’m a good coder. Also me in 2018:

19 Comments
2024/03/26
07:16 UTC

623

Part of the codebase I've inherited... God help me

86 Comments
2024/03/26
01:07 UTC

1,870

Man accidentally proves his ‘optimised’ python code is slower than before on LinkedIn.

125 Comments
2024/03/26
00:54 UTC

290

Short and simple

57 Comments
2024/03/25
17:39 UTC

321

There are only two hard things in Computer Science: cache invalidation and naming things.

21 Comments
2024/03/25
16:48 UTC

103

I mean it works

32 Comments
2024/03/24
07:13 UTC

Back To Top