Advice on working with legacy code

后端 未结 4 1618
日久生厌
日久生厌 2021-01-30 08:59

I need some advice on how to work with legacy code.

A while ago, I was given the task to add a few reports to a reporting app. written in Struts 1, back in 2005. No big

4条回答
  •  悲&欢浪女
    2021-01-30 09:39

    In a few words: before make any modifications to legacy code its good idea to start from automated unit tests. This will give developer understanding about key things: dependencies this piece of code has, input data, output results, boundary conditions so on.

    When it’s done most likely you will better understand what this code does and how it works.

    After that its make sense (but not must) clean code a bit giving more accurate names to local variables, moving some functionality (repetitive code, if any) in to functions with clear human friendly names.

    A simple clean up could make code more readable and at the same time save developer from regression issues with unit tests help.

    Refactoring – make small changes, step by step, when you have a time and understanding of the requirements and functionality, regularly unit testing the code.

    But do not start from refactoring

提交回复
热议问题