Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

One trick I've found that works well is to tell it to refactor, e.g for Python:

    Refactor the Python code to make it more Pythonic, e.g. fewer classes/singletons, especially if it will provide a speedup. The Python code **MUST** follow code organization standards expected of popular open-source Python packages code without causing any benchmark performance regressions.
A variant I've used for Rust code:

    The Rust codebase in `/src` has become bloated with several files >1k LoC. Refactor the Rust codebase to fit code organization standards expected of popular open-source Rust code without causing any benchmark performance regressions.
Those types of prompts appear to a) reorganize the code logically and b) do seem to get better performance from the agents because the file names now provide semantic hints to where relevant code resides. For bloated 5k LoC files, the agent has to Read several chunks to find relevant code which is inefficient.

In terms of benchmark performance it generally improves after the refactor which I suspect is coincidental (especially in Rust where it shouldn't matter due to compiling) but I'm not complaining.



Exactly. Simply asking agentic coding tools to clean up code bases, to do some targeted refactorings, to enforce things like SOLID principles, and other good practices can result in a lot of easy improvements.

I've noticed a thing where by default, agentic coding tools are reluctant to remove code. Even when you tell them to. It will bend over backwards to keep old code around, to add complexity for allowing that code to still be called, etc. Super annoying if you are basically just prototyping. You basically end up with a lot of dead code, which than confuses things when you try to add to it. But once you know this, you can just ask it to get rid of the legacy stuff.

Keeping the code base clean, actually stimulates AIs to do the right thing. If there are lots of tests, it will add more when creating new functionality. If there's documentation, it will update that without needing to be prompted as well.

As code harnesses improve, a lot of this is probably being built in as well. Which means even less experienced prompters can get decent results.


Asking it to apply the YAGNI principle also sems to work well for trimming codebases down. Generally ask it to review, generate a list of review points, then we go through each one together and I make a decision yes/no on each one (or suggest further modifications).


I can totally see doing this incrementally, but this seems extremely risky to do for the entire codebase in one shot on anything in production. Especially if you don’t have really thoughtful e2e tests of the whole system.


The AGENTS.md also orders the agents to create relevant tests with each added code, so the tests are already present to catch regressions. The benchmarks themselves also serve as de facto tests since they'll typically break if the refactor is done incorrectly.


I just say "refactor the codebase" and that also works pretty good!

I have my code styling rules in my CLAUDE.md already anyway


> I have my code styling rules in my CLAUDE.md already anyway

Well... that is quite different than just saying "refactor the codebase".


the word your looking for is idiomatic


Yes and Pythonic is the Pythonic word for idiomatic


Pythonic is a specific type of idiomatic; it never hurts to be overly specific with modern agents.

Also, as evident from the different tones in these two prompts, my prompts are often freeform.


The word you are looking for is "you're".

(Can we not play language police? It's boring and doesn't lead to interesting discussion.)


I think in this context it is actually important to share exact wording that causes the AI to perform well. My favorite is "Do not use your own knowledge."


That's positively incoherent. You can't even interpret an instruction without relying on prior knowledge. Not to mention LLM's are in essence made of knowledge.


No, it's a specific direction to look information up in docs or online rather than relying on model training.


It works though.


yeah, me too. I usually ask it to do a code review using SOLID standards and it usually does a good job, if not a little overkill sometimes.


Have you tried telling it:

“Write perfect code, make no mistakes”

I use this one in my Ralph Harness all the time, it’s a classic!

It’s not that it can’t do that, it’s just that you haven’t told it to!


That's not what this is. Refactors are necessary because LLMs tend to bloat even with controls against it, but it's ok to make mistakes if they can be easily fixed.


So wait you’ve told it not to make any mistakes or you haven’t? Seems like you’re missing this one easy trick!

It’s not about making mistakes, it’s about telling it not to make mistakes!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: