3 ms·
> When I want to refactor my first step is to inline code and data until it cannot be inlined further, so that new approaches for reuse appear. I do a similar
by chriswarbo 10y ago
> When I want to refactor my first step is to inline code and data until it cannot be inlined further, so that new approaches for reuse appear.
I do a similar thing. My first attempt is usually full of layers of helper functions and not-quite-right abstractions as I was simultaneously trying to understand and solve the problem.
Once I've got something that works, I refactor it to collapse these layers and remove the bias introduced by my previous fumbling. Inlining reduces external references, and point-free style eliminates local references ( https://wiki.haskell.org/Pointfree https://wiki.haskell.org/Pointfree ).
After such a refactoring, the code is dealing much more with inescapable features of the problem, rather than fighting against itself. At this point, I can do a final cleanup to introduce abstractions to reduce redundancy and aid understanding.