How often should you refactor?

前端 未结 25 2324
耶瑟儿~
耶瑟儿~ 2020-12-13 01:36

I had a discussion a few weeks back with some co-workers on refactoring, and I seem to be in a minority that believes \"Refactor early, refactor often\" is a good approach t

25条回答
  •  我在风中等你
    2020-12-13 02:09

    I try to go by this motto: leave all the code you touch better than it was.

    When I make a fix or add a feature I usually use that opportunity to do limited refactoring on the impacted code. Often this makes it easier to make my intended change, so it actually doesn't cost anything.

    Otherwise, you should budget dedicated time for refactoring, if you can't because you are always fighting fires (I wonder why) then you should force yourself to refactor when you find making changes becomes much harder than it should and when "code smells" are just unbearable.

提交回复
热议问题