AI-powered development. Part  1. Introduction

AI-powered development. Part 1. Introduction

This introductory article tries to answer the question: "Why should I care about AI tools for software development?".

Play this article

Why should you care?

Figure 1 shows how GitHub Copilot generates a semantically correct Jest test for my custom code. The result of generation is a fully functional test that handles my custom logic; it's not a boilerplate with "put your implementation here"; it's a working code that saves your mental effort.

Figure 1. Code generation by GitHub Copilot
Another argument for using AI tools is improving developer performance or, more accurately, team performance. To define the term "performance", I will reference to approach based on four key architecture metrics — deployment frequency, lead time for changes, change failure rate, and time to restore service described in Software Architecture Metrics Book.
AI tools allow a team to improve lead time for changes and decrease the failure rate due to the ability to generate using AI new code/tests and use AI to assist in refactoring old code. As a result, the developer empowered by AI will write less and/or better code and have more space for software improvements on both functional and non-functional requirements.

Acknowledgments

Thanks to Anastasiia Hrechko for helping me prepare this article.

The cover image is taken from https://www.monkeyuser.com/2022/effort-shift/.

The goal for the series

A new generation of AI tools for developers is here. There is a need to figure out what task they can solve and how they can help your team to perform better.
Also, it takes a lot of effort for a leader to promote new tooling because you need to understand it, show practical use cases and explain how these tools can help specific developers in their day-by-day work.
Another barrier to adopting AI tools is a new mental shift in thinking that may require effort from a developer and maybe external help. Nevertheless, these tools are here:

In this series, I'll try to collect practical use cases for AI for software development. This introductory article aims to help team leaders and developers adopt AI through practical use cases and build new processes around AI-enabled tooling.

Note. This series was inspired by @svpino post

Introduction

In 2022 IT industry was revolutionized by two AI tools:

  • GitHub Copilot - GitHub Copilot uses the OpenAI Codex to suggest code and entire functions in real-time, right from your editor.

  • ChatGPT - ChatGPT is a significant language generation model developed by OpenAI. It is based on the GPT (Generative Pre-trained Transformer) architecture and is trained on a dataset of conversational text. As a result, it can generate human-like text in response to prompts, making it useful for tasks such as chatbots, language translation, and text summarization.

Note. It is worth mentioning GitHub Copilot Labs, A VS Code extension for experimental applications of GitHub Copilot. Currently, Copilot Labs consists of a VS Code sidebar that houses the next features: code explanation, code translation (from one programming language to another), IDE Brushes (check Figure 2) and test generation. Check Figure 2.

Figure 2. GitHub Copilot Labs Panel

You can try both ChatGPT and Copilot for free.

Use cases

Let's discover possible use cases for software development. Figure 3 contains the graph representation for different use cases. I organized these use cases into an algorithm that helps improve software quality based on simple criteria - do you have code, or it's a new feature that requires development from scratch?

Figure 3. Algorithm to use AI tools for software development

Note. Figure 3 contains an infinite loop between Refactor, Code improvements and Tests blocks. This loop shows that software improvement is a never-ending process that follows Plan-Do-Check-Act (PDCA) cycle.

Refactoring

The most advanced branch of Figure 3 is related to refactoring existing code due to the nature of AI - which requires input from a human being to offer a solution. Parts 2.1 and 2.2 of this series will cover use cases related to the refactoring:

  • Tests

    • Unit tests

    • Integration tests

    • Performance tests

  • Code Improvements

    • Bugs search and bug fix

    • Optimize code

    • For untyped languages like JS, add types

    • Migrate code from one framework to another, e.g. from Jade to ReactJS

    • Simplify code

    • Add documentation

Code generation strategies

Part 3 of the series will be related to another branch of an algorithm - new code development. Even without any code, you need to give input to AI to get help. At this stage possible approach is to use GitHub Copilot to define API/Event/Input Shape in one of the machine-readable specifications like OpenAPI or Protocol Buffers.
Created specifications serve as input to the AI tool to generate boilerplate code using the framework of your choice. In addition, the new specification gives you a good starting point for documentation of the solution and the ability to use ContractTest or Test Driven Development (TDD) techniques for building software.

Note. Be ready for whether AI will use basic libraries or best practices. AI can do a lot, but you need to be specific about what you want. It's like Genie. It will give you what you want if you know what you want :)

Limitations

Warning!!! The statement that "AI can solve my problems" is one of the big misconceptions about existing AI tooling. AI can write code when you give it tips and questions, but YOU are the only one who can solve the problems.

Invalid code

A good illustration of the current AI user experience is a description of it as an irresponsible author. The best way to demonstrate this behavior is using the Jest test generated by ChatGPT for this code.

const text = process.env.TEST_VAR || "nothing";
export const getState = () => {
  const state = `Hello ${text}`;
  return state;
};

Generated by ChatGPT Jest test had this shape.

describe("State resolver test", () => {
  it("should return Hello world", async () => {
    const result = await getState("world");
    expect(result).toBe("Hello world");
  });
});

As you can see in generated code, AI wrongly assumed that the getState function accepts parameters to generate an output string. You need to spot such errors and fix them or ask AI to fix them.

Limited knowledge base

When this article was written, ChatGPT and Copilot (based on an OpenAI project called Codex) were limited by knowledge up to 2021. As a result, it's impossible to generate code for Apollo GraphQL Server v4 released in 2022.

Summary

  • AI-powered software development is the new normal that can increase team performance and software quality.

  • Leaders and developers will require additional efforts to incorporate new AI-based tools to improve functional and non-functional quality metrics in software development processes.

  • AI tools can help to refactor and generate tests of existing code. Also, AI is capable of generating new code.

  • Be aware that AI alone cannot solve your business problems.