Where do we start refactoring a large method?
We see a large method and decide to refactor.
There is so much to nip away at.
Where do we start?
Has this happened to you? It is not only difficult picking a starting point, but if we pick a less than ideal place to start, the abstractions we end up developing may be no better.
Sandro Mancuso suggests we start with statements nested most deeply within our code.

The deepest branches gives us small, localised problems to solve where there are fewer dependencies to deal with. It is also likely that the deepest branches will be expressing details that don’t belong in the method, i.e. details that violate Uncle Bob’s ‘one Level of abstraction per method’ rule. As we nip away at those details, patterns that express the methods true intent should emerge. Once we start seeing those patterns, we can come up with better abstractions.
Sandro demonstrates the technique in the following video:
Relevant
Test pyramid and ice-cream cone
The test ice-cream cone is a strategic anti-pattern. It indicates excessive reliance on expensive and flaky forms of testing, such as manual and end-to-end, especially for components that could otherwise...
Dragan on lack of design skills
The following is a message shared on the company’s internal messaging app by Dragan Stepanović while we worked together at Careem. It was around 2018 or 2019. I have referred...
RefactoringRabbitHole
Code can never be perfect. So when we’re refactoring, we must call good enough at some point. When we forget to call good enough, we’re falling down the metaphorical rabbit...
Architecture Decision Records (ADR) for this site
ADR is for architecture what Git’s commit log is for code. It is a light-weight, append-only, process for documenting changes to a system.
Recent posts
A worked example of Value-Stream Mapping
Value-stream maps can be daunting at first glance like these maps on Google Images. ValueTech (a made-up software company for the purpose of our example) thought so too until they...
Notes on Value-Stream Mapping
A value stream is the sequence of activities required to design, produce, and deliver a good or service to a customer. – Value Stream Mapping by Karen Martin and Mike...
First experience with Event Storming
Event Storming is a technique that uses post-it notes to map out a business domain. Alberto Brandolini initially used it as a means to identify aggregates in the context of...