How to refactor a Delphi unit with 10000 lines with no documentation?

后端 未结 8 1987
醉话见心
醉话见心 2021-02-02 00:28

I have been assigned the task to refactor a Delphi unit. Wow. 10000 lines of code, no documentation, tons of copy and paste code.

THere are many methods made with copy a

相关标签:
8条回答
  • 2021-02-02 01:03

    I think the best thing you can do is to write DUnit Tests for the interface. It forces you to understand the existing code, helps during debugging and it ensures that the interface acts the same after refactoring.

    The Top 12 Reasons to Write Unit Tests apply perfectly in your case:

    • Tests Reduce Bugs in New Features.
    • Tests Reduce Bugs in Existing Features.
    • Tests Are Good Documentation.
    • Tests Reduce the Cost of Change.
    • Tests Improve Design.
    • Tests Allow Refactoring.
    • Tests Constrain Features
    • Tests Defend Against Other Programmers
    • Testing Is Fun
    • Testing Forces You to Slow Down and Think
    • Testing Makes Development Faster
    • Tests Reduce Fear (Fear of change, Fear of breakage, Fear of updates)
    0 讨论(0)
  • 2021-02-02 01:08

    Start out small and eventually do a partial or full rewrite. Start creating base classes to accomplish pieces of the puzzle without changing the output. Rinse-repeat until you have a new, supportable codebase. Once you hit those copy-n-paste routines, you'll have base classes to do the work and it'll really help accelerate the task.

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