Goodbye, Clean Code
So the two cases against writing the most legible, succinct code <i>given the specifications at the time of writing it</i> are:<p>&gt;Firstly, I didn’t talk to the person who wrote it. I rewrote the code and checked it in without their input. Even if it was an improvement (which I don’t believe anymore), this is a terrible way to go about it. A healthy engineering team is constantly building trust. Rewriting your teammate’s code without a discussion is a huge blow to your ability to effectively collaborate on a codebase together.<p>There&#x27;s no question about this. Nobody likes the self-proclaimed savant who works in isolation and makes sweeping changes to the codebase or other people&#x27;s work without collaborating and gaining some consensus. If it&#x27;s a change worth making it should be a simple case to present to your (hopefully) equally intelligent team.<p>There is a difference, it has to be highlighted, between refactoring someone&#x27;s code in order to extend it yourself and simply re-writing someone&#x27;s implementation because it doesn&#x27;t suit your requirements. The former is part of the job, the latter should at the very least be an opportunity to mentor the person&#x27;s whose code you want to re-write in <i>why</i> it was suboptimal and guide them on the changes you&#x27;d like to make, or even give them the chance to make it themselves. This is kind of what code reviews are supposed to do.<p>That does not negate the need to structure and optimize code to remove duplication whatsoever. It&#x27;s not an argument against clean code standards and it&#x27;s weak that it amounts to 50% of his case here.<p>&gt;Secondly, nothing is free. My code traded the ability to change requirements for reduced duplication, and it was not a good trade. For example, we later needed many special cases and behaviors for different handles on different shapes. My abstraction would have to become several times more convoluted to afford that, whereas with the original “messy” version such changes stayed easy as cake.<p>Time changes, requirements change. It&#x27;s part and parcel of our jobs in software development. Writing code that at one point is optimal and most legible for the cases present should also be done to try to make it refactorable and extendable.<p>It is much easier to refactor and extend code that isn&#x27;t riddled with duplication and mangled with hardcoded business logic. Abstract your code and write your implementations well, name things in a way that people can read it and write tests that describe what&#x27;s expected from it.<p>Refactoring well isn&#x27;t easy work. Refactoring a sprawling legacy codebase with a lot of duplication and legibility problems is <i>significantly</i> worse.<p>I&#x27;m not saying we need to be dogmatic here. If you&#x27;re given the opportunity to develop new code you should be aiming to do the best job of it given what you know <i>now</i>, in a way that will be comprehensible to you, or whoever needs to touch that code <i>next</i>.<p>We all know that there are problems with premature optimization caused by &quot;best practices&quot; evangelists who&#x27;d happily drive up time-to-market and operating costs&#x2F;complexity exponentially in the name of having the codebase and applications &#x2F; services architecture in line with whatever he or she has read lately from &quot;thought leaders&quot; in our industry, but writing the code for a given application in line with the above isn&#x27;t one of them.