β€’

tech

Walking your code with AI

AI is establishing solid roots in the workflow of every software developer. I am experimenting ways to write faster code with AI, without compromises on quality. Here is how.


Sandro Maglione

Sandro Maglione

Software

AI is becoming a valuable companion for software developers 🀝

But, for now, no more than that πŸ™Œ

I am playing around with various workflows, a few work, others don't πŸ‘‡


Suggestions and autocomplete

My first and most common use of "AI" is still smart autocomplete.

Often times by intention is clear, it's mostly about the verbosity of writing the code.

The AI catches that most of the times β˜‘οΈ

I got in the habit of writing a few characters, and "Tab" my way to completion, letting AI do the rest.

Safe and not-intrusive, saving a few seconds every few lines. Those compound to a huge time saving over a few hours coding session.

This works better when the codebase is already established, and the AI can just pick up common patterns.

Standard, but unknown

Sometimes you know some Web API or standard function exists, but you forgot how it's called or how to use it (e.g. Date, Intl, navigator) πŸ€·πŸΌβ€β™‚οΈ

That's another ideal scenario for AI!

The API is so standard, that AI knows everything about it. So you don't have to πŸ’πŸΌβ€β™‚οΈ

These are all queries like "format this date" or "implement a function to copy this text". Most of the times, you don't even need a web search or docs anymore πŸ™Œ

Brainstorming and design

AI works great also as a peer developer: not writing code, but discussing patterns and best practices.

Recent example: relational database schema structure.

Often times a single query is not enough to express your full intent.

You may not know exactly what you are looking for πŸ’πŸΌβ€β™‚οΈ

My process:

  1. Give AI an overview of the data model and how it should work (not how to implement it)
  2. The AI comes back with an initial proposal
  3. You (as an expert) understand the proposal and refine it based on requirements

A few back-and-forth later, nailing down all edge cases, until you get to a final design.

Once all the details are "in memory", you can be more confident in "letting" AI write the implementation (in this case output a .sql file).

Not full AI (yet?)

I recently tried spec-kit.

[...] focus on product scenarios rather than writing undifferentiated code with the help of Spec-Driven Development.

The idea: use AI to write the spec (in as many details as possible/necessary), and then let the AI loose to write the code.

spec-kit comes with a few markdown "agents" used to guide you (and the AI) to a full spec.

It went all great, until the last step: the implementation 🫠

I had my specs, many details about the tech stack and a monorepo already in place. The AI started coding, still not too bad.

But then I encountered the real blocker: modifying AI code 🀯

The AI cannot nail every single detail, regardless of how detailed are the spec.

When you will need to update some code, that's where the real pain begins 🀦

I noticed a few issues, usually quick fixes. But then I found myself having to read nearly all the code the AI generated to understand the implementation and make a change.

AI makes initial iterations fast, at the cost of more bugs and time in later stages.

Just like a legacy/outdated codebase 🀦

I ended up removing everything (specs and code) and start back again with another approach πŸ‘‡

Provide example guides for AI

New attempt: instead of having AI write all from scratch, I write myself the first "core" examples and patterns.

This time I wrote manually the initial code (a few data models, a quick UI, and a state machine). This acts as a "guide" for the AI.

I then asked AI to "use" the code already written to implement a similar feature.

It worked. The AI picked up the core patterns without issues.

This is my current workflow: write the "right" code, before letting AI writing "the rest".


Not sure about "x10" your productivity with AI, but the speed boost is definitely there.

And it's trending upward, as new features and patterns are discovered and implemented.

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