Skip to main content

The Difference Between Refactoring and Changing

The word refactoring has become popular in software development. Unfortunately, like many things in software development, not everybody uses it right. That is probably because it takes some effort to understand.

Somebody who doesn't understand refactoring might use the words "refactor" and "change" interchangeably, like synonyms. However, refactoring does not mean the same thing as changing.

Example Using Math
Refactoring means changing the factors without changing the result. Refactoring software is like refactoring a multiplication problem in arithmetic. For example, consider the math problem:
  • 3 * 4
This can be refactored to:
  • 2 * 2 * 3
  • 2 * 6
In these examples, the factors change, but the result remains the same:
  • 3 * 4 = 12
  • 2 * 2 * 3 = 12
  • 2 * 6 = 12
However, making this kind of change is not refactoring:
  • 3 + 4
Because it changes the result:
  • 3 * 4 = 12
  • 3 + 4 = 7
So, that was a different kind of change.
Refactoring does not mean the same thing as changing.
Example in Software
Refactoring software has a similar meaning to refactoring math problems. Refactoring refers to a specific kind of change which changes the implementation of the software without changing the application of the software. In other words, refactoring involves changing the inner workings of software "under the hood" without changing its external functionality.
Refactoring means changing the factors without changing the result.
For example, consider a program like this:
  • Declare a new variable named "greeting"
  • Initialize the value of greeting to "Hello World!"
  • Display the value of greeting
This can (and probably should) be refactored to:
  • Display the value "Hello World!"
That change was refactoring because the refactored program does exactly the same thing. They both display "Hello World!" The refactored version simply no longer uses a named variable to do it. Therefore, it is a shorter, simpler, and higher quality program.

However, this kind of change would not be refactoring:
  • Display the value "Hello Sailor!"
That change affects more than the inner workings of the program, because it changes what the program actually does. The program's external functionality now displays a different message.

Accurately understanding what refactoring is and how it works provides a very useful tool to improve the quality of your software development.

Comments

Popular posts from this blog

Reality Checks to Demystify Buzzwords

As an IT insider, I feel I have something valuable to offer nontechnical people in terms of correcting misinformation. Here are a few simple tests for some popular buzzwords in tech. When evaluating a product or service, if you can honestly answer Yes to the reality check question, the buzzword probably truly applies. If the answer is No, it is probably fake. agile Does it make the developers happy? blockchain Does it cut out the middleman? cloud Does it automatically scale? microservice Does it only do one thing? object oriented Is it mostly made of interfaces? RESTful When requests arrive at a certain address, are they ready to use (without parsing)? unit test Does it prevent the tested code from touching anything outside itself?

How (Not) to Handle Different Exceptions

Came across this sample from a certain multi-billion-dollar company, purporting to show how to implement exception handling. I slightly changed a few cosmetic details to make it anonymous. try { // ... } catch (GeneralException e) { if (e instanceof SpecificExceptionA){ // ... } else if (e instanceof SpecificExceptionB){ // ... } } This is a true actual story--you can't make this stuff up. Yeah, I thought it was pretty hilarious; so I felt like I had to share it.

Starting a company or Developing ideas?

Are you starting a company that needs software developed? Or, are you a developer with ideas? Take the chance to let us know what you want We need your input to be successful. Help us help you by sharing what problems are important. It would really help us out, and we would greatly appreciate it. Thank you.