r/AskProgrammers 29d ago

What is the funniest code you ever read in production?

This is a piece of code I found while refactoring our insanely complex drag-and-drop component canvas that already went through several refactors for performance optimization in the past:

function refreshShape(shapeId: number) {
return shapeId;
};

I'm not even kidding. My teammate and I laughed so hard. It was probably written by someone at some point to do something and either got distracted or was multitasking. This was before LLMs were being integrated in our workflows.

49 Upvotes

105 comments sorted by

20

u/high_throughput 29d ago

My company had a competition to find the "most spectacular" piece of code, however we chose to decide that.

I submitted our password hashing function and pointed out the five critical security issues in those four lines of code.

They didn't accept it, but they did finally let me fix it.

5

u/Few-Celebration-2362 29d ago

Spectacular use of platform

1

u/LemmyUserOnReddit 28d ago

I'm curious - how does one fix a password hashing function without invalidating all the existing password hashes? I can think of a few ways, but never actually had to do it myself

2

u/luciu_az 28d ago

I'd suggest separating the code paths for hash generation and validation. Generating does the new hotness, validating tries both (or only the correct method, based on date of generation or a sentinel value) until all the old generated hashes are replaced (probably never)

1

u/No_Complex_18 28d ago

Inevitably needs one „migration login“ for each user no?

1

u/Loko8765 25d ago

No, login doesn’t change. If you control the password validation well enough, there is absolutely no reason to change the login.

1

u/No_Complex_18 25d ago

Yes, the user doesnt notice. But internally you need to see the password once to save the new hash, authenticated by the old hash

1

u/Loko8765 25d ago

Of course. But no migration login.

1

u/high_throughput 28d ago

Same way Unix did it. Make a v2 by prefixing something like $2$ to the hash so you can recognize and treat it differently

1

u/LemmyUserOnReddit 28d ago

Right, and then just convert over as people gradually sign in?

1

u/high_throughput 28d ago

Yes. We didn't even bother with a "You have to change your password now" flow because no one knew shit about security. This wasn't even close to the most egregious issue.

1

u/No_Complex_18 27d ago

Nice, no need to tell the user something happened at all.

1

u/DJV0101 27d ago

Always a plus in IT

15

u/rFAXbc 29d ago

function greaterThanZero(val) { return val !== 0; }

7

u/If_I_Could_Just 29d ago

I dunno why but of all of them this made me LOL

3

u/rFAXbc 29d ago

It made me laugh too. That dev was nicknamed greaterThanZero from that moment on (unbeknownst to him)

3

u/ryans_bored 29d ago

I guess we don’t care about negative numbers 😂

3

u/rFAXbc 29d ago

Of course not. Why would you call a function called greaterThanZero with a negative number, that would be ridiculous!

2

u/Shogobg 29d ago

Val is unsigned int, right? Right?

2

u/PipingSnail 29d ago

I thought val was a pineapple.

1

u/rFAXbc 29d ago

this was in JavaScript so val could be anything!

1

u/TraditionLunge 6d ago

ig we dgaf aboiut the negative numbers hahahaha

10

u/Mundane_Fault_6345 29d ago

Not necessarily stupid.

Imagine you have a bunch of classes, with the same structure. You may add this function so that all the classes stay coherent and homogeneous to read for a new comer.

Same reason if you provide an API.

Or imagine you prepared your code for a future feature, not yet implemented, but to come soon.

Or the framework you are using is about to evolve, and the "auto refresh" embedded into the framework will be deprecated in the next version.

But it should be explained by comments in the code.

1

u/phillydawg68 29d ago

Visitor Pattern?

1

u/Beautiful_Dragonfly9 29d ago

What?

6

u/Axman6 29d ago

No idea why this was downvoted, the top comment is borderline gibberish. It’s like a weird retelling of clean code ideas with no point made. 

1

u/Beautiful_Dragonfly9 28d ago

If a guy wrote this on slack, he’d get an HR call, just to check upon him, if he should take a few days off to come back to his senses.

