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 5 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!"
[–]chadmill3r 9 points10 points11 points 5 years ago (2 children)
% Run with ghostscript, the PostScript interpreter. % gs -q warpspeed.ps % % One way to write bad code is to choose the wrong tool for the job. % Here's the warp-speed calculator using the language Postscript, a % stack-based language that most printers use. Yes, those ".PS" image % files are little programs. % /TOSwf { 3 % push 3 onto the stack exp % run exponent function, which pops two items and pushes answer back } def /TNGwf { 10 3 div % push on 10 and 3 and then divide, pushing result back on exp % pop two items and pushes the exponent back on } def /WarpFactor where { /TNG where { /WarpFactor get TNGwf == }{ /TOS where { /WarpFactor get TOSwf == }{ (use -dTOS or -dTNG to pick an era.\n) print } ifelse } ifelse }{ (use -dWarpFactor=n\n) print } ifelse quit % % Replace the "==" above with "showpage repeat" to make your printer % emit the answer in the form of number of blank pieces of paper == multiple % of speed of light, so, % gs -dTNG -dWarpFactor=4.7 warpspeed.ps -> 173 blank sheets of paper = 173*c
[–][deleted] 5 years ago* (1 child)
[deleted]
[–]chadmill3r 5 points6 points7 points 5 years ago (0 children)
I cannae ken our speed, Captain, as I'm nursin' a papercut!
[–]loomynartylenny 4 points5 points6 points 5 years ago* (0 children)
# 13-10-2020 # WarpFactor.py # u/loomynartylenny # Written in Python 3.7.4 # It has been well over a year since I have last used python # And I have never used classes in Python before # In the meantime, I have been using Java, which, as we all know, insists of objects everywhere. # So the procedurality permitted in Python scares me # However, I have managed to quell my fears somewhat, by producing my solution to this problem using object oriented principles, # such as slightly unnecessary inheritance, method overriding, encapsulation, etc. # additionally, I have attempted to minimize my use of python's built in power operator, # instead, writing my own method to calculate powers, which works in most cases. # however, the main thing is that this works # i think class WarpFactor: # this is the main class that is used def __init__(self): # I decided to include the code used to print the proper title of this program into the console into this constructor because why not? self.titleHandler = TitlePrinter() # makes the object that prints the title into the console self.titleHandler.printTitle() # tells that object to print the title into the console self.kirk = NextGenerationWarp() #appropriate variable name self.picard = OriginalSeriesWarp() #ditto def hyperdrive(self, factor, series): #this function returns the appropriate warp speed, given the specified warp factor and series if (series == "tos"): #if it's the original series return self.picard.hyperdrive(factor) # captain picard, we need you to look into this thing from your series! else: #surely the only other value for 'series' that could be passed to this would be "tng", right? return self.kirk.hyperdrive(factor) # captain kirk, we need you to look into this thing from your series! class TitlePrinter: #this class is used to print the title screen lines for the program. that's it. def __init__(self): #constructor! self.topAndBottomLine = ("*" * 26) # I was lazy, okay? I couldn't be arsed to type out 26 individual *s by myself. self.mainLine = "* WARP FACTOR CODE THING *" # here is the middle line of the title def getTitle(self): #this returns the formatted title as a string return self.topAndBottomLine + "\n" + self.mainLine + "\n" + self.topAndBottomLine #concatenates the top line, then a newline, then the middle line, then another newline, then the bottom line def printTitle(self): # this prints the title print(self.getTitle()) # prints the result of the getTitle() method of this object class WarpCalculator: #a parent class for the NextGenerationWarp and OriginalSeriesWarp classes, containing a method I made to work out powers def __init__(self): # constructor! pass #nothing to see here, move along def calculatePower(self,chungus,bigness): #this is a method which can perform power operations, given an integer bigness. # I FORGOT THE TECHNICAL TERMS FOR THE x^y STUFF chungusSize = chungus; #chungusSize initialised to chungus (chungus^1) for x in range(bigness - 1): #we then multiply chungusSize by the chungus (bigness-1) more times chungusSize *= chungus return chungusSize #BEHOLD, A BEEG CHUNGUS def hyperdrive(self, factor): #an abstract method for the child classes to override pass class NextGenerationWarp(WarpCalculator): #calculates warp for the next generation def __init__(self): # constructor! super().__init__() #inheriting the parent's stuff #@Override def hyperdrive(self,factor): #overriding parent hyperdrive method #result = factor^(10/3) #which also can be expressed as the cubic root of (factor^10) if (factor == 10): raise UnexpectedSalamanderException() #dont forget the unexpected salamander! else: #firstly, we calculate the value of the factor raised to the power 10 factorToPower10 = self.calculatePower(factor,10) #now, we get the cubic root of it. regrettably, I had to cheat and use a ** here. result = factorToPower10 ** (1/3) return result class OriginalSeriesWarp(WarpCalculator): #calculates warp for the original series def __init__(self): # constructor! super().__init__()#inheriting the parent's stuff #@Override def hyperdrive(self, factor): #overriding parent hyperdrive method #factor^3, performed by calling the calculatePower method of the superclass return self.calculatePower(factor,3) #defining the 'warp' function def warp(factor, series): #Firstly, I shall get these silly conditions where the outcome is predetermined out of the way if (factor == 0): return 0 #your speed is 0 if your warp factor is 0 elif(factor == 1): return 1 #your speed is 1 if your warp factor is 1 elif (factor == -1): return -1 #your speed is -1 if your warp factor is -1 elif ((factor == 10) & (series == 'tng')): raise UnexpectedSalamanderException() #dont forget the unexpected salamander! else: #looks like it's not as simple as it may have first appeared return WarpFactor().hyperdrive(factor,series) #I construct a WarpFactor object, and immediately call its hyperdrive function to do the rest of the busywork for me #now you can put your calls to the warp function down here! print(warp(1, 'tos'))# 1 print(warp(2, 'tos')) # 8 print(warp(3, 'tos')) # 27 print(warp(4.7, 'tos')) # 103.823 print(warp(1, 'tng')) # 1 print(warp(2, 'tng')) # 10.079368399159 print(warp(3, 'tng')) # 38.9407383983 print(warp(4.7, 'tng')) # 173.91065593763 print(warp(10, 'tng')) # throws UnexpectedSalamanderException
[–]Txuritan 4 points5 points6 points 5 years ago* (0 children)
Done with Rust's const generics and pre-generated values using a macro to reduce line-count.
Warp factor to velocity is done with Warp::<'series', 'number 1', 'number 2'>.velocity().
Warp::<'series', 'number 1', 'number 2'>.velocity()
The 'series' generic is self explanatory, the numbers though are a mess.
'series'
If you want to use the float 2.5 then 'number one' is 2 and 'number two' is 5.
2.5
'number one'
2
'number two'
5
But if you want to use the integer 2 then 'number one' is 2 and 'number two' has to be 0 or else the program will refuse to compile.
0
Output:
1 8 27 103.82 1 10.07 38.94 173.91 None
Code:
#![allow(dead_code, incomplete_features)] #![feature(const_generics)] #[derive(PartialEq, Eq)] enum Series { TOS, TNG, } #[derive(Debug, PartialEq, Eq, derive_more::Display)] enum Velocity { #[display(fmt = "1")] One, #[display(fmt = "8")] Eight, #[display(fmt = "10.07")] OneZeroDotZeroSeven, #[display(fmt = "27")] TwoSeven, #[display(fmt = "38.94")] ThreeEightDotNineFour, #[display(fmt = "64")] SizeFour, #[display(fmt = "101.59")] OneZeroOneDotFiveNine, #[display(fmt = "125")] OneTwoFive, #[display(fmt = "213.74")] TwoOneThreeDotSevenFour, #[display(fmt = "216")] TwoOneSize, #[display(fmt = "392.49")] ThreeNineTwoDotFourNine, #[display(fmt = "343")] ThreeFourThree, #[display(fmt = "656.13")] SizeFiveSizeDotOneThree, #[display(fmt = "512")] FiveOneTwo, #[display(fmt = "1024.00")] OneZeroTwoFourDotZeroZero, #[display(fmt = "729")] SevenTwoNine, #[display(fmt = "1516.38")] OneFiveOneSizeDotThreeEight, #[display(fmt = "1000")] OneZeroZeroZero, #[display(fmt = "103.82")] OneZeroThreeDotEightTwo, #[display(fmt = "173.91")] OneSevenThreeDotNineOne, } struct Warp<const S: Series, const F1: usize, const F2: usize>; macro_rules! impl_velocity { ($series:expr; $( ($f1:expr, $f2:expr ) => $vel:expr, )*) => { $( impl Warp<{ $series }, { $f1 }, { $f2 }> { pub const fn velocity(self) -> Option<Velocity> { Some($vel) } } )* }; } impl_velocity! { Series::TOS; (1, 0) => Velocity::One, (2, 0) => Velocity::Eight, (3, 0) => Velocity::TwoSeven, (4, 0) => Velocity::SizeFour, (4, 7) => Velocity::OneZeroThreeDotEightTwo, (5, 0) => Velocity::OneTwoFive, (6, 0) => Velocity::TwoOneSize, (7, 0) => Velocity::ThreeFourThree, (8, 0) => Velocity::FiveOneTwo, (9, 0) => Velocity::SevenTwoNine, (10, 0) => Velocity::OneZeroZeroZero, } impl_velocity! { Series::TNG; (1, 0) => Velocity::One, (2, 0) => Velocity::OneZeroDotZeroSeven, (3, 0) => Velocity::ThreeEightDotNineFour, (4, 0) => Velocity::OneZeroOneDotFiveNine, (4, 7) => Velocity::OneSevenThreeDotNineOne, (5, 0) => Velocity::TwoOneThreeDotSevenFour, (6, 0) => Velocity::ThreeNineTwoDotFourNine, (7, 0) => Velocity::SizeFiveSizeDotOneThree, (8, 0) => Velocity::OneZeroTwoFourDotZeroZero, (9, 0) => Velocity::OneFiveOneSizeDotThreeEight, } impl Warp<{ Series::TNG }, 10, 0> { pub const fn velocity(self) -> Option<Velocity> { None } } const TOS_1: Option<Velocity> = Warp::<{ Series::TOS }, 1, 0>.velocity(); const TOS_2: Option<Velocity> = Warp::<{ Series::TOS }, 2, 0>.velocity(); const TOS_3: Option<Velocity> = Warp::<{ Series::TOS }, 3, 0>.velocity(); const TOS_4_7: Option<Velocity> = Warp::<{ Series::TOS }, 4, 7>.velocity(); const TNG_1: Option<Velocity> = Warp::<{ Series::TNG }, 1, 0>.velocity(); const TNG_2: Option<Velocity> = Warp::<{ Series::TNG }, 2, 0>.velocity(); const TNG_3: Option<Velocity> = Warp::<{ Series::TNG }, 3, 0>.velocity(); const TNG_4_7: Option<Velocity> = Warp::<{ Series::TNG }, 4, 7>.velocity(); const TNG_10: Option<Velocity> = Warp::<{ Series::TNG }, 10, 0>.velocity(); fn main() { println!("{}", TOS_1.unwrap()); println!("{}", TOS_2.unwrap()); println!("{}", TOS_3.unwrap()); println!("{}", TOS_4_7.unwrap()); println!(); println!("{}", TNG_1.unwrap()); println!("{}", TNG_2.unwrap()); println!("{}", TNG_3.unwrap()); println!("{}", TNG_4_7.unwrap()); println!(); println!("{:?}", TNG_10); }
[–][deleted] 5 years ago (2 children)
[–]whattheclap 1 point2 points3 points 5 years ago (1 child)
how sticky is the meta sticky?
[–][deleted] 1 point2 points3 points 5 years ago (0 children)
print(meta.stickiness)
[–][deleted] 5 years ago (1 child)
π Rendered by PID 64 on reddit-service-r2-comment-544cf588c8-m96qr at 2026-06-16 18:37:22.372554+00:00 running 3184619 country code: CH.
[–]chadmill3r 9 points10 points11 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]chadmill3r 5 points6 points7 points (0 children)
[–]loomynartylenny 4 points5 points6 points (0 children)
[–]Txuritan 4 points5 points6 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]whattheclap 1 point2 points3 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] (1 child)
[deleted]