Chapter 17. Chaining

Tidyings are like potato chips. You eat one, and you’ll want another. Managing the urge to keep tidying is a key tidying skill. You just tidied; should you tidy more? It depends (we’ll get to what it depends on in Part III).

How big you step will be up to you, but I encourage you to experiment with sticking to tiny tidying steps. Optimize each step. From the outside it will look like you are running, but, like the centipede, you will know you’re taking many little steps.

Tidying becomes a game of chess, with moves visible ahead. Let’s look at how tidyings set up further tidyings:

Guard clause

Once you’ve set up a guard clause, the condition may benefit from being turned into an explaining helper or extracted into an explaining variable.

Dead code

Once you’ve removed the clutter of dead code, you may be able to see how to sort the code into reading order or cohesion order.

Normalize symmetries

Once you’ve made identical code identical and different code different, you may be able to group precisely parallel code into reading order. I did this once with a file containing several web entry points. Once they all looked alike, it was natural to group them at the top of the file as a kind of table of contents to the rest of the code.

New interface, old implementation

Once you have your shiny new interface, you’ll want to use it. If you don’t have the automated rewrite tools to convert all callers, you’ll need to convert them one at a time. This is the first ...

Get Tidy First? now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.