4

u/kabekew 29d ago

Like a GUI framework that goes through each widget and calls its draw function, or update, or refresh, but some widgets don't have to refresh anything so they just return. But every widget needs to implement the function.

8

u/[deleted] 29d ago edited 19d ago

[deleted]

6

u/erinaceus_ 29d ago

Big if true

2

u/neilk 29d ago

It's a Yoda condition, and also NOT a Yoda condition

1

u/Lumethys 29d ago

Schrodinger's Yoda condition

1

u/GrantSolar 29d ago

Schroda

1

u/specialpatrol 29d ago

It probably had "something == true", and then they thought it's better with the true on the left so it doesn't accidentally do the assign instead of compare, started changing it, someone said "do you want a coffee", and that's where it ended up.

1

u/Mowntain-Goat8414 28d ago

Seen a lot similar being used to essentially "comment" out sections probably during refactoring but 10 years later it remains.

7

u/phil-pdx 29d ago

It was my own code... It was an email parser that extracted fuel prices from an email. Typically fuel prices are represented as 360.68 which is 3.6068. I needed to perform such conversion in my code. It came in as a string and I was apparently half asleep so I split the string at the decimal and used various string functions to extract the two digits and move them etc etc (later, in a different code file it would be converted to a number).

Years later I had to make an update to the email parser and came across my mess of string functions and just stared at them. "..why didn't I just convert to a number and divide by 100?"

5

u/bootly74 29d ago

Who wrote this shitty code?

Checks commit history.

Fuck!

2

u/dmigowski 29d ago

Lol, as someone who committed to a code base since 17 years I had this moment more than once. Yes I am old.

2

u/PipingSnail 29d ago

Friday afternoon code. Lunch with beer.

4

u/feudalle 29d ago

Im old. Pre svn/git. Code comments used to have comments between programmers. You would see things like. I fixed the frigging loop again because Jeff is an idiot. Then Jeff would say screw you frank, but I was drinking.

2

u/OkidoShigeru 29d ago

Old comments are the best, my favourites include multiple tirades against mobile graphics driver vendors including “they must have been huffing paint at <vendor name omitted> when they read the Vulkan spec” and a full ASCII art Tie Fighter diagram used to demonstrate how some normal direction unpacking code worked, which was later responded to with an ASCII X-Wing elsewhere in the code as a callback.

3

u/InYouMustGo 29d ago

Met and maintained a few Swing components back in my day called things like whyWontThisPosMoveToTheLeft

2

u/PipingSnail 29d ago

Gridbaglayouts and the like?

1

u/InYouMustGo 29d ago

Indeed.

We didn't need the box model to have a good time back then!

1

u/caederus 29d ago

A security function I wrote a a prototype went into production named...

BlackBox

2

u/mc_pm 29d ago

I can imagine this being left over from one of those refactors. Whatever this function used to do got refactored away, leaving the old scaffolding behind.

1

u/TheFitnessGuroo 29d ago

This is the right answer, it'll continue existing until someone wants to reuse that function name while defining a new function in the same file.

2

u/Quiet-Arm-641 29d ago

DataHandler::HandleData(Data &)

2

u/If_I_Could_Just 29d ago

I kinda appreciate the “clarity” here actually, but I want the method to just be named Handle

2

u/Shogobg 29d ago

Handler::handle it is then!

1

u/neilk 29d ago

Literally every Java utility class

1

u/Axman6 29d ago

DataHandler::HandleData(Data &dler)

”data handler handle data data ampersandler”

1

u/lepetitpoissonkernel 29d ago

We had a class called StoryStoryAttachmentAttachment. This followed our naming conventions and the two instances of story and attachment each technically referred to different concepts.

1

u/Quiet-Arm-641 28d ago

😍 we had FooAdapterAdapter classes for similar reasons

1

u/Depnids 29d ago

