Posted on Jan 1, 1

title: Saving a codebase from the next LLM disaster

I am building a prototype that I have largely written with LLMs. I barely looked at the code being generated and only at times. Now before making it something anywhere more serious, I want to refactor it. A refactor is also a way to make sure I understand the codebase and that I have a good sense of the risks that may or may not arise from running generated code that wasn’t carefully expected. A refactor is now for me a code review in which I spend a lot more time. But this LLM coded like a savage. Basically all the code is in a single file and the file is huge. It has no modularization, no tests, no logical division that makes sense. To be fair, I didn’t ask to do any of that, I just wanted to prove an idea and prove it quick and that was achieved. But the code like this can go nowhere, it’s a minefield. I have to save this codebase from the LLM.

Bad stuff everywhere

Maybe I should have taken a deeper look at the code before, but I was really focused on getting the propotype done. Anyway, what is done is done. What am I dealing with?

  • a huge file.
  • lots of global variables, which means refactoring is pain.

I’m now hugging a photo of Martin Fowler and moving things around in packages, make it compile, removing the global variables, repeat.