You have asked me to send an account of the miraculous occurrence known as The Refactoring. In answer to your inquiry, I have consulted both our Git commit messages and actually spoken with living witnesses to this miracle of miracles. Here is a true account of what happened in The Refactoring!
Yea, verily, in the beginning, there was the Code and the Code worked and the Company prospered mightily.
Then, the Refactorers inspected the Code and pronounced judgment: the Code was !@#$%
The Refactorers sent a deputation to interrogate the Cowboy Coder who had written the Code. He asked if Kent Beck was a kind of beer. When shown a copy of the Holy Text Refactoring by the Prophet Martin Fowler, the Cowboy Coder leafed curiously through the Holy Book and started laughing. At once they seized this Heretic and Blasphemer and dragged him to the front door.
He began to shout “Wait! Wait! You don’t understand what I am doing! I am deferring complex expensive work with little revenue producing value so that we can get revenues now!” And the ultimate blasphemy, the recourse of all sinners: “But the Code works!”.
I cannot repeat all the lies and calumnies this serpent among men then repeated to the assembled Refactorers. The Refactorers prayed and chanted: “There is but One Way to Code and it is Our Way! Begone sinner!”
The Refactorers plugged their ears against the Cowboy Coder’s lies and began to stone him and drove him into the wilderness never to be seen again.
As the Cowboy Coder fled, he cried out: “Lord forgive them for they know not what they do!”
The Code consisted of Modules Alpha, Beta, Gamma, Delta, and Omega.
The Chief Refactorer shouted forth: “There is duplicated code in the modules! Sin! Sin! Sin! All duplicated code should be in a single module. The single module will make the code scalable and maintainable.”
The Refactorers worked mightily for forty days and forty nights to refactor the Code into Modules Alpha, Beta, Gamma, Delta, and Omega … and Epsilon, which contained the duplicated code. Alpha, Beta, Gamma, Delta, and Omega, each one, called Epsilon.
And the Code did not work and the Company suffered mightily.
And the Refactorers shouted: “It is all the Cowboy Coder who wrote the original Code’s fault! He did not write scalable, maintainable Code. All he cared about — sin of sins — was that it worked!”
And the Code still did not work and the Company suffered mightily.
And then, Theo, that viper the Vice President of Sales plotted against the Refactorers and went to the CEO and whispered: “Perhaps we should send a deputation of our most silver tongued sales and marketing executives into the wilderness with chests of incense and myrrh and fine gold to find the Cowboy Coder, apologize, and ask him on bended knee to please return and fix the Code.”
And the CEO was outraged and shouted forth: “I will not reward incompetence! Never!”
And the Vice President of Sales was seized and dragged to the front door and stoned and cast out into the wilderness — never to be seen again.
And the Code still did not work and sales plummeted even more without that silver tongued viper among men the Vice President of Sales.
The Refactorers worked mightily for another forty days and forty nights, cleaning and fixing the Code in Modules Alpha, Beta, Gamma, Delta, and Omega … and Epsilon.
And the Code worked poorly and the Company suffered and the Refactorers received raises and promotions.
The Refactorers worked mightily for another forty days and forty nights, cleaning and fixing the Code in Modules Alpha, Beta, Gamma, Delta, and Omega … and Epsilon and Epsilon Prime (They had to refactor Epsilon as it grew too large for the Coding Style Standard).
The Fifty-eighth Commandment of Good Coding: Thou shalt not have a Module with more than 200 Lines of Code.
And the Code worked OK and the Company was profitable once more and the Refactorers received raises and promotions.
And then Theo, the CEO spake: “The Alpha module can’t handle widgets. I want it to handle widgets!” And the CEO wept and tore his clothes.
The Refactorers bowed down before the CEO and answered: “Fear not, the Code will handle widgets.”
The Refactorers worked mightily for another forty days and forty nights, modifying the shared code in Module Epsilon … Prime to handle widgets.
And then the Code could handle widgets but stopped handling wadgets (Module Beta), worrels (Module Gamma), ickbats (Module Delta), and lothbigs (Module Omega). That sinner, the Cowboy Coder had deferred implementing handling all the special, mutually contradictory peculiarities of wadgets, worrels, ickbats and lothbigs in order to — sin of sins — get things working fast! Through his sloth and haste, the Cowboy Coder had created the false impression that code could be shared in the handling of widgets, wadgets, worrels, ickbats, and lothbigs!
And then Theo, the CEO spake again: “What the !@#$%^!” And the CEO wept and scourged himself!
The Refactorers bowed down again before the CEO and answered: “Fear not, the Code will handle widgets, and wadgets and worrels and ickbats and lothbigs!”
The Refactorers worked mightily for another forty days and forty nights, refactoring Module Epsilon into Modules Epsilon-Widget called by Alpha, Epsilon-Wadget called by Beta, Epsilon-Worrel called by Gamma, Epsilon-Ickbat called by Delta, and Epsilon-Lothbig called by Omega, which in turn called Epsilon-Prime (well all but Epsilon-Lothbig which called Epsilon Double-Prime due to an obscure peculiarity of lothbigs not shared by widgets, wadgets, worrels, or ickbats).
And Theo, once again, the Code worked (sort of) and the Company struggled to survive, barely turning a profit.
And the Refactorers said: “It is all the Cowboy Coder’s fault! Look how hard it was to modify and extend his code! Sinner! Sinner! Sinner!”
And Theo, here is the miracle, the CEO believed and showered the Refactorers with more raises and promotions.
© 2014 John F. McGowan
About the Author
John F. McGowan, Ph.D. solves problems using mathematics and mathematical software, including developing video compression and speech recognition technologies. He has extensive experience developing software in C, C++, Visual Basic, Mathematica, MATLAB, and many other programming languages. He is probably best known for his AVI Overview, an Internet FAQ (Frequently Asked Questions) on the Microsoft AVI (Audio Video Interleave) file format. He has worked as a contractor at NASA Ames Research Center involved in the research and development of image and video processing algorithms and technology. He has published articles on the origin and evolution of life, the exploration of Mars (anticipating the discovery of methane on Mars), and cheap access to space. He has a Ph.D. in physics from the University of Illinois at Urbana-Champaign and a B.S. in physics from the California Institute of Technology (Caltech). He can be reached at [email protected].
The problem is that, more than a refactor it was a re-doing.
Refactoring can be as simple as changing a variable name. It should be done in baby steps. And it must always keep the code working.
If the code is not functionally the same, it is not a refactor.
The problem is that, more than a refactoring, it was an undoing.
Undue undoing happens when dogma guides action instead of thought. It also happens when professional code spinners fail to recognize that for some, code is NOT the art but MERELY the canvas on which the art is practiced.
When they drove the Cowboy Coder out into the wilderness (where he is now very happily, thank you, herding still more complex mathamagic into spartan code structures THAT WORK) they parted with their only understanding of what the code was for.