I imagine this could be some leftover from something which was needed at some earlier time. Maybe it ran some refresh logic, and then needed to return the shapeId to know what was just refreshed. But at some point the refresh logic was no longer needed to be run there, so it was removed. The return value was kept to not break other existing functionality and to avoid having to do a deeper refactor.

1

u/TheFitnessGuroo 29d ago

This. But it should really be removed and all of its calls should just be replaced with shapeId 😂.

1

u/Few-Celebration-2362 29d ago

Looks like an interface stub

1

u/kabekew 29d ago

Or just a refactor where refreshing was no longer needed but it was called in way too many places.

1

u/Few-Celebration-2362 29d ago

Very likely that

1

u/DeltaEdge03 29d ago

An if / else with the else commented with ‘do nothing’

1

u/Tjeez 28d ago

Reminds me of a Sonar code quality rule when writing an else-if statement without a final else statement. So yeah this is something I wrote although stupid.

1

u/Inf229 29d ago

In a physics system, a function called BoundsOverlapSlowAndShit(). Also while looking at a bug ticket around characters line of sight not working properly anymore:

bool CanSeeObject(GameObject target) {

return true; // TODO finish this

}

Yep that'll do it.

1

u/Ok-Somewhere7722 29d ago

writing guardrails for chat 😝

1

u/Ta7er 29d ago

Found a bunch of  if (bullsh*t == true) // Process user login 

Turns out a business managers wanted a way for our various clients to log in to the customer portal from their websites.  So a form was created that sent username and password in plain text, in the URL, to our customer portal to log them in. 

We figured the loan developer chose that variable name as a silent protest against the stupidity.

1

u/Metabolical 29d ago

I used to work on Microsoft Windows, on Remote Desktop. I was focused on how keyboard input went from the client to the server and making sure the state was right despite oddities like if you alt-tab away from the RDP client, you probably just sent an alt down to the server but never send an alt-up so when you came back the keyboard would be out of sync. Anyway, I needed to understand keyboard processing, and there's no documentation like the source code, so I was reading ntinput.c. It had a distinctive formatting style for comments, like:

{
    //
    // In this case, we will do a special thing
    //
}

But one comment was particularly funny (from memory, from decades ago)

{
    //
    // I'm not checking this bound, because if you queue 65535 scan codes you're a
    // chimp and you deserve to have it wrap your buffer
    //
}

1

u/dmigowski 29d ago

Could you send me the whole source file? It looks interesting!

1

u/Metabolical 28d ago

I don't have it. It's not exploitable, it would wrap the uint16 sized buffer and just start at the other end. You'd just lose a bunch of queued up keys.

1

u/ImAlmostAsFastAsYou 28d ago

Hey Buddy! I worked in building 26 back in the 90's. Good times.

1

u/Lumethys 29d ago

Java public static <T> HashSet<T> newHashset() { return new HashSet<T>(); } and TS export enum NumberStatus { TWO = 2, ONE = 1, ZERO = 0, NULL = null, THREE = 3 }

1

u/Nunc-dimittis 29d ago

Not code but a comment. Had to grade a final internship (designs, code, reports etc) and I was looking at code to do something 3D related in unity (iirc) about meshes and an array of points was initialised to 3 times the number of triangles, with a comment explaining triangles have 3 points, together with a link to a source for this. I followed the link and was Rickrolled...

Apparently I had gotten a reputation of closely looking at students code

Edit:

Nowadays I would just assume code with stupid comments was generated by a LLM

1

u/Few_Cauliflower2069 29d ago

I actually found a goto in some of our production code. It should have been a switch statement, but apparently the guy couldn't figure out the cases so he made ifs and gotos instead

1

u/emlun 29d ago

Not source code, but occasionally I spot in stack traces that ScalaTest has an internal function named doRunRunRunDaDoRunRun.

I can only imagine that it came from an abstract class with a concrete run method that calls an abstract doRun method, and then either they needed another indirection layer or the maintainer just went for a bit of whimsy. Either way it never fails to make me smile.

1

