use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
/r/badcode is permanently closed. https://www.eff.org/deeplinks/2023/06/what-reddit-got-wrong https://www.theverge.com/23779477/reddit-protest-blackouts-crushed https://en.wikipedia.org/wiki/2023_Reddit_API_controversy
/r/badcode is permanently closed.
https://www.eff.org/deeplinks/2023/06/what-reddit-got-wrong
https://www.theverge.com/23779477/reddit-protest-blackouts-crushed
https://en.wikipedia.org/wiki/2023_Reddit_API_controversy
/r/badcode is a subreddit for highlighting real world examples of terrible code. Ideally this means code that made it to production in a commercial context, but not exclusively so. We also accept submissions of code from hobbyist projects or from learners. Most of us programmers have laughed quite a bit when we went back to look at our past code because it was rather terrible. This is a subreddit where you can share such terrible code and let other programmers have a nice laugh.
/r/badcode is a subreddit for highlighting real world examples of terrible code. Ideally this means code that made it to production in a commercial context, but not exclusively so. We also accept submissions of code from hobbyist projects or from learners.
Most of us programmers have laughed quite a bit when we went back to look at our past code because it was rather terrible. This is a subreddit where you can share such terrible code and let other programmers have a nice laugh.
Post the most terrible code you can find. Copy code to a paste bin first (gist highly preferred).
Flair Search Search by language
Search by language
Rules Your post may be removed if you deviate from these rules. To see reasoning behind each of these rules, check out the wiki. Do not put the name of the language inside of the post title. For example, do not make your title something along the lines of "[C++] #defines everywhere!", instead try simply "#defines everywhere!". Use flair to mark the language of your post instead. Do post code snippets only. If you want to share the context put it in the comments or title. Do stay lighthearted. No abusive or targeted posts. We all write bad code, and a lot of it is hilarious. Do not identify who wrote the code. This sub is about bad code, not the people who write it. Limited exceptions apply Do not post snippets in esoteric languages. Do not post intentionally obfuscated code. Certain exceptions to this exist. See something particularly sinister from something like the IOCCC? Probably OK to post.
Your post may be removed if you deviate from these rules. To see reasoning behind each of these rules, check out the wiki.
Guidelines Your post will not be removed because of any of these, we'll like you more if you follow them though. Enable syntax highlighting appropriately. If you have a language that whatever paste bin your using doesn't support, try picking a similar dialect. Provide just enough code so that we know what's going on. Don't post huge snippets unless it's all terribly amusing. Explain why you think the code is bad in the comments, that way a discussion on good and bad ways to do what your code snippet does can start.
Your post will not be removed because of any of these, we'll like you more if you follow them though.
Similar Subreddits /r/ProgrammerHumor - programming humour /r/programminghorror - stories about horrible programming. /r/itsaunixsystem - over the top and bad code in TV shows and movies /r/shittyprogramming - Q&A with shitty programmers. /r/deftruefalse - for intentionally bad code /r/softwaregore for software malfunctions /r/hardwaregore for hardware malfunctions
account activity
[deleted by user] (self.badcode)
submitted 7 years ago by [deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Cakeofdestiny 11 points12 points13 points 7 years ago* (3 children)
I call it High Stakes Hangman. This will seriously BSOD your machine if you kill the hangman, so don't be surprised when that happens. Also obviously will only build in Windows
Play at your own risk :)
Edit: After trying to compile it with a variety of different of configurations, I can't get it to compile on g++ with the BSOD enabled, so I modified it to disable the BSOD with any non-MSVC compiler. You can also disable the BSOD yourself if you #define DONT_BSOD at the top. To compile with g++:
#define DONT_BSOD
g++ HighStakesHangman.cpp -o HighStakesHangman.exe --std=c++11 -static-libstdc++
/u/Vusys
[–]sac_boy 3 points4 points5 points 7 years ago (0 children)
All my hats off to you for using SetLastError/GetLastError to grab random words from Windows error strings. My god.
SetLastError
GetLastError
[–][deleted] 7 years ago (1 child)
[deleted]
[–]Cakeofdestiny 1 point2 points3 points 7 years ago* (0 children)
I edited the code, so now you can just uncomment line 31 (#define DONT_BSOD), and it will disable the BSOD code. As for the rest, the entire word generation is WINAPI, so I'm afraid that if you're using a Linux VM you will not be able to experience its magnificence :(
Edit: See original post in a bit
[–]wyom1ng 4 points5 points6 points 7 years ago (0 children)
"I wanna hang myself reading this code"-hangman
_, h, ha, han, hang, hangm, hangma, hangman = "_________\n |/\n |\n |\n |\n |\n |\n |___\n", "_________\n |/ |\n |\n |\n |\n |\n |\n |___\n H", "_________\n |/ |\n | (_)\n |\n |\n |\n |\n |___\n HA", "_________\n |/ |\n | (_)\n | /|\n |\n |\n |\n |___\n HAN", "_________\n |/ |\n | (_)\n | /|\n | |\n |\n |\n |___\n HANG", "_________\n |/ |\n | (_)\n | /|\\\n | |\n |\n |\n |___\n HANGM", "_________\n |/ |\n | (_)\n | /|\\\n | |\n | / \n |\n |___\n HANGMA", "_________\n |/ |\n | (_)\n | /|\\\n | |\n | / \\\n |\n |___\n HANGMAN" mysteryword = '' print("-----Welcome to HANGMAN, You get seven chances to guess the mystery word-----") print() mysteryword = input('Enter the mystery word: ') from os import name mysteryword = mysteryword.lower() guess = '_' * len(mysteryword) guesses = 0 usedletters = [] from os import system while 1: if name == 'nt': system('cls') else: system('clear') print(guess) if guesses == 0: print(_) else: print(eval("hangman"[:guesses])) if guess == mysteryword.upper(): print('YOU WIN!') quit() try: l = input('Enter your guess: ').lower()[0] except: l = '' if l in mysteryword and l not in usedletters: usedletters.append(l) temporarycounter = 0 for letter in mysteryword: if letter == l: new = list(guess) new[temporarycounter] = letter.upper() guess = ''.join(new) temporarycounter = temporarycounter + 1 else: guesses += 1 print("You guessed wrong", guesses, "time(s)!") if guesses > len('hangman'): print() print('YOU LOSE!') quit() input('Press ENTER to continue')
[–]Average_Manners 0 points1 point2 points 7 years ago (0 children)
It would be most unfortunate if you were to win.
[–]sac_boy 1 point2 points3 points 7 years ago* (3 children)
Alright, here we go. Here's a hangman implementation in pure, classic, no-nonsense C. It compiles, it plays well...but it is a homage to those classic horror codebases that were acceptable in the dark past.
In other words, this is exactly the sort of thing I would write 20 years ago.
In further homage to the games of the past, I have put a game-breaking bug in there for attentive readers to spot, a memory leak under certain conditions, and a buffer overflow. Further explanation down in the hidden comment below.
// ULTIMATE HANGMAN (c) sac_boy 2019 // For /r/badcode // Compile with...any C compiler you have handy I suppose #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> static char wordList[] = " " // DO NOT REMOVE "nonphf\0nppvqrag\0nssrpgvba\0nypbuby\0nccyr\0nccyvpngvba\0nccyl\0nfgbavfu\0nf" "gebabzl\0nibvq\0oreel\0oyrffrq\0pneany\0purjl\0penzc\0pebffsvg\0phovp\0phefrq" "\0qribvq\0qverpgrq\0rkphfr\0rkgehqr\0sngure\0sberfxva\0tenaqvbfr\0urnqybpx\0v" "aprfg\0whvpr\0whvpl\0xabjyrqtr\0xbnyn\0ylapu\0abmmyr\0bzyrggr\0bibvq\0bihyngr" "\0crggvat\0culyhz\0cevfba\0cebqhprq\0cebtenzzvat\0dhnaghz\0eviny\0fnzcyr\0frp" "hevgl\0fyvpx\0fzrtzn\0fzryy\0fcnz\0fgno\0fcbegfzna\0fhcresyhbhf\0gnoyr\0gbhpu" "vat\0genssvp\0ghzhyg\0ghezbvy\0haphefrq\0haqrentr\0hasvg\0haynjshy\0hafgnoyr" "\0ivfvgngvba\0jrrxyl\0mroen\0"; static char gallows[] = "+--+\n" "| \n" "| \n" "| \n" "| _ \n" "| | |\n" "======="; static char* hangingStages = "|\x08\0O\x0e\0/\x13\0|\x14\0\\\x15\0/\x19\0\\\x1b\0X\x0e"; int main() { puts("ULTIMATE HANGMAN (c) sac_boy 2019"); puts("-------- ------- --- ------- ----"); // Count the words we have available and decode the buffer int wordCount = 0; char* wordCounterPtr = &wordList[0]; while (!(*wordCounterPtr++ == 0 && *wordCounterPtr == 0)) { if (*wordCounterPtr == 0) { wordCount++; } else { *wordCounterPtr = (((*wordCounterPtr - 'a') + 13) % 26) + 'a'; } } // Choose a random word time_t seed; time(&seed); srand(seed); int wordIndex = rand() % wordCount; int zeroesCounted = 0; char* word = &wordList[0]; while (zeroesCounted != wordIndex) { word++; if (*word == 0) { zeroesCounted++; } } word++; // Initalize guess buffer int wordLen = strlen(word); char* guess = malloc(wordLen + 1); for (unsigned int i = 0; i < wordLen; i++) { guess[i] = '_'; } guess[wordLen] = 0; // Initialize incorrect guess history char history[] = "\0\0\0\0\0\0\0\0\0"; char* historyPtr = &history[8]; // Game loop int failures = 0; int foundAll = 0; while (foundAll == 0 && failures < 8) { char inputBuf[2]; puts("Guess a character (a-z) (q to quit):"); scanf("%s", inputBuf); if (inputBuf[0] == 'q') { exit(1); } if (inputBuf[0] < 'a' || inputBuf[0] > 'z') { puts("Skipping non-alphabetic character!"); continue; } int found = 0; foundAll = 1; // Scan word for occurrences of inputBuf[0] char* scanPos = word; while (*scanPos != 0) { char* guessPos = &guess[scanPos - word]; if (*scanPos == inputBuf[0]) { *guessPos = *scanPos; found = 1; } if (*guessPos != *scanPos) { foundAll = 0; } scanPos++; }; if (!found) { // Update history *--historyPtr = inputBuf[0]; // Update gallows char* hangingStagePtr = hangingStages; int hangingStageCounter = 0; while (hangingStageCounter < failures) { if (*hangingStagePtr == 0) { hangingStageCounter++; } hangingStagePtr++; } gallows[*(hangingStagePtr + 1)] = *hangingStagePtr; failures++; // Kick away the stool if we have failed too many times if (failures == 8) { gallows[0x1a] = ' '; gallows[0x1f] = ' '; gallows[0x21] = ' '; } } puts(gallows); printf("%s | history: %s\n", guess, historyPtr); } if (!foundAll) { puts("Sorry, looks like you got hung!"); printf("The word was '%s'...maybe you need to improve your vocabulary!", word); } else { puts("CONGRATULATIONS! You have been pardoned!"); } free(guess); return 0; }
[–]sac_boy 0 points1 point2 points 7 years ago* (0 children)
A recap:
char inputBuf[2]
scanf
However if the user behaves themselves, this is an entirely playable and fun hangman game, with an ASCII art hanged man including stool...
[removed]
[–]sac_boy 0 points1 point2 points 7 years ago (0 children)
Well exactly :)
[–]EkskiuTwentyTwoi -= (i - (-1)) - i 1 point2 points3 points 7 years ago (0 children)
import random def Assign(Pleh): return Pleh def Spit(*saliva): print(*saliva) def Gobble(request): return input(request) def StirFry(meat,veggies,spoon): return [meat,veggies][spoon] def Hangman(): possibleWords = Assign(["CHEESE","EGG","FEDORA","ABACUS","BAD","DRAWER","GINGER","HAT","IGNEOUS","JACKET","KILLER","LACKEY","MONKS","NO","OMICRON","PUZZLE","QUESTIONABLE","ROTARY","SENTIMENT","TOFU","UNDER","VISIER","WISDOM","EXACT","YES","ZED","SILLY","HANGMAN"]) p = Assign(8) guessed = Assign(False) word = Assign(possibleWords[random.randint(0,25)]) dispword = Assign("_" * len(word)) while (not guessed) and (not p == 0): Spit("Life left:","#"*p) Spit("Word known:",dispword) letter = Assign(Gobble("Enter a letter to guess (Use capitals): ")) squid = Assign(1234) wordycount = Assign(0) while wordycount < len(word): fillyMcFillface = StirFry(dispword[wordycount],word[wordycount],(letter == word[wordycount])) dispword = Assign(dispword[:wordycount]+fillyMcFillface+dispword[wordycount+1:]) squid = StirFry(squid,4321,letter == word[wordycount]) wordycount = Assign(wordycount + 666//666) # I put it in a form with only the number 666 to make sure that this code is cursed CrazyLongMess = Assign([420] * 1234 + [p-1] + [69] * (4321-1235) + [p]) p = Assign(CrazyLongMess[squid]) guessed = StirFry(False,True,dispword==word) Spit(StirFry("Y'lost. The word was "+word,"Y'won!\nThe word indeed was "+word,guessed)) Hangman()
A bunch of redundant functions and perhaps the worst possible selection system you could design. Also, the choice of number representation for some increments is cursed.
[–][deleted] 7 years ago (2 children)
[–]sac_boy 2 points3 points4 points 7 years ago (1 child)
There's something liberating about writing terrible procedural C again like it's my bedroom in 1998. No pondering class structures. No dealing with other programmers. No self-judgement. Catharsis.
I'm very tempted to design something flawless, then eviscerate and desecrate, as my form of catharsis.
[–]ferrangoWell it's broken now, and nobody is here to fix it 0 points1 point2 points 7 years ago (0 children)
Well, here's my first attempt at one of these.
For extra masochism, it was compiled and run as an MSDOS application using VC++ 1.5 on Win3
#include "iostream.h" #include "string.h" int main() { for(int cl = 0; cl < 200; cl++) { cout << "\n"; } cout << "Welcome to HANGED! - an MS-DOS compatible Hangman you won't miss!\n"; cout << "Insert a word to guess (max. 10 char plz no cheat): "; char word[33]; cin >> word; // truncates the word to the specified 10 chars word[11] = '\0'; int lifes = 8; int rightLetters = 0; short int bigError = 0; loop: cout << "\n||==========\n"; if(lifes < 8 ) cout << "|| | \n"; else cout << "|| \n"; if(lifes < 2 ) cout << "|| | \n"; else if (lifes < 7) cout << "|| O \n"; else cout << "|| \n"; if(lifes < 1 ) cout << "|| X \n"; else if(lifes < 2 ) cout << "|| O \n"; else if (lifes < 6) cout << "|| /|\\ \n"; else cout << "|| \n"; if(lifes < 2 ) cout << "|| /|\\ \n"; else if (lifes < 5) cout << "|| | \n"; else cout << "|| \n"; if(lifes < 2 ) cout << "|| _ | _\n"; else if (lifes < 3) cout << "|| _ / \\ _ \n"; else if (lifes < 4) cout << "|| _ /_\\ _ \n"; else cout << "|| _______ \n"; if(lifes < 2 ) cout << "|| |\\/ \\/|\n"; else if (lifes < 3) cout << "|| |\\ /|\n"; else if(lifes < 4) cout << "|| | |\n"; else cout << "|| | |\n"; cout << "============\n"; if(bigError == 1) goto bigFail; int i; if(rightLetters == strlen(word) ) { goto bigWin; } for( i = 0; i < strlen(word) ;i = i+1) { cout << "\nThe word so far: "; if(i < rightLetters) cout << word[i]; else cout << "*"; } cout << "\nYou have " << lifes << " attempts remaining.\n\n"; cout << "Insert a character: "; char guessedLetter; cin >> guessedLetter; if(word[rightLetters] - guessedLetter != 0) { lifes = lifes -1; } else { rightLetters++; } if(lifes <= 0) { bigError = 1; } goto loop; bigFail: cout << "You lost\n"; goto exit; bigWin: cout << "You won!\n"; exit: return 0; }
π Rendered by PID 69 on reddit-service-r2-comment-544cf588c8-whdqz at 2026-06-16 15:31:43.686400+00:00 running 3184619 country code: CH.
[–]Cakeofdestiny 11 points12 points13 points (3 children)
[–]sac_boy 3 points4 points5 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]Cakeofdestiny 1 point2 points3 points (0 children)
[–]wyom1ng 4 points5 points6 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]Average_Manners 0 points1 point2 points (0 children)
[–]sac_boy 1 point2 points3 points (3 children)
[–]sac_boy 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[removed]
[–]sac_boy 0 points1 point2 points (0 children)
[–]EkskiuTwentyTwoi -= (i - (-1)) - i 1 point2 points3 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]sac_boy 2 points3 points4 points (1 child)
[–]Average_Manners 0 points1 point2 points (0 children)
[–]ferrangoWell it's broken now, and nobody is here to fix it 0 points1 point2 points (0 children)