What’s a simple way to share and learn refactor?

Trung Vo
3 min readFeb 20, 2021

I have been organizing coderetreat and creating screencasts on refactoring and TDD, etc… however, I find it takes lots of time and effort to organize, preparing and facilitating. (it’s not that I complaining about it as a matter of fact I love it every single second and I’m amazed at how much I have learned from the community)

I have been asking myself, what’s the simpler way for me to learn refactor and share with others? (why refactor, you may ask? it’s because it’s my favourite topic in the long never-ending list of agile technical practices) and for some reason, I really like to share my boring meme jokes, so I guess why not share a list of animated gifs of refactoring and the motivation of it.

I guess since I’m an Asian guy (hopefully some kind of descendants from Bruce Lee) so this saying pretty cool to me:
“I fear not the man who has practiced 10,000 different kicks once, but I fear the man who has practiced one kick 10,000 times.”

and as a matter of fact, there are so many moves in refactoring, so I’m curious if I could just distill most of the refactoring moves in under 10 moves (like there’s are 10 basic numbers)

so the game plan for this article is to post as many refactoring moves/snippets as possible but then distill them and reduce them to under 10 moves/snippets. So here goes the list

Extract Method

Motivation

  • separate the intention and implementation
  • put a name to the block of code (“Naming as a Process” from Arlo)
extract method snippet with naming

Rename method, classes, fields

Motivation

  • Easy to read code start with good naming and naming is hard
  • “Naming as a process” provides good heuristic for naming but it’s too freaking long.
  • I find this short, simple and easier to remember

Golden Master

Motivation

  • Provide safety nets for doing refactoring by leverage Standard IO
  • It’s a quick way to provide test coverage without knowing much about the underlying code
  • It would probably more tedious to mock out external/IO/Database call in the code.

…still under construction and more to come on the list

References

--

--