Pastebin
Paste #2289: How to clean up old code
< previous paste - next paste>
Pasted by tdn
From: http://developers.slashdot.org/story/12/01/14/008236/code-cleanup-culls-libreoffice-cruft Speaking from personal experience dealing with huge, complex, unmaintainable PHP legacy systems for the last ten years, let me tell you a far better path: 1. Search the code base for what may be directly calling the code. 2. Set debug breakpoints at the start of each piece of cruft code and rigorously test the app. 3. Create a custom exception (e.g. CrapCodeHitException) and throw it at the beginning of each code segment you want to remove. If you don't hit any of the exceptions after, say, a week of normal browsing doing other things, plus testing, then proceed to step 4. 4. Catch the CrapCodeHitExceptions at the highest level you dare, log this into a separate log file you will have permission to read. Commit the code into a releaseable branch so that it ends up on your QA and staging servers. 5. Get approval to have the logging code be pushed to staging. Add comments above each cruft piece of code stating a) the level of risk you think if it is removed, b) when one should feel free to remove it (pick increments like 3 mo, 6 mo, 1 yr, based on risk), c) your name. If shit hits the fan cuz of removal, you want to man up and accept responsibility so your peers don't waste precious cycles needlessly troubleshooting why this "perfectly fine" code was seemingly arbitrarily removed. 6. After each time of your comments has elapsed, if the code was never triggered (parse the logs!), feel free to remove it. Please leave a note behind that you removed such and such, tho, and stick your name on it. Remove these notes after a year. I've personally cleaned up 100,000s lines of code using this mechanism on several large and complex sites, without a single failure.
New Paste
Go to most recent paste.