2 ms·
I didn't say I never looked at them. I said I didn't need to understand how they worked. There is a huge difference. For example, I've seen logic that looked a
by romaniv 13y ago
I didn't say I never looked at them. I said I didn't need to understand how they worked. There is a huge difference.
For example, I've seen logic that looked at roughly 10 user input fields and generated one out of 30 pre-defined values. That was the extent of what it did. It had multiple classes, complex global state management, database and session interactions and thousands lines of code (with no automated tests or comments). That's how real legacy code looks.
When asked to modify something like that, a bad developer would simply add a few more lines of code, do some manual testing and move on.
Another kind of bad developer would start refactoring that code 'by the book', writing unit tests... and would never finish.
A good developer would start by asking what is the point of that final value the code generates and why we really want to modify the logic. Sure, you want another classification of stuff, but why?
In my case I realized that everything and everyone that were relying on that final value could use something else. Instead of spending time messing around with pathological code from above I spent my time switching systems and people to using other values. Then I simply removed that legacy classification mess altogether. The number of tickets we got for the system dropped by at least 50%. I still don't know exactly how all that code worked, because I merely traced out where it interacted with the rest of the world.
Someone will surely comment "But that's refactoring!". I don't care how you call it, because at the time and place I was working on the project it was considered a rewrite, and that's what matters. If everyone followed Joel's advice, no one would question the necessity of that code, no one would look at deleting it altogether it would still be there, except bigger and buggier.