β€’

tech

What makes AI write great code

Another experiment with AI this week, and this time it went extremely well. I ported Bevy (game engine) to TypeScript, with the patterns and type safety of effect. All AI. This is why it went so well.


Sandro Maglione

Sandro Maglione

Software

My Odyssey into AI experiments continues, welcome to a new episode this week πŸ‘‹

The theme of this week is:

Let AI write as much as possible, manual code should rarely become necessary, or you are doing something wrong πŸ™Œ

Let's see how did I get here πŸ‘‡


Recap of the past episodes

I have been going left/right, up/down, all the way on one side and then the other with AI.

Like this, more or less:

  • Full "Orchestration" with AI (here)
  • AI and slop creep-in (here)
  • AI faster than you (here)

I went the extremes: projects with all AI, projects with some manual clean ups, projects mostly manual with AI suggestions.

In any case, one fact is certain:

AI write and reads code faster that you ever will πŸ’πŸΌβ€β™‚οΈ

And in fact, most times, with the right prompt and bounds, AI writes even better than you would (it has more context after all, reading all that code).

Quality In, Quality Out

All the way to today, with another hypothesis and another experiment:

If AI can read and write faster, if it has the right sources to reference, it can copy/adapt them and come up with something that works, no matter how hard the task πŸ€”

I picked a bounded task for this: ECS (Entity Component System).

If you've been following the newsletter for a while, this has been a recurring topic a while ago (here) πŸ‘ˆ

The experiment went as follows:

  • Bevy is a Rust game engine that implements an interesting ECS model
  • Effect (v4) has great internal TypeScript library code

Two great sources to "copy", in two adjacent domains.

Let's see how AI ports the core of Bevy in an Effect-inspired TypeScript library πŸͺ„

AI joins your team, but you are the coach

I had 3 powerful players in my team:

  1. Fast AI
  2. Concepts and ideas from Bevy
  3. Structure and type safety of Effect

Alone, those will not work well. You, the expert developer, are the coach that puts together a winning team πŸ—οΈ

I cloned both the Bevy and Effect repository locally, and started prompting AI for the porting.

I have enough familiarity with the internals of effect and the concepts of Bevy and ECS to understand the domain, and have a strong debate with AI 🀝

And, well, it went really well πŸ‘‡

bevy-ts

Don't prompt less, prompt better

My new main takeaway from this:

AI writes fast, and it can write well.

You job is to ensure AI has all it needs to write well πŸ™Œ

You should do whatever you can to increase your confidence in AI-authored code.

In this week experiment, the AI had a clear goal (by inspecting how Bevy does it) and a clear example of great implementation (Effect internals).

My "expertise" on top then helped to define bounded tasks and steer important product/API decisions. As well as making sure strict roadblocks are in place, and correct (testing).

You are the manager of AI: make sure it has everything it needs to do great work 🫑


Same statement as last week: you still need engineering expertise to use coding AI

The magic is in the details, and you steering AI in the right direction, and keeping it on track πŸ’πŸΌβ€β™‚οΈ

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