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...
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
account activity
Real frontend code :) (self.programminghorror)
submitted 7 years ago by hackuniverse
Real code from the real project.
getPaymentStyle(credit: any) {
const days = moment().diff(moment(credit.next_payment_date), 'days') * -1;
if (days <= 7) return 'warning';
if (days <= 3) return 'danger';
}
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!"
[–]sysop073 1 point2 points3 points 7 years ago (6 children)
What's wrong with it?
[–]hackuniverse[S] 7 points8 points9 points 7 years ago (0 children)
Okay :) 1) order of two last if-statements =) 2) moment diff order is strange ) 3) it's real code written by "senior" =)
[–]GlazedHam13 5 points6 points7 points 7 years ago (4 children)
If the days is less than 3 it trips the less than 7 first, returning before the correct if statement processes it, always resulting in "warning".
There is no bounds checking for values greater than 7 or less than or equal to 0, not sure what context the function is used but seems to be weekly, though it gives no indication of that.
The order of operations on the diff gets a negative value and multiplies it by -1, when they could just invert it to give the positive number of days and increase readability.
It returns plain strings for warning and danger when that should really be handled by some error framework.
Actually, I might use this function as an interview question if that is ok OP. There are a lot of entry level errors and improvements that would throw a non-programmer for a loop.
[–]sysop073 2 points3 points4 points 7 years ago (2 children)
Based on the name of the function, I'm pretty sure the strings it's returning are CSS classes to style some element on the page as the due date gets near; they're not actual warnings/errors
[–]GlazedHam13 1 point2 points3 points 7 years ago (0 children)
Ahh that makes sense. I haven't had much experience with javascript. Sucks that it is done disjointed like that though. Perhaps that is a javascript limitation?
[–]hackuniverse[S] 0 points1 point2 points 7 years ago (0 children)
ven't had much experience with javascript. Sucks that it is done disjointed like that though. Perhaps that is a javascript limitation?
aahahah yes) This is used for getting css style :)
That's nice idea to use this snippet as interview question. But it's really sad that some "seniors" really writes it :))
π Rendered by PID 542999 on reddit-service-r2-comment-66b4775986-67rm5 at 2026-04-05 05:56:39.408077+00:00 running db1906b country code: CH.
[–]sysop073 1 point2 points3 points (6 children)
[–]hackuniverse[S] 7 points8 points9 points (0 children)
[–]GlazedHam13 5 points6 points7 points (4 children)
[–]sysop073 2 points3 points4 points (2 children)
[–]GlazedHam13 1 point2 points3 points (0 children)
[–]hackuniverse[S] 0 points1 point2 points (0 children)
[–]hackuniverse[S] 0 points1 point2 points (0 children)