AI Is Changing The Way We Code: AI-Driven Development (AIDD)
Tags: testing, ai, chatgpt, tdd
Published: 2023-03-09 07:49:32

These days, it appears that anyone can write code. You’ve probably seen plenty of videos online of non-developers using AI to generate working scripts in no time. Code that actually seems to work! It’s like magic.

And it _is_ kind of like magic. These next-generation models like ChatGPT emerged onto the scene in 2023 and blew almost everyone’s minds; even non-technical people were amazed by all the things AI could do, coding being just one of them.

And not only that, it is getting better and smarter by the month. The pace of improvement is absolutely astounding. It seems everything is about to change.

## It's a Br-AI-ve New World

But wait… doesn’t that mean developers are about to be replaced by AI?

Surely if grandma can now divide-and-conquer a data structure using an AI-generated merge sort algorithm in O(log n) time without breaking a sweat, how could it not mean exactly that? 

Maybe it’d be smart to start looking elsewhere for work. How about gardening? Plumbing? Yoga instructor influencer? Anywhere where we might shield ourselves from this sudden AI disruption.

Well, hold on just a moment. In this new world, code can indeed be generated by AI. Great code, too. But here’s the kicker: how can we gain _confidence_ that this code will actually do what it is supposed to do, in a good way, and in an ever-changing environment? Especially within the context of a software system consisting of other AI-generated code, with which it is going to have to integrate.

How can we as developers harness and benefit from the vast intelligence of these new AI companions, while also ensuring that our customers’ complex software systems remain maintainable, scale well, and function without bugs?

That is the problem that AIDD solves. 

In this article and its accompanied video, we'll explore the eight core steps of AI-Driven Development and see how this workflow could have the potential to supercharge your life as a developer. And how it does so not by fighting against—nor surrendering—to the AI, but by joining forces with them.

## The Value Of Human Development Skills

But before we do, for the developers out there who might still be concerned about the rise of Artificial Intelligence and how it could affect their job security. What exactly are the reasons why your skills and creativity as a developer will remain crucial to the software construction process?

Here are just five of the many exciting responsibilities you can expect as a future AIDD developer. Some you will be familiar with, some are brand new.

1. Be the one who has a deep and thorough understanding of the vast space of vague human customer requirements.

2. Carefully guide the AI through the AIDD process. 

