Workflows with AI-DD

Alberto BasaloAlberto Basalo
7 min read

If you are a developer and are considering incorporating AI into your workflow, you may have heard both promises and warnings. It's easy to get excited about the idea of an AI that writes code for you, but it's also important to have your feet on the ground and understand its limitations, which also become apparent when you scratch a little under the surface...

In this article, I will explain how you can integrate AI-DD (AI-Driven Development) into your daily routine, with a practical and realistic approach.

โœจ Expectations and Disappointments

Most developers experience a common cycle when starting with AI:

  1. Initial excitement ๐ŸŽ‰: "This is magic! It will write code for me"
  2. Early disappointment ๐Ÿ˜•: "It doesn't understand what I want, it generates errors"
  3. Frustrating rejection ๐Ÿ˜ค: "It's a waste of time, I'd better do it myself"
  4. Realistic acceptance ๐ŸŽฏ: "I understand what it's for and what it's not for"

When you start using AI, it's tempting to think that it will solve all your development problems. After all, it can generate code, solve errors, and optimize processes. However, it's not a magic being that understands everything you ask it to do perfectly. The key is to manage your expectations well: the AI is not going to replace your logic or your ability to analyze problems, but it can be an excellent help if you know how to use it.

One of the biggest surprises for developers is discovering that AI is non-deterministic. Unlike a compiler or a code formatter, which always produce the same output for a given input, LLMs can generate different responses each time. Even with the same prompt, the same model, and the same configuration, you will get variations in the generated code.

The key is to understand that the AI is not a replacement for the programmer, but a tool for amplification. As such, we need to learn how to use it correctly and establish a workflow that allows us to take advantage of its capabilities.

๐ŸŽฏ 1. Ask well

The first skill you need to develop is asking good questions. In this context, ask means request or even command. Communicating clearly what you need is essential to work effectively with AI. It's not enough to just say "write a program that does X", you need to give a broad and specific message at the same time. This implies mastering three levels of interaction:

๐Ÿ”ง System Prompts

Some AI tools allow you to configure system prompts, which are like the initial instructions that guide their behavior. For example:

You are a senior developer specializing in Angular and Node.js.
You follow SOLID principles and write unit tests.
You prefer simple, maintainable solutions.

I leave you a reminder of my article on System Prompts, based on the รรฑigo Montoya methodology

๐Ÿ“ Prompt Engineering

Here is where the true art? engineering? comes in. Part of the success of current AI interactions is the use of natural language. Which, by definition, is not formal and structured like the languages we use regularly to program. This is the difficulty of the matter: the more precise and formal you are when formulating your prompts, the better the responses you will get and the more chances you will have to reuse them. And all in your native language. In the absence of that prompt language, here are some practical tips for structuring your questions:

  • Be specific and detailed
  • Divide complex problems into parts
  • Provide examples of the expected result
  • Establish constraints and preferences

I will dedicate a complete article to this topic in the future. Subscribe or follow me on social media to not miss the launch.

๐Ÿงฌ Prompt as Code

An interesting idea is to treat prompts as code, versioning and refining them. This allows you to reuse them and adjust them according to the needs of the project. If you work in a team, you can also share these prompts as part of the code documentation. This is part of what you can do with your prompts:

  • Write them structurally in Markdown, and add JSON or XML if the LLM supports it
  • Version them in the git repository associated with a code change
  • Share them with the team or even open source

Some tools already facilitate this process. But if not, you always have the manual option of saving them in files.

๐Ÿงฉ 2. Add relevant context

The AI, no matter how advanced it is, cannot read your mind or know all the details of your project unless you provide it with relevant context. So the next step is providing relevant context.

๐Ÿ“‹ Functional Requirements

Before asking the AI to write code, make sure you have clear requirements:

  • Clearly define what the code should do
  • Menciona restricciones y quรฉ no debe hacer
  • Even better, provide use cases and examples
  • Obviously indicate if it's for a web app, mobile, cli, server...
  • And the tech stack you will use

I will dedicate some posts to this topic to formalize this process.

๐Ÿ“ Coding Rules

If you work in a team with strict coding rules, make sure the AI follows them. You can directly tell it those rules or guide it with examples of well-formatted code.

  • Communicate the preferred coding style (clean code, functional, etc)
  • Define naming and style conventions
  • Specify patterns and architectures to follow
  • Even better, provide examples of well-formatted code

Some editors allow you to define coding rules per project. Which is a good practice.

๐Ÿ“š Documentation of Libraries

If your project uses external libraries, it's useful to provide documentation or examples of how they should be integrated. The AI may not always get all the details right, but if you give it additional information, it can generate code more tailored to your needs.

  • Mention specific versions of frameworks
  • Show preferences for libraries
  • Share existing code snippets relevant to integration
  • Provide integration documentation

As I said, maybe the editor or plugin supports enriching the documentation.

๐Ÿ”„ 3. Evaluate and repeat

Working with AI is an iterative process. The first attempt is rarely perfect, so you need to evaluate, adjust, and repeat until the result is what you expected.

As Reagan said: "Trust, but verify!"

๐Ÿ” Continuous Improvement Process

Each time the AI gives you a result, review it carefully. Does it meet the requirements? Does it follow the coding rules? Is it efficient? If the answer is "no" in any of these points, adjust the prompt and try again. This cycle of generation, evaluation, and adjustment is key to getting the best out of AI.

  1. Generate a first version
  2. Evaluate the result
  3. Refine the prompt or add context
  4. Regenerate and compare

๐ŸŽฒ AI is not deterministic

An interesting aspect (and stressful) is that due to its probabilistic nature, the AI does not always generate the same code for the same prompt. This has its advantages and disadvantages:

  • Each response will be slightly different
  • You can exploit this variability to explore alternatives
  • It's important to review the code before using it
  • Combines the best parts of different responses
  • Use git to manage versions and go back or mix responses

โฑ๏ธ Chat Session Pomodoro Commit

Well, I don't know how to call the interaction cycle with the bot. A trick that can help you work better with AI is to use chat sessions like "pomodoro". This means working in focused time intervals, using the AI to generate code or solve problems during a short period and then making a commit of what you have achieved. This ensures you maintain a constant pace and integrate the generated code in an orderly manner.

  1. Establish focused work sessions
  2. Keep the context in a single conversation
  3. When you achieve something useful, save it and commit it
  4. Integrate the generated code in an orderly manner

The idea is older than the wheel. Divide the problem into parts and work in short intervals. Save and document each advance

๐Ÿ“ฆ Conclusiones

AI is not the magic solution that will do everything for you, but if you know how to integrate it correctly into your workflow, it can save you time and improve the quality of your code. The key is:

  • Ask clearly and structurally
  • Proporcionar contexto relevante
  • Iterar y refinar las respuestas

With an appropriate approach, AI-DD can be one of the most powerful tools to maximize the benefits of AI while minimizing the frustrations associated with its inherent limitations.

Powerful tools + structured methodology =

Code smarter, not harder. ๐Ÿš€

0
Subscribe to my newsletter

Read articles from Alberto Basalo directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Alberto Basalo
Alberto Basalo

I am a full-stack developer with over 25 years of experience. I can help you with: Angular and Nest architecture. Testing with Cypress. Cleaning your code. AI Drive Development.