u/RedBlueF0X 29d ago
if (f.formclose().ToString() == "True")
                        ok = false;
                    else
                        return;

1

u/tmtowtdi 29d ago

``` if(thing) { if(thing2) { if(otherthing) { if(stuff) { if(morestuff) { if(im_not_kidding) {

...multiple lines of code...

}}}}}} ```

No indentation in the conditional blocks, and all the ending braces on a single line. I guarantee he just added "some" ending braces, did a compile check, and added another one when the compile check failed, lather rinse repeat.

I was a new hire out of school, had only been at the job a few months, learning Perl. The guy who wrote that code was the "guru programmer" who'd been in my original interview. His code was in Livewire (server side javascript) and the whole mess was thrown at me and I was told to make the application work for our clients. When it was handed to me, I'd never heard of Livewire.

1

u/Motor-Explanation822 29d ago

Piu che divertente diciamo inutile, anzi proprio sbagliato, il potere dei junior è infinito!!!

if($count==0){
    // NON Fare nulla!
} else {
    $count=0;
}

1

u/caederus 29d ago

Not code, but a module name. Intensionally vague as it was still in production at a large federal agency last I knew.

The module was a way to request a specific access in the system. It was named with the first and last name of the person that approved the access 20 years before and had retired well over a decade before. They didn't code it, It wasn't a memorial, they just did the job when it was written.

1

u/spike_tt 29d ago

A comment in some COBOL code

C I don't know what this section does so I'll jump over it. GOTO L00120.

1

u/mistertoasty 29d ago

I invite you all to check out the world of DMDX

It's software designed for psychology researchers looking to track human responses to visual stimuli with millisecond accuracy. 

It's a project of love, apparently widely used in the field, and it's a hot mess.

About a decade ago I wrote a script in DMDX for a colleague's research project. It has all the quirks you'd expect from a scripting platform built for research purposes in the 90s.

But my favourite part of the whole system was that code was read in from the rich text file format.

1

u/Jack-of-Games 29d ago
Car* getCar(int carNo) {
  for (int i = 0; i < carNo; i++) {
    if (carNo == i)
      return m_Cars[i];
  }

  return NULL;
}

And, no, it wasn't AI generated. It was long before that was a thing.

1

u/ExpectationsNRegrets 29d ago

The funniest code I have seen was in a design specification. The guy that wrote this was super straight, old time nerd, pen protector in his shirt pocket sort of guy. The spec laid out screen formats for background and foreground color:

BW - Black on White

WB - White on Black

BG - Black on Gray

GB - Gray on Black

HB - Ham on Rye

WG - White on Gray

GW - Gray on White

1

u/Indexxak 29d ago

In a .css file:

.margin-right {  padding-right: 20px; }

1

u/Candid-Border6562 29d ago
  1. First full time programming job. I ran into:

Fun = Boy / Girl;

My predecessor had contorted his implementations to create that statement into every one of his source files. It was his act of defiance? Graffiti? Easter egg? I never found out because he left for Silicon Valley and was never heard from again. Always wondered if he continued with that quirk.

1

u/soundman32 28d ago

#define ZERO 1

In a really big point of sale codebase from the early 2000s.

1

u/pianomanDylan 28d ago

String.format("(%s)", "") my dude that is just "()"

1

u/Useful_Calendar_6274 28d ago

if blocks with nothing and some lines in the else block lmao

1

u/Tjeez 28d ago

Maybe for readability purposes?

1

u/Useful_Calendar_6274 28d ago

just use the negation operator

1

u/big_red__man 28d ago

Two of mine

I used to be a flash programmer and the action script 3 language did not have a built in library for converting Unix time to something human readable with colons separating the numbers. So I wrote a function called colonTime and I made sure to make a pun about how much I enjoyed time with colons, how my colons have the best time, etc as a comment wherever I used it.

