DEV Community

Cover image for Refactoring How Deep?
John Peters
John Peters

Posted on • Updated on

Refactoring How Deep?

When we first take the refactoring plunge we eventually want to ask "How deep should this go?". The answer is simply; go as deep as possible to get code that does only one thing! Doing this, by nature, turns almost everything into functional programming styles (with just a tiny bit more effort to achieve pure functions).

We begin to see (over-time) that programming is nothing more than an ordered set of functions, composable anywhere (if we've made them reusable in our own libraries).

In addition, we ensure that each function is bullet proof, and all of a sudden, down the road we pick up immense speed in creating applications.

We also become familiar with what good coding patterns should look like and can immediately refactor code into smaller functions.

If we then see the pattern of "hey this does that same thing as that other thing we did last week" except it's for a different type of data, then we're in luck... it's time to look into implementation of generic functions. Those that work on any collection regardless of type.

Deep Refactoring is always good, it forces us into creating composable software. Composable Software is just 'pulling in parts where we need it.' We are composing an application the same way car are built.

TIP: Avoid callbacks! Why? When we have a lot of smaller functions each callback has to push the stack and then on return pull it. When you are debugging this you have to go with the Unwind when single stepping. It's not fun to do that.

JWP 2020

Top comments (0)