exupero's blog
RSSApps

Refactoring in different domains

A big part of software development is refactoring. Writing new code is fun, but I also enjoy changing the structure of code to provide different affordances. There are a lot of aspects to consider when refactoring code, such as how readable the code is to its audience, how performant it is, how easy it is to change and extend, and how it constrains future work. Writing good code is an iterative process of discovering what best serves your purposes. It's harder to write good code from scratch. If someone does writes good code from scratch, it's probably because they've gone through the iterative journey of discovery before and have learned patterns that are useful in the present circumstance.

While I'm a professional software engineer, my degree is in math, so besides refactoring code I also learned a bit about refactoring mathematical concepts. Math doesn't call that process of discovery "refactoring". Instead it focuses on symbolic manipulation and juggling terms in pursuit of a vague concept called "elegance". Naturally elegance is subjective. Personally, I think of elegance in terms of affordances: an elegant expression allows you to understand it or use it in ways an equivalent but unelegant expression doesn't. Often an elegant expression is one whose relationship to other expressions is readily apparent, or which can be easily integrated into other expressions.

The only other domain where I have experience refactoring is in English composition. In the written word, refactoring is called "editing". When I started writing for fun in high school, I felt like my best draft was my first draft, but that was because I didn't understand how to edit. After years of writing, I can see what's weak in my first drafts, and I've developed techniques for improving those weaknesses. None of those techniques are unique to me. Mostly of it is age-old writing advice, but I've learned why that advice is important, when to use it, and when to occasionally ignore it. The affordances offered by good writing are psychological: how well does the writing keep the reader's attention? How well does it provoke an emotional response? How well does it cause the reader to think or take action? Writing English well is a much more demanding task than writing good code. In software terms, the written word is code that runs on the machine of the human brain, and no two compilers interpret that code the same way. A lot of safe writing advice is a codification of what's common to human processing.

Beyond the fields of software, math, and English composition, I don't know much about what refactoring looks like. In wood- and metalworking and other construction disciplines, I'd guess refactoring involves changing the structure or assembly of something to make it use less material or more common parts or be easier to put together. For the design of electrical circuits, the closest idea I've heard of is Muntzing.

I imagine other arts have a concept comparable to refactoring. Certainly graphic design has rules of thumb like alignment, color scheme, and consistency of fonts. Do other visual disciplines have refactoring? What about musical composition? That one intrigues me the most. How does a composer create affordances in a piece of music? Or is that the wrong way to think about improving a musical composition? Beyond the basics of harmony, music theory, and triggering an emotional response, how does a composer turn an average piece of music into a great one?

I feel like I don't really understand a domain until I understand how to refactor something in them.

If you know of other domains that have a concept similar to refactoring, or you have a perspective on refactoring in any of the areas mentioned above, email me.