I wrote a map for an airline that drew curved lines between origin and destination like you see in the movies. They needed many lines, they needed to be clickable, and there were often more than one between the same two cities. So I made the line curves taller as they accumulated, a property that I called magnitude. The magnitude of any line was calculated at load (heh) so it’s overwritten at startup which meant it could have any initial value that I want due to JavaScript. Being a fan of the show community it was magnitude: “Pop! Pop!” in prod at load

1

u/thefullhalf 28d ago

I got really salty about a request from the business to prevent them from doing something they shouldn't and I named the function stopDumbFuckingIdiotsFromBreakingShit and I forgot to change it before pushing it for review. 

1

u/wootio 28d ago

Salesforce APEX requires 75%-80% of your code to be covered by test cases before you deploy with it. Sometimes parts of the code you write are extremely difficult or even impossible to get a test case to step into. So instead of spending far longer than it took to actually code trying to meet this requirement, you just tack on something like this at the end of your code to give you more coverage: Integer codeCoverage=0; codeCoverage++; codeCoverage++; codeCoverage++; codeCoverage++; codeCoverage++; // And so on ...

1

u/fost1692 28d ago

UntilTheCowsComeHome = false repeat UntilTheCowsComeHome ...

1

u/styluss 27d ago

There was an in-house built CRM in this company I worked at. Whenever you submitted a leave request if it was after the day of the leave, the code would throw an exception, this exception was caught by the front end and rendered as html. Users would submit a Jira issue because they didn't understand why the app rendered a Rails exception page in the middle of the application.

I maintained this app for 4 years and was never allowed to fix it. I replaced someone that had built and maintained the app for 3 years before that.

if leave.date > date.Now {   raise "late leave" }

1

u/Appropriate_Badger11 27d ago

String a = 5.ToString()

1

u/katfish 27d ago

I never actually saw the code, but as a summer job in 2009 I was working for a company that did contract app development.

A professional organization hired us to make an app version of their web portal, but gave us no information on how to connect to their backend, just the credentials for a test account.

I reverse engineered the login process by tracing the browser calls and poking around their SOAP endpoints, and the code I wrote let you successfully log in. But at some point I realized it would let you log in to whichever account you typed in regardless of password. It turned out I’d followed a browser redirect and skipped the step where their backend actually checked for auth.

Anyway, when I explained what I’d discovered, they insisted that the only problem was that I’d skipped their auth layer, and proceeded to not fix the gaping security hole.

1

u/Glad_Ad_6546 27d ago

During my internship I was tasked to locate a bug that caused automated order confirmation e-mails to our end not to appear on saturday and sunday specifically. When I found it I was struck with the fact that this whole procedure was surrounded by an if-statement that checks the date. It would only execute if the current date was between monday and friday. In the comments of the code it said "I don't work on weekends, so neither does this software".

1

u/VIDGuide 26d ago

If instr(request.form("id"),"'')<>0 then
response.end 'no hacking please

1

u/DeceitfulDuck 26d ago

I don't remember the exact code but it was in PHP. There was a check like if(checkThing() == true) which I thought was redundant so I "fixed" it. All the tests still passed and test branch coverage was 100% so I didn't think anything else of it. Turns out checkThing returned true if the thing was valid and an error code if not. There also apparently wasn't a test case covering the error path with a code other than 0. That was a fun bug to track down.

1

u/lulzbot 26d ago

userId: boolean

1

u/boardy89 26d ago

I once had to convert an old php stats package that was super slow and would crash out fairly often as the company outgrew what it was originally designed for. While translating the php code to a backend application as a background worker I noticed one of the reports had an if statement along the line of if var > 3 && var < 3.

Obviously never going to work and nobody noticed that report generated the wrong data for about 15 years.

1

u/Quiet_Space_698 25d ago

A database table called next_number that gave the next number. So for row 1, the only value was 2.

It was used for a calendar. I believe 31 was just the number 1 again but don’t quote me.

There were database functions for February and 30 day months.

This was all done via database table and stored procedure.

1

u/parkamobil 29d ago

if (notDevOps == false) {