To a programmer, refactoring should never end.
In a real-life project, we cannot afford the endless refactoring. But we could do it in mind, have the chance to read some old coding created by yourself and rethink. Any other solution? Any better way to implement?
Just like setting up my .vimrc
, that is a happy project probably lasting forever. Because I reckon it will help me better the work-flow and then make me more productive, and further more I could learn some cool stuff from that.
I have made a post about drupal refactoring in my daily life.
And here I would like to make some notes about the rules in JS aspect or the general ideas.
Some general principle
All the refactoring aim to make the program readable, extensible, efficient.
-
readable
-
Sufficient comment.
-
Semantic naming (variables, functions, nameSpace).
-
-
extensible
-
Extract logic to separate functions / files.
-
Centralize: keep the similar functions, setting in one file.
-
Decoupling: observer design pattern
-
DRY: use iterator to repeat.
-
Use function’s parameter
-