β€’

tech

The Ultimate AI coding guide

This is the last guide you need to write great code with AI. And it's nothing impressive, but mostly a series of high-level steps that, if done correctly, guarantees success with AI coding.


Sandro Maglione

Sandro Maglione

Software

(Possibly) The last chapter of the AI odyssey 🫑

After trying all approaches with AI coding, and seeing all the pitfalls, I emerge with a definitive strategy

In practice: structure codebase, prompt well, let AI write, you read πŸ‘‡


Structure codebase

You must be always in control of how the code is structured, aka "architecture".

Libraries, folders, pattern, conventions are all up to you, and they must be enforced at all times, and early πŸ”’

This has 2 practical implications:

  1. Initially the project moves slower, you must check each file and config
  2. Guardrails and automated checks are key, and must be added early

Plus another major requirement:

You must have enough expertise to fully understand the full picture, and steer even smaller deviation and details πŸ™Œ

In fact, broader architecture and automatic checks setup may be (become) more important than the details of the code πŸ€”

Prompt well

Automatic checks in place, it's time to turn on the AI.

And prompting is also a skill that need to be acquired and honed πŸ‘€

General principles:

  • Give references to files, as many as possible
  • Manage the scope of each feature, keep it small(er)
  • Be precise in the requirements, as much as you can

Use "plan" mode, or at least make sure that AI does some research before writing code, and that you agree with the plan πŸ—οΈ

In fact, let me give you an obvious but overlooked advice:

Read the plan πŸ’πŸΌβ€β™‚οΈ

You job is not writing anymore, but it shifts a lot more into reading.

Read the plan, correct any small deviations, and add more and more context until it's all aligned. All.

Let AI write

Forget about actually writing most of the code.

With proper guardrails and an aligned plan, the AI can do a great (and faster) job 🫑

If the previous two steps are checked, just let AI run with it. In fact, don't even bother checking any work in progress.

Let AI write the full implementation until completion, don't bother with any intermediate steps πŸ’πŸΌβ€β™‚οΈ

Again, if plan and guardrails are solid, the AI tends to self-correct before notifying you when finished.

You read

Again, sounds obvious? It's not.

This is the missing link. The corner stone that may never go away.

And it's also where the quality of the previous steps shows up:

  • No architecture/check = AI added folders, bad patterns, code slop
  • Bad prompt = AI wrote something, not what you wanted, not how you wanted, or way too much

"But it takes too much to review all those changes" cit. 🀯

Long review time causes:

  • Scope too large, reset and prompt for a smaller piece
  • Architecture too scattered, too many random files and patterns
  • You don't understand the code (anymore)

The last point is key:

The moment the AI gets ahead of you in your own codebase, you won't be able to review simply because you don't understand what the app is doing πŸ™Œ


You don't write code anymore. But you are still the owner of it.

Your job shifted more into management: of architecture, of prompt and scope, and as reviewer.


The above process and principles are generic and always valid (as of today), no matter what kind of code your write.

That's why I would consider this the ultimate AI guide, and not sure how much more there is to say about this.

See you next πŸ‘‹

Start here.

Every week I dive headfirst into a topic, uncovering every hidden nook and shadow, to deliver you the most interesting insights

Not convinced? Well, let me tell you more about it