4 ms·
The Three Most Common Refactoring Opportunities You Are Likely to Encounter
- surfsvammel 7y agoThe worst bug I ever introduced was when refactoring duplicate code. I was refactoring handling of dates. The code was littered with date handling that was not thread safe and duplicated all over the place. So. I made it thread safe and pull it all out into a central place. But while doing so I accidentally introduced a new bug that then hit every single time dates where being handled. Which was all the time. Several thousand times per minute. Oh my. The cleaning up we had t do after that. The lessons I learned was: 1. Don’t be so eager to refactor code. 2. If you refactor repeated code you are introducing a single point of failure. Make sure it works.
- chupa-chups 7y agoI am also quite careful deduplicating code. Most of the time it is correct and good for code quality, but quite a few times the duplicated code was just seeming to be duplicated (i.e. the code was (almost) the same, but not the reason for the code). This led a few times to bugs, since someone changed the central, de-duplicated method correctly without thinking about the "other" use case unknown to her/him.