18

"Code refactoring" is an expression widely used in programming communities and is used to describe the work of changing or rewriting the program code without changing the code results.

What is the root word of "Refactoring"? Does it come from the word "factor", like "doing the factor" again or "factory", like "refabricating"?

28

If you use a dictionary with etymologies, you will see that the English word "factor" and similar words like "factory" and "manufacture" derive ultimately from the Latin verb "facere," which has a very broad field of meaning but mainly means to "do" or to "make." The root of the past participle of "facere" is "fact-." All of this is basic Latin that can be found in any Latin dictionary.

According to the Online Etymology Dictionary, "fact-" was then turned into a Latin noun, "factor" meaning "doer" or "maker." (Personally I do not remember this word, but I studied Latin a very long time ago.) Thence, the word passed into Old French as "facteur" meaning "doer," "author," or "creator."

So the usage that you have given of "re-factoring" seems to fit quite well with the Latin root meaning of "re-doing." Julius Caesar would have understood it once you explained to him what a computer and computer code are.

| improve this answer | |
  • 25
    "Julius Caesar would have understood it once you explained to him what a computer and computer code are." Such a task is left as an exercise for the reader. – Joe Dec 15 '17 at 21:31
  • 5
    It should be relatively easy. "Imagine an army of tiny people that pass messages around... Now imagine a set of orders that they should carry out in certain situations... Imagine what would happen if loads of laypeople kept amending those orders until they were incomprehensible... What do you think refactor means?" (But in Latin.) – wizzwizz4 Dec 16 '17 at 12:09
5

Early uses of "refactor" found by searching in google books show that it has a different meaning in the early 1990s and before.

Before the 1970s (apart from misspellings of "refractor" or "refactory") its very rare appearances are associated with "finding the factors of factors

45 = (9)(5) = (3)(3)(5)
since the factor 9 was not prime it was necessary to refactor it.—(source)

However this does not seem to be related to the current meaning in computer science. For that you should look to its meaning in iterative processes. Particularly in the matrix form of Newton's method.

In this method, a matrix is calculated and at each step of the method a new matrix needs to be calculated. If the partial derivatives are known exactly then this is quick, but if the partial derivatives have be evaluated numerically, then finding the iteration matrix takes a long time. The process of finding a new iteration matrix was called "refactoring the matrix", and various computer science texts discuss how this slow refactoring can be avoided, or discuss the consequences of not refactoring the iteration matrix

from what I understand in your method, you don't refactor the stiffness matrix and in the modified Newton Raphson method you have to refactor the stiffness matrix every once in awhile. —(source)

The meaning of "improve code" was linked to the object-oriented programming movement, and early books on Smalltalk discuss programming as being an "iteration" of design-write-test-refactor

As with every facet of object-oriented application development, several iterations are required until we find the optimum distribution design. [...] Because designs tend to change during the implementation, it is necessary to refactor and optimize after the infrastructure is complete. —(source)

It is reasonable to suppose the word was coined from Latin roots (factor = make) to describe the process of building a new iteration matrix, and then was adopted for an iterative approach to writing code.

| improve this answer | |
  • 9
    Whilst I don't disagree on the Latin root, I would say it is via factor in the sense of 'component part'. Simplifying by identifying common elements is a standard action in refactoring, and has clear parallels to elementary algebra. – richardb Dec 15 '17 at 19:39
  • 3
    @Richardb This is not a site to discuss abstract algebra, but I would be prepared to argue that " factor" in algebra has a more general sense than you ascribe to it. It makes sense to say that the prime factors of an integer are in a meaningful sense that integer's component parts, but any rational or real number has an infinite number of rational or real factors. Sorry if that seems to be nitpicking, but I do not think it is sound mathematics to say that "factor" on its own denotes the idea of component part. It denotes a "divisor." – Jeff Morrow Dec 15 '17 at 19:51
  • 3
    I'd argue that the (9) -> (3)(3) bit is pretty like refactoring in computer science -- generally, you're splitting things up (or at least moving them around) to make things simpler, clearer, and easy to read. – Fund Monica's Lawsuit Dec 15 '17 at 22:10
  • 1
    Read the chapter Factoring in Brodie's Thinking Forth (1984). Factoring is just that, with a "re-" to denote change to an existing program. The thread of "decomposition into parts" (as in prime factorization or factoring a polynomial) is paramount -- factoring is defined as finding a useful subpart of something and extracting it. Refactoring the Jacobian in Newton's method is just an instance of matrix factorization, aka matrix decomposition; it isn't a special usage and in any case isn't especially applicable to programming. – hobbs Dec 16 '17 at 1:54
  • 4
    In the 1999 book Refactoring: Improving the Design of Existing Code, the authors explicitly use the high school algebra sense of the word "refactoring" as an inspiration for the programming sense of the word "refactoring". – Jasper Dec 16 '17 at 5:34
5

Forth programmers used the word factoring meaning "turning common functionality into a function" - for example in "Thinking Forth" book, first published in 1984. This could be created as an analogy to algebraic "factoring out" expressions, as in 2*4 + 3*4 = (2+3) * 4.

| improve this answer | |
  • Oops, I see that Thinking Forth was in fact already mentioned. It's hard to prove a connection between this and later usage, but everyone is pretty sure it exists. The terminology was just bubbling under the surface for most of the 1980s. – hobbs Dec 16 '17 at 2:10
3

The closest we can get to a definitive answer is the rather indefinite note on the matter by Martin Fowler, who had access to the first people to use the term in this way:

When I asked around the creators of refactoring, the common answer was that they had no idea. The term had been around for a while and they don't know where it came from.

The one definite answer I got was from Bill Opdyke, who did the first thesis on refactoring. He remembered a conversation during a walk with Ralph Johnson. They were discussing the notion of Software Factory, which was then in vogue. They surmised that since software development was more like design than like manufacturing, it would be better to call it a Software Refactory. Refactory has gone on to be the name for the consulting organization that Ralph and his colleagues use.

The foundations of what we refer to these days as refactoring comes from the Smalltalk communities. However the metaphor of factoring a program was also part of the Forth community. Bill Wake dug out the first known printed mention of the word "refactoring" in a Thinking Forth, a 1984 book by Leo Brodie. We're pretty sure that this usage didn't pass from the Forth community to the Smalltalk community, but developed independently.

"EtymologyOfRefactoring", Martin Fowler

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.