5 ms·
Oh my god, I've been in this situation. We had an executable that had the behavior "if the program is started with '-s', it's a server. Otherwise, it's a client
by jes5199 13y ago
Oh my god, I've been in this situation. We had an executable that had the behavior "if the program is started with '-s', it's a server. Otherwise, it's a client that connects to the server". While the rest of us moved on to the next feature, a Purist came and rewrote that code to use a dependency injection framework ("Guice", in this case).
On monday, we said "hey, there's a new bug - when started in Server mode, this code still tries to open a connection upstream! It looks like a Client class is getting created when we don't need it! ... and hey, where did our code go?"
The Purist said "oh, well, that's a weird thing to want and isn't supported by the framework, but I can put a kludge in here...." The kludge is, unfortunately, too weird to describe in english - he played a game with lazy loading and well-when-this-happens-then-that-makes-this-happen. And the rest of us had better fights to fight so we just let it stay.
- andrewflnr 13y agoHoly crap. This guy still has/had a job?
- jes5199 13y agoYes. He's still with the company. I left for various reasons.
- mech4bg 13y agoI love the linked article and this post so much. I've seen so many coders come into a new project, think 'ugh, why is this so bad?!' and then refactor it their own favorite way. When things break, it's always the same sentiment as your guy - 'oh that's a weird thing to want', as if function should follow form instead of the other way around.
- mcv 13y agoThere can be a lot of value in refactoring code, but you should always refactor to _reduce_ bugs, rather than introduce them, and increase maintainability, rather than obfuscate it. When I see terrible code and set out to fix it, I try to change it into what the author probably meant, rather than how I would have done it. And usually that's a lot faster, because I don't have to rethink and rewrite everything. And sometimes the ugly approach really is better. I've introduced tight coupling where loose coupling was causing problems. The components were never going to be used separate from each other anyway, and this removed a whole pile of complexity that we didn't need. The simplest way is often best.
- loup-vaillant 13y agoTo this guy, and many others like him, I would ask one question: "Is your code shorter?". If not, then I can be quite confident the modification was worse than nothing. (Most of the time, "simpler" and "shorter" mean the same thing.) When I rewrite code, at least I make sure the result is simpler than whatever I started with. If not, I simply revert back to the the previous version.
- jes5199 13y agowell, the thing is, his version replaced all the code with type annotations. So, in some sense, he replaced a 5 line method with no code at all!