Lurker News
I've been working on a personal project recently, rewriting an old jQuery + Django project into SvelteKit. The main work is translating the UI templates into idiomatic SvelteKit while maintaining the original styling. This includes things like using semantic HTML instead of div-spamming, not wrapping divs in divs in divs, and replacing bootstrap with minimal tailwind. It also includes some logic refactors, to maintain the original functionality but rewritten to avoid years of code debt. Things like replacing templates using boolean flags for multiple views with composable Svelte components.

I've had a fairly steady process for doing this: look at each route defined in Django, build out my `+page.server.ts`, and then split each major section of the page into a Svelte component with a matching Storybook story. It takes a lot of time to do this, since I have to ensure I'm not just copying the template but rather recreating it in a more idiomatic style.
This kind of work seems like a great use case for AI assisted programming, but I've failed to use it effectively. At most, I can only get Claude Code to recreate some slightly less spaghetti code in Svelte. Simple prompting just isn't able to get AI's code quality within 90% of what I'd write by hand. Ideally, AI could get it's code to something I could review manually in 15-20 minutes, which would massively speed up the time spent on this project (right now it takes me 1-2 hours to properly translate a route).
Do you guys have tips or suggestions on how to improve my efficiency and code quality with AI?

Comments (469) 111 threads

Earlier comments
dboreham#
1. Introduce it to the code base (tell it: we're going to work on this project, project does X is written in language Y). Ask it to look at the project to familiarize.

2. Tell it you want to refactor the code to achieve goal Z. Tell it to take a look and tell you how it will approach this. Consider showing it one example refactor you've already done (before and after).
3. Ask it to refactor one thing (only) and let you look at what it did.
4. Course correct if it didn't do the right thing.
5 Repeat.

skeptrune1 reply#
You should make sure that your queries to the agent contain a "loop condition"[1]. This can be something like "keep trying until yarn test passes".

Always remember that these agents are just LLMs running tools in a loop and treat them as such.
[1] https://www.skeptrune.com/posts/prompting-the-agent-loop/

verdverm#
if they aren't already, they will be multi-agent / llm systems, more and llm being asked to loop

for example, in ADK you can set up a sequential agent with [planner, loop(coder, validator), finalizer] with the inner loop, such that another agent is the one checking and deciding if the task is complete or not, but we are also creating higher level enforced constructs of seq and loop
Getting reliability in this high-level process is helpful

rokoss21#
The key insight most people miss: AI isn't a code generator, it's a thinking partner. Start by defining the problem precisely in plain English before asking it to code. Use it for refactoring and explaining existing code rather than generating from scratch. That's where you get the 10x gains.

Also, treat bad AI suggestions as learning opportunities - understand why the code is wrong and what it misunderstood about your requirements.

seanmcdirmid#
If you are working on something big, have AI generate intermediate artifacts before it generates code, and feed those artifacts into the code generation prompt. Then you check those artifacts, see where the AI is going with the code, and suggest corrections before a token of code is even generated. Keep those artifacts around like you would documentation, having your AI fix them when the code needs to change.

Load more comments