/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

341,029 Subscribers

85

I unironically did this today and feel ashamed...

25 Comments
2024/04/06
21:29 UTC

0

how would I create a motion detection dance game with only a camera as input

4 Comments
2024/04/06
14:57 UTC

384

Version? No we don't do that here

I'm refactoring this system and this isn't the worst it has 5 tables for users, the worst part is that they don't have a difference

46 Comments
2024/04/05
14:23 UTC

0

infrastructureManagementCanHoldYouBack

3 Comments
2024/04/05
12:08 UTC

178

Trigonometry functions in CSS

25 Comments
2024/04/03
20:27 UTC

105

Had to make sure I don't check values outside of the 2d array...

20 Comments
2024/04/03
18:11 UTC

0

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

3 Comments
2024/04/03
09:40 UTC

148

Function to read an account from a database.

32 Comments
2024/04/02
20:49 UTC

72

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()?

30 Comments
2024/04/02
18:36 UTC

63

Generalized prime factor FFT... it just works

12 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

47 Comments
2024/04/01
19:58 UTC

308

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

62 Comments
2024/04/01
17:56 UTC

135

we all love sleeping to deal with entropy

13 Comments
2024/03/31
15:50 UTC

1,180

theHorror

62 Comments
2024/03/30
22:07 UTC

26

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

6 Comments
2024/03/28
17:52 UTC

1,369

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

291

Do you split your components

34 Comments
2024/03/27
00:00 UTC

Back To Top