Skip to content

Comment on Vibe Coding Is Fun–But Vibe Refactoring Pays the Bills

Comments

mg

Refactoring is indeed one of the areas where LLMs already shine bright. And I love it.

I have been coding since I am 12 years old. I always loved writing code. But I also always loved reading code. I don't know, for me code is a kind of art. Never met anyone else who sees it like this. When a friend was hiring for his startup a while ago, I was happy to sit down for multiple hours and read all the code the applicants wrote and gave him advice on whom to hire.

So for me, the new times are paradise. I try to not touch code directly anymore. I write prompts that would enable a really good developer to implement features and then let various LLMs work on it. Afterward, I rate the results so I have an overall score for each LLM. I pick the best solution for my codebase and manually finetune it to perfection.

After each commit, I also ask the LLMs if they can find anything in the files that can be refactored to make the code shorter or more logical. The result is that the codebase becomes better and better. Because the LLMs often find stuff to improve. They usually come up with 10 ideas I dislike, but also one idea that I like. And so the codebase becomes better and better over time. Instead of worse and worse like in the past when you had to keep a balance of refactoring for the sake of beautiful code and building new features. Nowadays, refactoring becomes more and more free.

I also ask the LLMs if they can find anything in the files that can be refactored to make the code shorter or more logical

Citation needed? The worst kind of code tends to be clever code. This seems like a lot of code churn for no real benefit other than some loose definition of "better". How do you prevent bugs with these constant refactors?

You have to read the suggestions and evaluate them using your skills and experience and then decide to accept / deny / adjust the proposed changes. There is not silver bullet but the speed you can iterate and experiment is impressive

Man, I must really suck at this stuff. This is not at all my experience. Asking LLMs to refactor almost always results in hasty abstractions that I want to keep out of my codebases at all cost. Am I not letting go enough?

FWIW this is my experience too. I use LLMs pretty regularly for coding but to get decent code you really have to supervise the hell out of them and often it's not worth the effort to push them into doing the right thing.

Maybe I'm just bad at getting it to do things, but I think your question about "letting go" is the real story. I think there are a lot of people not paying close enough attention to what's coming out of the LLM, and the tech debt building up is going to come back to bite them when it builds to a point the LLM can no longer make progress and they have to untangle the mess.

mg

The way I "ask" is that I really ... ask!

I ask the LLM "Can you find anything in this file(s) that can be made shorter or more logical?"

And then as I said, I like less than 10% of the ideas the LLM comes up with. But it is so fast to read through 10 ideas (A minute or so) that it is well worth it.

I really, really don't understand this either. Sometimes I feel like I must be using different LLMs than some HNers because my experience of them is the complete opposite of what they describe.

mg

Which LLMs have you tried?

Not who your replying too, but since I've expressed similar sentiment:

Sonnet 3.7 with thinking is my go-to.

Deepseek R1

Gemini 2.5 pro (I've heard it said Gemini is outperforming Sonnet, but I find Sonnet more consistent)

O1-mini

Depending on what I'm doing it's generally either via Cody or Aider.

As the author of this article/video - it's really strange for me that almost everyone here in these threads has focused on the LLM part of refactoring, where it's only mentioned as one of many tools for target-less flow state of the code tweaking sessions. :-)

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.