How to restrain one's self from the overwhelming urge to rewrite everything?

后端 未结 20 718
遥遥无期
遥遥无期 2021-01-30 12:50

Setup

Have you ever had the experience of going into a piece of code to make a seemingly simple change and then realizing that you\'ve just stepped into a wasteland tha

相关标签:
20条回答
  • 2021-01-30 13:50

    Write more unit tests just to find out that the code is running perfectly fine.

    If you still have the urge to rewrite it, you will have some tests to find out that your rewriten code is now failing ;)

    0 讨论(0)
  • 2021-01-30 13:52

    The most memorable project of this kind for me occured some 4 years ago when I was called in to a remote office to "help" with a project that was due in 1 week for major presentation to the client and was not working yet at all. The project had been primarily off-shored to India, and IMO, a project management failure resulted in a ton of spaghetti code that was too fragmented to ever work properly in its current form.

    After a full day's review, I presented my opinion to the management that the project simply needed wholesale refactoring and reorganization or it would never work properly. The result of this discussion was 6 days of 20 hours work / 4 hours sleep, 2 of which I actually spent sleeping on the couch in the company lobby due to the wasted time when driving back to the hotel.

    The major improvements to the code included:

    • Application of naming standards
    • Moved into source control
    • Development of a build process
    • Documentation of the individual components

    Most of the original code was left in place, but simply moved and reorganized / refactored to make it sustainable in the long term. Was it hell week? Sure. Did it make the project more successful? Yep.

    I can't live with spaghetti code, and I'll often donate my own personal time to address it.

    0 讨论(0)
提交回复
热议问题