/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

342,166 Subscribers

0

The best string replace on the PLANET!

Recently I've been exploring js proxies and I've been looking for a good excuse to explore tag functions. So I wrote this monstrosity to play with them together:

const wordReplacer = (word) => (strings, ...values) => {
  return strings.join(word)
}

const proxyHandler = {
  get(_, prop) {
  return wordReplacer(prop)
  },
};

const replaceWith = new Proxy({}, proxyHandler);
const Aaaah = replaceWith['Aaaah!']

const replaced = Aaaah`"${'Hello'}" said Bob to Alice.`

console.log(replaced) // "Aaaah!" said Bob to Alice.

https://gist.github.com/mike-pete/5dc3b185a909d2a1068bc50ea5698180

It feels like it'd fit in nicely with the other code in this sub lol

fr fr though proxies are pretty neat. I recently used them to build a typesafe RPC library for iframes. I you haven't used them before, definitely give them a try!

0 Comments
2024/05/04
17:44 UTC

237

Hum, yeah, that's totally correct.

25 Comments
2024/05/04
03:51 UTC

381

THIS IS SOME NIGHTMARE FUEL

92 Comments
2024/05/03
10:30 UTC

402

Reddit production deployment crashed CET 25 4 '24 19:15 lasted for 2 hours

35 Comments
2024/05/01
13:58 UTC

70

Let me share my idgaf what happens to my db insert function.

12 Comments
2024/05/01
08:01 UTC

23

took me oddly long to realize what was causing the SIGFPE exit code

20 Comments
2024/04/30
08:09 UTC

552

Trying to learn syntactic sugar for cleaner code. Isn't this example plainly stupid since the expression already returns a boolean?

125 Comments
2024/04/29
17:57 UTC

3 Comments
2024/04/29
02:47 UTC

489

I made a python program for our school calculator for learning math (it makes problems for you to solve). Someone complained that it was a kilobyte in size (our calculators dont have much storage), so i made it exactly 300 bytes in size. This is the result:

51 Comments
2024/04/28
15:35 UTC

463

I just realised that python @decorators can be lambda functions

29 Comments
2024/04/26
16:48 UTC

254

Block I cleaned long ago

35 Comments
2024/04/24
19:32 UTC

0

Apparently `settings` has 3 `t`s

18 Comments
2024/04/24
12:25 UTC

259

When the story says “Chang labels to lowercase”

And you’re feeling a little trollsy

17 Comments
2024/04/24
05:13 UTC

73

found it in a fireship video

6 Comments
2024/04/23
21:56 UTC

139

JSON network data deserialization

18 Comments
2024/04/23
18:07 UTC

229

A new language where programs consist of one big data structure

14 Comments
2024/04/23
18:00 UTC

98

Just learned how to add numbers, how am I doing??

15 Comments
2024/04/23
15:56 UTC

558

Source code from Balatro

131 Comments
2024/04/23
14:58 UTC

0

Can't you just do output[CONTROL_BYTE_ADDR] = controlByte ?

byte[] controlByteArr = new byte[] { controlByte };
System.arraycopy(controlByteArr, 0, output, CONTROL_BYTE_ADDR, controlByteArr.length);
0 Comments
2024/04/23
11:25 UTC

516

Who needs an obfuscator when you have javascript and time to kill?

22 Comments
2024/04/22
16:51 UTC

427

Incredible

23 Comments
2024/04/21
23:03 UTC

0

Want to start making a website!

Hi, I used to code a bit 1-2 years ago, but I recently got back into it a few months ago. Can someone help me get started maybe start making an application with someone. Ill learn everything i need fast. DM

4 Comments
2024/04/21
18:30 UTC

1,027

Anyway so what's a "public variable" again?

66 Comments
2024/04/21
05:49 UTC

271

I hope I didn't mess up these values

17 Comments
2024/04/21
02:55 UTC

3 Comments
2024/04/20
16:21 UTC

2

Not JSON

I'm to blame for this one. You might be wondering what is wrong with this.
If you use json you might realize the directory back slashes aren't escaped.
On the JSON page it claims their strings are like C string and Java strings.
That's a lie. I can store directories in C string and it doesn't require escaping characters.
I really didn't want to deal with writing functions to escape everything and the later undo that.
So my solution is Not JSON or njsn. I get why it is there it makes full sense for it to exist with js.

So why is this a programming horror.
Well some poor person down the road is going to open this file and think it is json because he didn't read the documentation first.

https://preview.redd.it/gknh4d6hvivc1.png?width=490&format=png&auto=webp&s=f2a2d7db963cf77bdf95191db9ddf8cb4d159882

18 Comments
2024/04/19
23:49 UTC

102

one more underscore

12 Comments
2024/04/19
23:22 UTC

Back To Top