Developers as proof readers

Does this scenario sound familiar? You recently implemented a feature. Everything works perfectly, you ironed out a couple of little bugs and had great test coverage and were very happy with the code architecture. Now another developer comes along with a monster PR that rewrites it all. You check out the PR with distaste. Of course it’s going to be garbage, you spent ages on making that code perfect. Wait, their refactor actually makes a lot of sense, what’s going on!?

Well after writing code professionally for 10 years, it’s happened to me over and over again. I’ve come to realise and embrace the magical second refactor. It’s very hard to see from your initial standpoint how your code will be used in the future. You can architect it as best you can to make it pragmatic, readable and easy to change. Even if you do all this perfectly (which is unlikely), your head will be stuck in your implementation. That’s why another developer with an outside perspective who just read your code will be in a better position to make the code even better (in a way you could never have thought of).