HACKER Q&A
📣 tinycabbage

What code have you written that you regret?


From the difficult to debug to the morally questionable, where have you gone astray?


  👤 ccvannorman Accepted Answer ✓
Pretty much all of it. For the first few years of my programming career I would review weeks or months old code in horror. What barbarian had written this useless, convoluted gibberish? Then, the code I would go on to write that very day would be reviewed by a future me, who was again horrified by the sheer idiocy of what I had written.

Eventually I just gave up. Look, I'm a game programmer. I code because it makes pretty colors move on my screen. I favor the fast over the correct, and I only do things "right" when my inner self remembers the pain of doing it wrong before; so I stick to simple behaviors separated, rip things out immediately if they start to be a headache, build one-off behaviors that aren't scalable, because damnit I don't have time to think about how to build this correctly. I want it to work so that I can use it and move on.

I started my path as an aspiring architect who would write pure, scalable, performant and dare I say beautiful code. My programs would hum like a fugue by Bach and my comments would hang off the page like sweet blackberry bunches, easy to pluck and digest. My hopes were so high for myself!

But today I burn a path to my goal without consideration to the debt or damage it deals, my heart without morals and my mind without regret. Each day I stray further from god. Yesterday I had to rip out a utility function that took an entity and type as its input and searched the hierarchy for a parent of that entity with that type to return it, so that I could message root level objects on collisions with their child objects. What a disgusting beast I had created! What have I become! But I soldier on, unhindered by my evils. I cast code beneath my feet and it crumbles instantly as I take each step closer to hell.

But my game is really fun to play! :D


👤 jpgvm
Depends on what you mean by regret.

I somewhat regret spending my time at companies that were ultimately shutdown or acquired and my code being unceremoniously thrown out, but that isn't really about the code but rather lifestyle/career choice of working for startups.

I don't think from a creative or learning perspective I regret any of the actual coding. Sure some of it wasn't great code but that was generally a product of circumstances, generally the value I personally derived from the code was solid.

I did made an explicit career choice early on not to go into aviation/avionics because of it's dual-use. Originally being very interested in UAVs before they were cool I did built my own both fixed wing and quad-copter. After spending some time thinking about how my code would inevitably be used if I joined Boeing, Raytheon or Thales though I decided maybe something else would be better.


👤 gompertz
This is a good question. I sometimes ponder how those who write military software such as surface to air missile guidance may feel. When they started Computing Science did they have any idea they'd land up writing such code??

👤 Aqueous
On my first day at my current company several years ago I was told to refactor something that was very poorly designed and written by the tech lead who had written it. The code was impossible to work with and it took months to add the features they wanted, both because the PR process demanded small deployable PRs and because I had to avoid breaking the thing while working on it. Because I was new and because the tech lead I was working under had written the terrible code I was working on, I didn’t immediately say ‘This code is awful and the entire thing needs to be rewritten, both backend and front end.’ Instead I attempted to introduce right patterns to the data shape, etc. Suffice it to say the code was even worse and less maintainable at the end, only now I was taking the blame for it being that way because now my name was all over the git history. It was eventually rewritten anyway by another team. Suffice it to say, DO NOT touch code if it is designed in such a way as to be impossible to change. Throw it back up the chain and say , This needs to be rewritten, now. The consequences will be worse for you if you try to work around other people’s bad architecture as you will eventually be blamed for both the original mess and whatever you did to work around it given whatever condtraints on process you have. Years later. I am fixing another massive architecture mistake by the same engineer, who has since been promoted to higher levels. Over a year in, another data design mistake at a fundamental level that makes the system impossible to change without a huge refactor. Sigh.

Throw people under the bus if necessary. Don’t accept ownership of code that sucks.


👤 thescribbblr
Three years ago I wrote a php code to sum the total number of bought items and by mistake I forgot to add userid column so whenever someone added items it got save in the database but do not show in the user order section. I lost almost INR 30,000 of sales that week.

👤 smrtinsert
Code that I didn't test fully.