Earlier today, I published an article about the struggles of working in teams (it's a little personal, so apologies for the paywall). In that article, I wrote about a time when I was on a game development team, and I noticed someone do something I felt was truly horrific: they built a 100 by 100 game grid entirely by hand.
In other words, they created tile objects and hand positioned all 100 of them into a grid. Then, they gave each tile a name which corresponded to its position (i.e. (0, 0)
, (1, 0)
, etc.). From there, they wrote a script to find all tile objects in the scene, parse their names, and place them at the appropriate indices in a set of nested arrays. Naturally, the solution was unscalable, so we were stuck with that initial grid.
Honestly, I wanted to write a whole article about that story, but I don't really remember all the details. That said, I thought it would be fun to share what I could remember and see if anyone else had similar experiences.
I should mention that I'm not the first one to kick off this kind of discussion on the platform. Meghan Denny held a similar discussion over a year ago, so check it out!
Also, I don't intend for this to be a huge rant. I'm more interested in some of the lessons learned, so try to keep things positive and light.
Top comments (37)
This requires a bit of backstory, but it's worth it.
Dev worked on private company project. Dev was only "dev" that actually did anything valuable (there was 1 UX guy who was a consultant and a designer with extremely limited css skills).
Dev was owed little over $20-30k in commissions from a project.
Dev didn't get paid, instead he got fired (company's owner was a next level greedy asshole).
Mistake #1 by company: Not owning their repo
Mistake #2 by company: Pissing off a dev who owns the repo
Dev proceeds to delete all his work from server, deleted the repo, and then uploaded his own copy of everything back to the company (he didn't want to get sued).
There was only 1 small thing he changed. Every single class, ID, function name, you name it was now obfuscated. I don't really know how he did it, but everything was also connected to a script on HIS server. That script changed each class name, ID, and function every 24 hours or so?
Needless to say the company thought "well fine, we'll just rename it all and go from where he left off", and then everything renamed itself. These aren't devs so they are basically freaking out, and it turned into quite a hilarious event.
TL;DR: Dev got fired, dev was owed around $20-30k, dev proceeded to rename everything to look like "na89s7fn7234fna8h12sba" as class names on nearly 65,000 lines of code. Company finally paid up and got their original code back after realizing attempting to fix it themselves was pointless.
This is great. Haha this takes the “villain” definition of worst.
I once heard about a project where the business logic would depend of the front.
Something like:
I don't know if this is considered as bad code, but it sure is awful.
This looks like the kind of code I'd write when I'm working with D3. haha I struggle so much with web dev stuff.
I don't like the idea of categorizing "worst" code based on arbitrary metrics like lines of code, O(n) efficiency, etc.
However, I'd say bad code is difficult to understand and read. Code will always be interpreted by machines, but it should be comprehensible to humans.
But if I'm being honest the "worst" code I see is code with horrible security. I.e. plain text passwords, or hardcoded credentials.
I agree with all this! I do quite a bit of teaching, and I stress readability, correctness, and testing over metrics like efficiency and whatnot.
Inefficient code is more often than not hard to read! There is a reason people try to get rid of "pyramid code".
For sure! I was just referencing your mention of big O as a criteria for bad code.
Oh absolutely. We're in total agreement!
Code that works is never bad, but this is probably the most hacky one from my last project:
What does this do?
It displays an element which has been set invisible by a JavaScript-Library that I didn‘t want to hack. There was no option in the API to do it.
Cleaver code is not bad code xD
Uh, definitely the code that I had to put up with when I was doing a scholarship in one of the biggest company of my country. We were making an Angular application that had a couple of pages, one of which included a map, a table and a lot of buttons with actions that will change the state of the map and the table. So well, the guy who wrote all that decided it was a good idea to have it all in one single component with more than 10k lines of code across several methods named almost the same with a huge list of component variables handling the whole state, with incredible names like "points", "pointss", "pointsss"; basically he added another letter every time he couldn't think of a name.
Also in that project: Angular forced him to use TypeScript but he didn't want to write any interface because what's the point, right? So he annotated everything with any.
Oh, man, I do not miss being there.
Oh no... I can see it now:
That just brought very very bad memories hahaha.
Was pointsss a list of lists of lists of points?
Of course not, that'd have made a little tiny bit of sense!
A bit off-topic, but parts of your site confused me a little when I visited the link in your post, so I thought you might like hearing about it.
The "Members" tab shows both "Account" and "Login" no matter if you're logged in or not (And no "log out"). And if you can't see a page it just shows "You are unauthorized to view this page." in small text where the content would be, without telling you if it's because you're not logged in, or don't have a subscription.
There's also no easy way of seeing if an blog post is free or not. If I go Members.Account > Subscriptions > Basic it sends me to /tag/free which lets me filter the free ones, but I don't see a way of getting there from the blog itself. Nor are the tags visible in the blog post list.
All great critiques! Unfortunately, I haven’t found any nice ways to work around them. I’m not a web dev, so I’ve been rocking Wordpress for about 2.5 years now. Solutions to these problems aren’t always clear cut, and I’d prefer not to edit the theme files if I don’t have to.
EDIT: Okay, I fixed at least one of the problems! The unauthorized messaged you get is different if you're logged in or not now. I'm using MemberPress, and they have a shortcode which I've setup like this:
As for the other problems, I'll have to sit and think about them for a bit.
Alright, I just removed the login link altogether. All your account related info should be in the sidebar anyway.
I'll look into the last issue. I'm thinking I might have to add a watermark or something to the images. Otherwise, I'll have to add some custom CSS or something to make free/paid articles clear.
At last, I'm adding borders to the images, so it should be a bit more obvious when something is free (silver border) and when it is not (gold border). Public articles will continue to have no border at all.
Also, I added the free and premium tag links to the top of the blog archive. You should be able to get there in two clicks from the homepage now.
Seems like you've gotten a lot done, looks way better now ^
Even easy to use on mobile.
I was hired on at my current job to replace the developer before me who was part of the way through building an application that replaces what was at the time done in three very old applications. The opening method, called by pressing the start button, was named "DoStuff()". There were several other versions of "DoStuff" throughout the code and it made the job of learning what had already been done and needed to be done even harder than it needed to be. Thanks guy before me.
Haha I always love stories like this. It seems readability is always an afterthought.
Sure seems like! The first time we were debugging a soap request together on code I was able to conceptualize and write from the ground up, my manager was blown away at the OOP style of error output from small, single-job methods with descriptive names: "oh, it's getting hung up in the binding portion of the login method. Wow that's helpful!"
No more DoStuff() on my watch, dang it!
I teach a Java class, and students often gravitate toward strings because of their functionality. Why try to get the third digit from a number using math (i.e.
(5092 / 10) % 10
) when you can convert it to a string and call the index method on it (i.e.Integer.toString(5092).charAt(3)
)?Not making an excuse for this code! It's bad, but I can see why people do it. haha In this case, it really makes no sense.
For me it was a 2000 plus line function in PHP that had several include files with variables declared and used across a variety of files, then multiple 1 character variables reused for completely different things and the only comments were leftovers from some other time so they were inaccurate and misleading.
This sounds like an obfuscation challenge. haha
I wrote this gem yesterday:
The client does most of the front-end development and the whole logic for this was implemented ass-backwards; the checkbox's checked state disabled an email from being send. I chose to run with that logic on the back-end so we would be less likely to mix up the intention of the checkbox.