Therapeutic Refactoring
Image courtesy Kevin Zen (flickr.com/photos/kevinzen)

Therapeutic Refactoring

At a conference I attended a few years ago, Martin Fowler used the term "Therapeutic Refactoring" in response to a question. His explanation and a follow-on conversation convinced me that I had experienced the phenomenon that he was describing.[1]

Refactoring — improving the internal structure of code while keeping its behavior intact — is a key practice to which all self-respecting software teams give at least an honest try. "Refactoring" as a term has become so ubiquitous that it has leaped from software engineering into other disciplines: such as online publishing, hardware and biology.

By definition, refactoring has zero direct business value — the behavior of the code remains unchanged after the refactoring as no features are added, removed or modified. Of course, refactoring, if done in a regularly disciplined manner, provides significant indirect business value. I liken refactoring to the HR department of a company: the "People-People". This department by itself doesn't make any profit at all; but try disbanding this group in a healthy, profitable company and see how long the company survives.

Perhaps because of its nature as a source of indirect business value, software teams often find it difficult to do regular refactoring. This leads to badly factored code, and a tendency to "sell" refactoring directly to the business stakeholders as a valuable commodity. This approach inevitably fails — as the business is unwilling to spend money on code "that should have been written correctly in the first place". Ron Jeffries has written an absorbing article on the futility of this approach: Refactoring - not on the backlog.

Ron Jeffries' suggestion is to do refactoring as part of a feature story. My colleague, Emma Ritcey, shared with me her experiences of adopting this approach on a problematic Angular codebase she inherited. This is wonderful when it’s practiced; except that it can be hard to get started if you haven't done it before. And you don't learn it by aimlessly and lonesomely hacking through the thicket of "weeds, brush and undergrowth" in your code. So how do you get started?

This is where adopting refactoring as a communal therapy can be useful.

The team can have a soul-baring confession among themselves, admitting that their daily frustrations with the code won't subside until they themselves spend some time cleaning things up. The team can schedule a combined activity — replete with pizza and drinks, if needed — and enjoy team bonding while sanitizing their code.

Therapeutic refactoring has beneficial effects not only on the code but on coders, too. This benefit, in my experience, is just as rewarding as that of the resultant clean code.

Footnotes

[1] My friend Vishal Bardoloi reminded me of Katrina Owen's talk titled "Therapeutic Refactoring". She uses the term to define a related but different phenomenon. Perhaps we in the software in industry have much use for therapy, both individually and collectively! I am happy for a broad definition that encompasses multiple approaches to refactoring.

Vishal Bardoloi

Principal TPM at Amazon

5 年

Interesting! I always thought the term was from Katrina Owen's talk at RubyConf in 2012.

要查看或添加评论,请登录

Saleem S.的更多文章

  • Whose story is it, anyway?

    Whose story is it, anyway?

    There is a viral post on LinkedIn about a CEO, who shared a selfie of himself crying because he had to layoff "a few"…

  • Do you "like ????" your own posts?

    Do you "like ????" your own posts?

    I have a basic understanding of how LinkedIn’s algorithm works. I know how to take advantage of it and I have respect…

  • Pair Programming – a most uncomfortable working situation

    Pair Programming – a most uncomfortable working situation

    Firefighters, soldiers, hostage negotiators, and trauma specialists regularly deal with life and death situations at…

    5 条评论
  • Why are arrays zero-based in so many languages?

    Why are arrays zero-based in so many languages?

    This article is a summary of a wonderful lightning talk my friend and former colleague Kent Spillner gave a while ago…

    4 条评论
  • The morality of software

    The morality of software

    My brother (Dr. Nadeem Siddiqui) and I drove from Dallas to the Big Bend National Park in early November this year.

    14 条评论
  • You're already eating bugs for breakfast!

    You're already eating bugs for breakfast!

    The bliss of ignorance! It seems to make you more sure of yourself. Dunning and Kruger have shown that individuals who…

  • java.util.Optional — dividing opinions since 2014

    java.util.Optional — dividing opinions since 2014

    It may not be the worst source of divisiveness that you encounter in your social media feeds these days; however…

  • A one-in-a-thousand chance of failure

    A one-in-a-thousand chance of failure

    Gambling is often called a tax on the mathematically challenged. The odds of winning are always stacked (often heavily…

  • The US federal government shutdown broke my software (seriously)

    The US federal government shutdown broke my software (seriously)

    On January 19th, 2018, the United States' federal government partially shut down due to a political impasse, preventing…

    7 条评论
  • Why the Anita Borg award matters, and why it isn't enough

    Why the Anita Borg award matters, and why it isn't enough

    ThoughtWorks was awarded the 2016 Top Company for Women Technologists award by the Anita Borg Institute. To me, this is…

    3 条评论

社区洞察

其他会员也浏览了