What can you do to a legacy codebase that will have the greatest impact on improving the quality?

前端 未结 11 1199
既然无缘
既然无缘 2021-01-30 06:51

As you work in a legacy codebase what will have the greatest impact over time that will improve the quality of the codebase?

  • Remove unused code
  • Remove dup
相关标签:
11条回答
  • 2021-01-30 07:24

    As a parallel to what Josh Segall said, I would say comment the hell out of it. I've worked on several very large legacy systems that got dumped in my lap, and I found the biggest problem was keeping track of what I already learned about a particular section of code. Once I started placing notes as I go, including "To Do" notes, I stopped re-figuring out what I already figured out. Then I could focus on how those code segments flow and interact.

    0 讨论(0)
  • 2021-01-30 07:33

    The single biggest thing that I've done to the legacy code that I have to work with is to build a real API around it. It's a 1970's style COBOL API that I've built a .NET object model around, so that all the unsafe code is in one place, all of the translation between the API's native data types and .NET data types is in one place, the primary methods return and accept DataSets, and so on.

    This was immensely difficult to do right, and there are still some defects in it that I know about. It's not terrifically efficient either, with all the marshalling that goes on. But on the other hand, I can build a DataGridView that round-trips data to a 15-year-old application which persists its data in Btrieve (!) in about half an hour, and it works. When customers come to me with projects, my estimates are in days and weeks rather than months and years.

    0 讨论(0)
  • 2021-01-30 07:34

    I work with a legacy 1M LOC application written and modified by about 50 programmers.

    * Remove unused code
    

    Almost useless... just ignore it. You wont get a big Return On Investment (ROI) from that one.

    * Remove duplicated code
    

    Actually, when I fix something I always search for duplicate. If I found some I put a generic function or comment all code occurrence for duplication (sometime, the effort for putting a generic function doesn't worth it). The main idea, is that I hate doing the same action more than once. Another reason is because there's always someone (could be me) that forget to check for other occurrence...

    * Add unit tests to improve test coverage where coverage is low
    

    Automated unit tests is wonderful... but if you have a big backlog, the task itself is hard to promote unless you have stability issue. Go with the part you are working on and hope that in a few year you have decent coverage.

    * Create consistent formatting across files
    

    IMO the difference in formatting is part of the legacy. It give you an hint about who or when the code was written. This can gave you some clue about how to behave in that part of the code. Doing the job of reformatting, isn't fun and it doesn't give any value for your customer.

    * Update 3rd party software
    

    Do it only if there's new really nice feature's or the version you have is not supported by the new operating system.

    * Reduce warnings generated by static analysis tools
    

    It can worth it. Sometime warning can hide a potential bug.

    0 讨论(0)
  • 2021-01-30 07:34

    I'd say it largely depends on what you want to do with the legacy code...

    If it will indefinitely remain in maintenance mode and it's working fine, doing nothing at all is your best bet. "If it ain't broke, don't fix it."

    If it's not working fine, removing the unused code and refactoring the duplicate code will make debugging a lot easier. However, I would only make these changes on the erring code.

    If you plan on version 2.0, add unit tests and clean up the code you will bring forward

    0 讨论(0)
  • 2021-01-30 07:35

    Late to the party, but the following may be worth doing where a function/method is used or referenced often:

    • Local variables often tend to be poorly named in legacy code (often owing to their scope expanding when a method is modified, and not being updated to reflect this). Renaming these in line with their actual purpose can help clarify legacy code.
    • Even just laying out the method slightly differently can work wonders - for instance, putting all the clauses of an if on one line.
    • There might be stale/confusing code comments there already. Remove them if they're not needed, or amend them if you absolutely have to. (Of course, I'm not advocating removal of useful comments, just those that are a hindrance.)

    These might not have the massive headline impact you're looking for, but they are low risk, particularly if the code can't be unit tested.

    0 讨论(0)
  • 2021-01-30 07:36

    I would say just leave it alone for the most part. If it's not broken then don't fix it. If it is broken then go ahead and fix and improve the portion of the code that is broken and its immediately surrounding code. You can use the pain of the bug or sorely missing feature to justify the effort and expense of improving that part.

    I would not recommend any wholesale kind of rewrite, refactor, reformat, or putting in of unit tests that is not guided by actual business or end-user need.

    If you do get the opportunity to fix something, then do it right (the chance of doing it right the first time might have already passed, but since you are touching that part again might as well do it right time around) and this includes all the items you mentioned.

    So in summary, there's no single or just a few things that you should do. You should do it all but in small portions and in an opportunistic manner.

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