3. Create your application’s [testing pyramid](https://martinfowler.com/articles/practical-test-pyramid.html). From unit to integration to E2E tests. Yes, the AI can and will help you out here, but you are ultimately responsible for the health and maintenance of the test suite.

    ![Testing pyramid](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lord2czy40yx9fm525ov.jpg)

4. Repair and modify systems built using AIDD.

5. Use your skills as a developer to make sure the system fulfils customer requirements while also respecting the many principles of professional software construction:
 

>- Correct (_**vs buggy, crashing, doing nothing, or not executing**_)
>- Stable (_**vs brittle, or non-deterministic**_)
>- Readable (**_vs unreadable, or obfuscating_**)
>- Testable (_**vs tightly coupled**_)
>- Scalable (**_vs tightly coupled_**)
>- Extensible (**_vs tightly coupled_**)
>- Flexible (**_vs tightly coupled_**)
>- Reusable  (**_vs tightly coupled_**)
>- Cohesive (**_vs low cohesion_**)
>- Maintainable (**_vs not DRY, no 
documentation, dead code, etc_**)
>- Performant  (**_vs slow, and/or expensive_**)
>- Secure  (**_vs insecure_**)
>- Usable (**_vs frustrating user experience_**)
>- Accessible (**_vs only for privileged users_**)
>- Portable (**_vs tightly coupled to specific medium_**)
>- Consistent (**_vs paradigms or coding styles or formatting mixed together without forethought_**)
>- Minimal (**_vs over-engineered_**)

 

 
These five competencies—dealing with human customers and their ambiguous requirements, AI guidance, test suite creation/maintenance, repair/modification of AI-created systems, wisdom of high-level software principles—are just some of the reasons why you will still be valuable in the workplace as a developer. 

For the foreseeable future, it is reasonable to assume that many of these skills won’t be taken over by AI.

## So What Is AI-Driven Development?

AIDD follows the 'red, green, refactor' cycle, just like Test-Driven Development (TDD). It also employs the technique of writing tests _before_ implementation code. In a way, we can say that AIDD is like a futuristic extension of TDD.

However, unlike in traditional TDD where developers are responsible for creating both unit tests and implementation code on their own, AIDD introduces a new approach, emphasizing deep AI teamwork.


![Red, Green, Refactor Cycle](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e17bbqgrczh3o9gqp6j0.jpg)

Employing the AIDD technique, you are no longer working alone; you have a smart and patient AI ally by your side, ready to come to your _aid_ at almost every stage of development. Instead of you doing the heavy lifting, your AI companion goes to work behind the scenes while you can focus on higher-level development tasks.

## The 8 Steps of AIDD

To demo the technique, let’s first go through the steps at a general level. After that, in a video we’ll go concrete with a simple yet practical example, where we construct an isolated function to achieve some goal.

This way, you will start to get a feel for how this process works, and how it can really empower you in delivering value to your customers.

###1: Set the goal

Think about the function at an extremely high level; what are you trying to achieve? Consider it only in terms of Input→Output. 

>☝🏻 _Reflect on the function’s API, the ergonomics of actually using the function. Specifically, how many and what kind of arguments should it take? Should they be optional or not? Etc._

###2: Formulate the abstract type

Use a strongly-typed language—TypeScript, C#, Haskell—whatever you are using in your project, to manually write the type or interface for the function's input and the output. Strive always for [pure functions](https://en.m.wikipedia.org/wiki/Pure_function), unless you have absolutely no choice but to cause side effects.

>☝🏻 _If you need help in this or any other step, as always—ask the AI._

###3: Construct mock functionality

Using the function type you made, give them to the AI and ask it to construct a [mock function](https://en.m.wikipedia.org/wiki/Mock_object). This is a function without an implementation; it simply simulates a real function by faking the output.

###4: Write tests

Ask the AI to create unit tests for this yet-non-existent-function, as many as you need, based on the function type and a description of what you are trying to achieve. 

Carefully review the tests it creates. If necessary, add more manually, until you get the feeling that if these tests pass, you will actually feel _confident_ in the function’s correctness.

Here's another possible way to do step 4: write all the tests yourself, but with only one assertion for each test case. Then, you can ask the AI to generate 5, 10, 20 more similar assertions for each. 

With more assertions per unique test case, the probability of the function passing the test by sheer luck decreases.

>☝🏻 _The unit tests should be lightning fast. This is achieved by not relying on any external state or circumstance, employing techniques like the heavy use of pure functions, monads like Promise or Maybe, dependency injection, mocking, etc._

###5: Run tests and expect failure ❌

Run the tests using the mocked function and watch them dramatically fail.

If the majority of the tests are not failing—some probably will pass due to luck—return to step 4 and rewrite the tests to be more comprehensive and all-encompassing.

###6: Create concrete implementation

Now finally, it’s time for the magical last step of TDD and AIDD: the refactoring. It is here we actually create and then improve on the function. 

Give the AI the type or types you made in step 2. Or give it a simple verbal explanation. Or even all the unit tests you made. And unleash it!

###7: Run tests and expect success ✅

Use the function it creates and, hopefully, watch them gloriously pass!

If they don't—which will probably happen quite frequently, at least now in 2023—collaborate with the AI to achieve the goal of the tests passing. You could:

- Ask the AI to try again, supplying any error messages and ideas you might have to help it out. 

Or:

- Manually review the function and see if you can fix it, or implement it yourself. Ask the AI for ideas to help you out.

###8: Refactor

Once all the tests have passed, it's important to review the function manually and **assess whether it aligns with the spirit of professional software construction** mentioned [earlier](#the-value-of-human-development-skills). If not, maybe consider refactoring the function.

>☝🏻 _Again, if you're still not sure why you won't be replaced by AI anytime soon, the step above is one of the main reasons._

If the tests start to fail during the refactoring process, keep collaborating with the AI, following the same approach as in step 7, until all the tests pass again.

###(Optional Final Step): Celebrate!

All done! Congratulate yourself and celebrate the fact that you are now one step closer to delivering happiness to your customer! 🎉

>☝🏻 _In this article we are focusing on unit testing. However, I believe that in general AIDD is applicable to the other testing strategies as well. That said, it should be acknowledged that these other tests typically cover more complex scenarios and therefore require further manual effort and careful thought from the developer._
>☝🏻 _Although the principles of TDD and AIDD are close to identical, it's not until you start developing that you begin to see the significant differences between the two approaches._

##AI-Driven Development in the Wild

Finally, let’s see an actual example of how AIDD can be used in the real world. 

Why not attempt to follow along with your own AI companion?

{% youtube https://youtu.be/xQx3Do9Fji8 %}

If you did follow along with the video, pause for just a moment and take in the fact you didn’t actually create that function yourself. You didn’t even create all the unit tests yourself!

Instead, you were like a _god_; guiding your creation with subtle nudges—yet rarely directly intervening.

That, at least to me, is mind-blowing. 

---

Dawid Dahl is a full-stack developer at [UMAIN](https://www.umain.com/) | [ARC](https://arc.inc/). In his free time, he enjoys philosophy, analog synthesizers, consciousness, and being with friends and family.

---

Credit for pyramid and cycle graphics: Jenny Eckerud.
TS/Jest CodeSandbox [template](https://codesandbox.io/s/template-ts-jest-qb63h) used in the video.