I’m close to being able to explain why Extract Function is the most-used refactoring. Not sure why I didn’t ask this question for 30 years but here we are. #TidyTogether
Comments
Log in with your Bluesky account to leave a comment
I finished a 3 month programming gig today on some legacy Ruby & Rails code. I spent the last hours extracting duplicated code out into a module. The tests all passed before, the tests passed during and the tests passed after.
Another dev was shocked that I'd even try this on my last day! 😀
Back in the early 2000s, JetBrains released the first commercial version of IntelliJ IDEA. After trying it a little, I gladly forked over the cost of an academic license.
I'm half-surprised that I didn't wear out the Rename Variable/Method/Whatever part of the refactoring menu.
I'm surprised that the tooling is still a problem because the "Extract method" refactoring is available in R#/Rider like for ever.
And in F#, I simply select some code and move it into a function because everything is an expression anyway.
My gut response to this would be that it's because it is a very natural way to "compartimentalizing" the problem and generating new abstractions (a new function) with a clear name that serves also as a summary reminder of what it does. It's also kinda like a new layer of indirection.
Comments
But I bet one big reason it's the most-used refactoring is that it has a very small scope – it only affects one file/class/etc. at a time.
Another dev was shocked that I'd even try this on my last day! 😀
Extract method -> Introduce Parameter Object (or "Transform Parameters" in Resharper/Rider, for reasons probably) -> Move Instance Method.
This is often followed by Introduce Field (initialise in constructor) -> Introduce Parameter.
I suspect we may have cities on Mars before that happens.
It's usually the first time they've even seen it.
I'm half-surprised that I didn't wear out the Rename Variable/Method/Whatever part of the refactoring menu.
+1 for refactoring tools
And in F#, I simply select some code and move it into a function because everything is an expression anyway.