How do you refactor?

前端 未结 14 1254
别那么骄傲
别那么骄傲 2020-12-13 03:06

I was wondering how other developers begin refactoring. What is your first step? How this process (refactoring) differ if you refactor code which is not yours? Do you write

14条回答
  •  佛祖请我去吃肉
    2020-12-13 03:26

    I remove duplication, which unifies the thought patterns inherent in the code. Refactoring needs to achieve those two things. If you have code that does the same thing twice, refactor it to a common location, unifying the abstraction. If you have the same literal in three places, put it in a constant, unifying the purpose. If you have the same group of arguments, ensure they're always used in the same order or, better yet, put them in a common structure, unifying information groups.

提交回复
热议问题