Thought I’d start something a little fun. Is there any hilarious code you’ve found when working on projects? This could be code you did in the past or someone else. One rule, no finger pointing / naming actual people, just funny code.
Here is a snippet of code I found while doing a code review for an offshore team we are working with. In fairness they are almost all junior developers. What makes the code below so funny is that vendorId is an “int”.
My first mentor showed that site to me as an instructional aid when I was a new developer, the point being, just because you can do something in code, does not mean you should.
I have, it’s a great site. I used to get Visual Studio Magazine as well before they stopped sending it out in print and they had a section called Dev Disasters that was great.
Another one I found that they did was a Dictionary that used a Dictionary as a key, so it was like:
I always thought coding was pretty straight forward. I mean obviously when I first started learning to code it took me a little bit, but after about a month or so I caught on to how repetitive everything is, I found quickly I’m almost always using the same things over and over again. float, int, list, bool, and so on.
Since Dictionary doesn’t appear to overload operator==, it is a reference type AND (IIRC) default behavior of operator== in C# is to compare references for equality without calling Equals, this essentially is associating a string with random dictionary instance.
Now the trick question is if that’s what the dev actually wanted to do.
The “funniest” thing I can remember at the moment was when someone wrote a C++ dll returning std::string and built it using different compiler.
It gets more interesting when you get to high level OOP phase in language like C++.
Project development goes in cycles: you get a task, you make set of abstractions for it, then task changes into something that is incompatbile with already established OOP model, so you need to fix that without breaking the program and without rewriting half of it.
Sometimes it can be like rebuilding bottom floor of 2 meter tall card house during the earthquake while someone is dancing on top of the card house.
I’m afraid I don’t have it on me, but for some of my… Less stable physics applications, I employ what I call the “fuck it” function. When the object detects that something has gone wrong, instead of trying to rectify that it simple prints out “fuck it” in the console and destroys the game object.
Not really hilarious code so to speak, more a mildly amusing if someone childish way to tell
you that your code is shit.
You’re correct. So in order to resolve the value from the outer dictionary, someone would need to pass the inner dictionary back into it as the key. What made this really awful is that it was a return value for a business logic method, so the only way you ever have those keys is by extracting them from the outer dictionary in the first place. It was a lazy attempt by the developer to return multiple pieces of data without using a proper business object model.
That structure would make sense if someone just stored many dictionaries for “bookkeeping” or whatever, but as return value this is definitely not gonna fly.
Is that the case in India? And yeah, there were trying to say <= 0. In Entity Framework 0 and Null are the same thing for an identity column, of which VendorId is, but this was a data retrieval method. What they were attempting to do is do a quick sanity check on the id and not query the database if it was <= 0.
What I actually found must shocking is the fact that int is a non-nullable type, but the compiler actually compiles it! There must be some kind of implicit conversion in those operators, and it only results in a compiler warning and not an error.
One of my colleagues at work mentioned over lunch recently that his debugging code at university was literally print statements with “this section’s f***ed up”, “you divided by zero you bollix”, etc. He ended up writing a Python script that would trawl through his code and remove all print statements before handing it up
EDIT: Another one from work. I was setting up GruntJS to call UglifyJS to minify a file. One of the options for UglifyJs is “screw IE8” - which means "I don’t care about full compliance with quirks in IE6-8.
I had a real face-to-keyboard moment at work a couple of weeks ago. We discovered that running the client’s automated financial system was generating huge transaction logs in the database (like 6+ gb).
Had a quick look, turns out some genius was writing a query that inserted 11m rows (fair enough), but was then updating the entire table to set a column to be a constant, THEN running a delete to remove rows where an amount was 0. After the delete, the number of rows was something like 4000.
Why didn’t they just put the constant in the insert, and a where clause so the 0’s were never inserted to begin with? No idea, it was a fairly complex query so maybe they panicked. It took me 30 seconds to fix.
Bonus points for performing the delete AFTER the update.
The code worked fine, and even made sense when I wrote it.
Then months later I changed the way the indexer worked on data. And objects just started randomly disappearing. Took me hours to track it back to this particular script.