DEV Community

Discussion on: What’s your favorite piece of code that you had to throw away?

Collapse
 
andreasjakof profile image
Andreas Jakof

This might seem a bit weird to some, but I LOVE to throw away code. And not only code written by others, but especially mine.
Once I was writing a recursive algorithm to go through a tree with not only different kinds of data in it, but also unknown number of subnodes per node. I spent the whole day on it only to think of something „better“ right when I went to it the next day. Less code, less „exceptions“ (deviations from the standard path) and more importantly more flexibility!
The new code was written in two hours (or so) and could do more, than the one I just deleted whole heartedly!

And as a general approach: Code that is deleted, has no need for maintenance. And someone smart once said: the only code, that never produces bugs is code, that is never executed (or deleted).

Collapse
 
cubiclebuddha profile image
Cubicle Buddha

Truth! Recursive algorithms can almost always be expressed more simply.

That being said, have you ever had to delete code that you felt was as good as it can get? Or have you ever had a project canceled that you really enjoyed?

Collapse
 
andreasjakof profile image
Andreas Jakof • Edited

I threw away lots of code that was as good as it gets to my abilities at the time. But since I am still learning every time I do something in code (mostly intentionally) I never feel any regret or remorse, when deleting old code of mine.
Even though I might have done it similarly, I never get attached emotionally to code I produce. I code, because I like solving problems and the challenges that force me to learn.
So even though I threw lots of code away in my personal or professional life. I never felt, that I am destroying something invaluable. It‘s a means to an end. And if that end is reached, it can go.
Maybe IF I wrote an AI sometime in the distant future, that shows human treats, I could not, but so far... I always loved hitting the delete button.

But if I had to pick something, I'd choose a BER-Parser-Implementation, that was never used. I just wanted to see, if I can do it and used it at one point in my own code, which was superfluous, when we chose Azure-ADFS for authentication.
Others prefered the one from BouncyCastle or just dont want to have anything to do with certificates.

And I guess, there is another exception, which I wrote about already here: dev.to/andreasjakof/brilliant-but-...
It was wrong to do it this way, but still ...