The joy of deleting code
I consider myself a software craftsman. As every craftsman, I take good care of my craft. I create it, I augment it, and occasionally I reduce it.
Adding new features always makes me happy and I can understand why. I augment something that I really care about, making it even better. What I find difficult to understand is why I take so much joy when I am deleting code.
It just doesn't make sense. Every line of code I wrote has cost me time and/or mental effort. Sometimes a significant amount of both. I should feel bad when I figure out that I don't need this massive block of code or this feature is just useless and needs to be removed.
My only explanation is that it has to do with my mental model when building and understanding software. By default, I try to fit the entire program I am working on in my mind. By fit, I mean that, at some capacity, I try to be able to "dry run" the program myself. I can "calculate" what output the program might produce when certain inputs are given.
And I do this almost all the time while developing. When modifying a method, when refactoring some part of the code, when moving variables around. I quickly perform "tests" to ensure that I am not breaking anything.
(Ideally, software is split into self-contained modules for this exact reason: to be able to work on a module without the need to understand almost anything outside of it. But in reality, this rarely happens. Modules are rarely self-contained and small enough projects are not split into modules at all. Anyway, this is a subject for another time.)
Therefore, I suspect that the joy I get when I have to delete some code is not for the deletion per se. The joy comes from the simplification. If the codebase is reduced then it will be easier to "fit" it in my mind when trying to "dry run" it.
This better understanding leads to increased happiness when working on the codebase and the joy I am referring to. I am not happy about getting rid of something I spend time and energy on in the past. I am happy because the reduced code size will require less mental effort when working on that project.
So there you go. Go and delete that unneeded feature without feeling guilty about the joy you get. Until another feature takes its place and you are back to square 0 :)