How to make the best out of GenAI tools

Your architecture needs to be extremely clean to move fast with generative AI coding tools.

They have limited context windows, so if you want them to implement a simple API change that requires manipulating 10 functions spread over 5 files, it will keel over.

That’s why you can ask Claud for any kind of app that fits within 300 lines of code, and it just gives it to you.

And it works, often on the first try. It feels like magic.

Yet, when you start to expand by adding extra features that you need to make it useful, the code complexity starts to increase.

File sizes grow, you refactor into more components, and even though it’s now spread over many files, if you haven’t taken into consideration how to structure your app efficiently, it does not help.

The AI will struggle to make any sensible progress. It may even stall by fixing something, but it may introduce more bugs while rewritinge.

My approach is two-fold. I have it think about the architecture first, the design, the components, the folder structures.

Low cupling, high cohesion. Event-driven approaches work better. You want to isolate different parts of the system into small self-contained modules.

If you are generating frontend code for example, keep the HTML, CSS and JS in one file as a component of the larger app. Have events trigger updates.

That way, when you want to change that functionality, it needs to fix 1 file.

Another approach that can help is to add .md files in a /docs folder. I write out the goal, the main features and their behavior, and the application’s architecture.

This is useful so that I can include documentation as a file for my prompt.

I also like to create another file I call “current_task.md,” where I give it instructions. If the AI derails and goes off-track, I can just tell it to refocus on @curret_task.

Sometimes, though, it completely grinds to a halt, despite all these efforts.

It’s funny how it can throw out a fully functioning application with one prompt but then struggle to change a simple API endpoint without breaking something.

I tried powering through by trying different prompts, but the formula that has yielded the best success has been to give it two tries and then manually debug it to give it more context.

In a complex context, the step-through debugger is still your best friend and a tool the AI can’t yet use.

The monkeys still have a few months left.

Yours,

Taj

All writing