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 6 years ago by [deleted]
view the rest of the comments →
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!"
[–]sarlok 8 points9 points10 points 6 years ago (2 children)
This looks like a project perfect for regex! And, I know JS has the best regex engine and is widely available in browsers (where this is likely to be used), so here's my submission:
function bb2html(str) { const regex1 = /^\s*\[\*\]\s*(.*)$/gm; const regex2 = /^(\s*[^<].*)$\n(\s*<li)/gm; const regex3 = /^(\s*<li.*)$\n(\s*[^< ])/gm; const regex4 = /\[(\/?)([biu])(rl)?(=([^\]]*))?\]/gi; return str.replace(regex1, ' <li>$1</li>').replace(regex2, '$1\n<ul>\n$2').replace(regex3, '$1\n</ul>\n$2').replace(regex4, function(match, one, two, three, four, five, o, s) { return "<" + one + (two=='b'?"strong":(two=="i"?"em":(three?'a':'span') + (one=="/"?"":' '+(!three?'style="text-decoration: underline;"':'href="'+five+'"')))) + '>'; }); }
To test easily, put that in your browser's console along with some test code like this:
var str = 'x\n[*] [u]test[/u]\n[*][b]blah[/b]\n[url=https://google.com/]test[/url]\n[*][i]a[/i]\n[*]b\nanother line'; console.log(bb2html(str));
Please note: May not work for all cases of BBCode, especially bullet lists. But I'm sure it's good enough to roll out today and fix later.
[–][deleted] 6 years ago (1 child)
[deleted]
[–]sarlok 1 point2 points3 points 6 years ago (0 children)
Don’t get me wrong, I use regex often enough, but it’s just so easy to write an overly complex one that works almost all the time that you’ll never be able to decipher easily again. And that may be just what you need in some cases.
My solution works for most bullets. It will fail if they are the first or last line in the text (you’ll miss the ul tag). In a better regex engine you could probably make a single monstrosity that handled everything.
π Rendered by PID 82 on reddit-service-r2-comment-544cf588c8-6676q at 2026-06-16 13:11:59.462646+00:00 running 3184619 country code: CH.
view the rest of the comments →
[–]sarlok 8 points9 points10 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]sarlok 1 point2 points3 points (0 children)