8 ms·
Dunno, I successfully refactored some legacy services. Some of them even were a big index.js spaghetti files. You have to start with the smallest and most cons
by leidenfrost 4y ago
Dunno, I successfully refactored some legacy services. Some of them even were a big index.js spaghetti files.
You have to start with the smallest and most conservative to the most "refactory" ones:
- figure out what enters and what exits from the program, and create a test suite that reflects every known combination
- move parts of main() to funcions
- figure out what variables can be converted from mutations to returned values
- move thr ifs(){} to maps, early returns and such
- figure out the database schemas from newly written data
- infer model relationships fro further writes
- attempt to implement some pattern design, even if its just dummy variables
Sometimes you even have to do it at the last stretch of time of your workday, and slowly the mess will become clearer, your test suit more exhaustive and comprehensive.
And at some point it will achieve feature parity with the legacy service
- mixedCase 4y agoThe GP is referring to the political costs of changing bad code, not the technical challenges which are almost always manageable by any experienced programmer. Egos, however.
- leidenfrost 4y agoYeah. But there were times where I did some hidden refactoring even if people said "no" if I asked for permission. In part to maintain sanity in a toxic environment, and in part because I knew they just accepted it if it was handed to them.
- eska 4y agoYou’re the guy in corollary 1 in this article. https://yosefk.com/blog/people-can-read-their-managers-mind.html https://yosefk.com/blog/people-can-read-their-managers-mind.... Either you’re successful AND your managers have an epiphany that you were right and they were wrong, or you fail and your managers will punish you for ignoring their instructions. It’s a risky strategy for an employee.