Defactoring, factoring, prefactoring, and refactoring!

(just kidding...still factoring.  always factoring.)


In software, "refactoring" means changing the design or structure of code in order to make some improvement (speed, memory, flexibility, etc) but not change the functionality.  Keeping the same "what it does" but improving (hopefully) the "how it does it."


Leaving aside the meanings of "factoring" which involve mathematics (finding the factors of prime numbers, for instance), we can also say that "factoring" (without the "re-") means the initial designing of the code.  It's first complete implementation.


And, continuing to play with the words, "defactoring" might mean several things.  A quick Google search finds that "defactoring" is not as commonly used as "refactoring".  Which makes sense.  The plainest meaning should mean something like "taking away design or structure".  Why would you want to do that to your code?


Well, with that question in mind, let's consider the process of working on someone else's code.  It's older stuff, what is called "legacy".  Its design is unfamiliar; its functions and methods are primitive or clumsy or just not how you would go about the solution.  You think you can do better.  Or with fewer lines of code.  Or both!


How about the word "prefactoring"?  What might that mean?  Another quick Googling indicates it's used more often that "defactoring" but less often than "refactoring".  And it's got a fairly agreed-upon meaning, so bonus!  The term means "using your refactoring experience, proactively designing or factoring your planned code so that future refactoring is easier, simpler, or even unnecessary for longer."  In other words, considering the needs of the many (your future "you" plus other hypothetical future developers who are looking at your code and shaking their heads) before considering the needs of the one (your present "you").


Why am I blathering on about defactoring, factoring, prefactoring, and refactoring?  I am minded of them as I begin with my text-based roguelike* game program (nicknamed "DF").  With the recent release of Claude 3.7 (with option for extended thinking), I am going to revisit the program to see if I can complete it using the "constant conversation" model that I started with.  That is, I provide the requirements (functional, non-functional, and technical), work with the LLM to produce the initial design, and then the flowchart, and then the separation into modules, and then the flowchart for each codeblock in each module, and then the code for each codeblock.  With testing throughout the process.  I will use this go-round to see how the whole process works, working within and getting around Claude's context window, and seeing how RAG (retrieval augmented generation**).


We shall see how the conversation and code generation process go with this newer Claude.


Upshot is: Factoring, defactoring, refactoring, prefactoring, and [insert here your preferred prefix]factoring are all together a constant process, continual, continuous, and unending.  Call it what you like, it's all the same stuff.  Better coding; less breaking.





* Like a "Rogue" sort of game, but not really "Roguelike".  At least in the same universe as those.

** A.k.a., "read again, goofball".


Comments

Popular posts from this blog

Telling Rocks What To Think

WWHD?