Time to Adapt: Applying Generative AI in Software Development
A surreal image of computer code flowing like ribbons into the mind of lone programmer - MidJourney v6

Time to Adapt: Applying Generative AI in Software Development

For over 45 years, I've relied on code editors as my only technology to help me write code, and although they have provided some productivity benefits, writing the code for a computer program remains a largely human activity. However, as we enter 2024, I am adapting to a new era of coding with the aid of generative AI.

Generative AI excels at writing snippets of code quickly and accurately, applying best practices that I may not have been familiar with. As a result, my role as a human has evolved to focus on creating software designs and crafting specific prompts that generate code in an assembly-like fashion. That’s not a bad deal.

For those committed to continuing in this profession—and not in denial about the impact of generative AI—it is crucial to consider how you will collaborate with your new AI teammate. Before exploring available tools, you need to decide whether you will be a Centaur (working alongside AI) or a Cyborg (integrating AI into your workflow).

Imagine being able to walk through a software design and having generative AI write the code in the same amount of time it takes to assign and review tasks to a team of programmers. The code generated will be consistent and high-quality from the start, and can be endlessly revised and refactored as needed. It is possible that 2024 may mark the last year that computer programming is a predominantly human activity.

Ethan Mollick’s Research on Human-AI Collaboration

Ethan Mollick's work with the Boston Consulting Group has explored the concept of human collaboration with generative AI, introducing two distinct approaches: Cyborg and Centaur. See the link below for the full article?

(1) Centaurs and Cyborgs on the Jagged Frontier

In his article, Mollick describes the Centaur approach as having a clear line of demarcation between human and machine tasks. This means that there's a strategic division of labor, where responsibilities are allocated based on the strengths and capabilities of each entity. For instance, a Centaur might delegate tasks to AI, such as generating a sentence for completion.

On the other hand, Cyborgs blend machine and person, integrating their efforts deeply. Instead of delegating tasks Cyborgs intertwine their efforts with AI. This means that they work in tandem with the AI, handing over bits of tasks, like initiating a sentence for the AI to complete.

These collaboration models extend beyond programming to various tasks, including writing, design, and decision-making. By understanding these approaches, individuals and organizations can effectively harness the power of generative AI while leveraging human strengths.

Why This Matters in Software Development

When writing code, you now have two options: leveraging an AI-integrated code editor or using a chat interface like ChatGPT, Gemini, or Claude to generate code and the pasting that code into a traditional code editor. The former approach blurs the lines between human- and AI-generated code (Cyborg approach), while the latter maintains a clear distinction between human and AI-generated code (a Centaur approach).

Unless you're writing trivial code, such as a Tic-Tac-Toe game, upfront design work is necessary. This involves breaking down the problem into manageable pieces using an Object-Oriented (O-O) or Service-Oriented Approach (SOA), or combining both.?

In a recent case study, I designed a software solution to generate a first draft of a fiction novel. The diagram below illustrates how I decomposed the problem into three generative services and eight data objects. This modular design allowed me to assemble the solution by starting with data objects and then moving on to generative services. Your design may differ, but the key takeaway is to break down complex problems into smaller components.

Traditionally, this approach enables teams of developers to work in parallel, shortening the duration of the software development life cycle (SDLC). However, with generative AI, you likely no longer need a team of human programmers at all.?

A software design for first draft fiction novel generation including human-in-the-loop

The Centaur Approach to Coding: A Flexible and Effective Method

In a previous article, I used the Centaur approach to explore the potential of generative AI in software development. This approach allowed me to leverage the power of AI without changing my trusted code editor, Jupyter Notebook, which I've used for over a decade. I was already familiar with ChatGPT and had started experimenting with Gemini and Claude's chat interfaces.

A Step-by-Step Guide

  1. Open your code editor: Choose your preferred code editor, whether it's Jupyter Notebook, PyCharm, or another tool.
  2. Open chat interfaces: Launch one or multiple chat interfaces, such as ChatGPT, Gemini, or Claude. Having multiple options allows you to get a second opinion or compare results.
  3. Design and generate components: Start with data objects, using consistent prompts to ensure uniform code. Then, generate generative services that utilize the data objects. For example, I specified Pydantic data objects with a self-generating unique identifier (ID) and included testing code.
  4. Cut and paste code: Copy the generated code into your code editor, creating a new cell for each component. If your editor has a notebook interface, use separate cells for each component.
  5. Test and confirm: Cut and paste the testing code, execute it, and confirm that the component works as expected.
  6. Save prompts: Store your prompts in separate chats, opening a new chat for each data object generation.

Advantages:

  • No need to change your code editor
  • Compatible with any LLM (Large Language Model) with a chat interface
  • Clear separation of AI-generated output
  • Ability to use vision, text, or both in prompts

Disadvantages:

  • Requires frequent cut and paste actions
  • Chat interfaces are not specifically designed for software development

Leveraging the Vision Capabilities of Large Language Models

As an aside, an alternative Centaur approach leverages the advanced vision capabilities of leading Large Language Models (LLMs) like GPT-4 and Claude. Instead of starting with detailed prompts, I can use the software design diagram shown earlier as my prompt input, and the LLM will generate skeletal code based on the diagram.?

This top-down approach offers a more streamlined and efficient process. With more detailed software design diagrams, this method could potentially eliminate the need for crafting detailed prompts to generate code. While this approach is beyond the scope of this article, it's an interesting possibility and worth exploring at a later date.?


A Cyborg Approach?to Coding: Taking Off the Training Wheels

The Cyborg approach most likely requires to change your code editor of choice, which shouldn't be taken lightly.? If you're doing a small amount of programming, it's best to stick with what you know and adopt a Centaur approach. However, if you're working on medium to large-scale programming projects, it may be time to consider switching. For the purposes of this article, I'll be highlighting one code editor that stands out from the rest: Cursor. You can find an overview of its features here.

Cursor - The AI-first Code Editor

Cursor the AI Code Editor?

If you have experience with professional code editors, you'll find the Cursor interface familiar and user-friendly. With its extensive features, I'll focus on how generative AI is seamlessly integrated into this editor.

Mastering Cursor's AI capabilities is simple, with only two key command combinations to remember:

  • Command-K: Opens a prompt window to use AI to generate or edit code
  • Command-L: Opens an AI chat sidebar window

In the example below, after hitting Command-K, a prompt window appears. I requested Cursor to generate two Pydantic data objects, Order and OrderLine, and provided some details. The generated code is shown below, and I have the option to accept or decline it.

Cursor AI Editor - code generation

To open a chat window, use the key combination Command-L as shown in the image below, the chat window opens on the right-hand side, providing access to some or all of your code base. In this example, I've used it to summarize the code so far with a simple prompt. This chat interface becomes invaluable when dealing with a large amount of code.

Cursor AI Code Editor - Opening an AI chat window

When editing a selection of code - whether written by a programmer or generated - I repeat the process: hit Command-K again, and the prompt?window reappears. This time, I've asked it to write the necessary code to validate the objects.


As you can see, the new code it has added starts with @validator. The LLM determined that what I wanted was a mechanism to ensure that each?

Order would have at least one OrderLine associated with it - something I hadn't considered when crafting the prompt. At times, it seems as though the language model understands my code better than I do.

Cursor AI Code Editor - editing a selection of code

Cursor provides the option to upgrade to Pro, which currently costs $20 per month. Alternatively, you can use your own API key from OpenAI (GPT-4) or Anthropic (Claude) and pay as you go. The settings for this are shown below. It's worth mentioning that the code I generated earlier was done entirely for free using GPT-3.5. You can write a significant amount of code without needing to upgrade to more expensive options like Claude-3 Opus or GPT-4.?

Cursor AI Editor - Accessing generative AI Large Language Models


Cyborg Approach: Advantages and Disadvantages

The Cyborg approach, which combines human coding with generative AI capabilities in a code editor like Cursor, has both advantages and disadvantages.

Advantages:

  • A unified user interface for both human and generative AI coding
  • Eliminates the need for cut and paste, reducing errors in the process

Disadvantages:

  • It may require learning a new code editor, which can be a significant adjustment
  • It can be challenging to discern what has been created by generative AI and what has been written by a human - a distinction that may not matter in the long run
  • The added features of generative AI can further complicate an already complex interface
  • Some code editors only allow you to interact with a single LLM?
  • No vision input capabilities

Summary?

The productivity benefits of human and generative AI collaboration in the software development lifecycle are unprecedented. As previously discussed in a separate article, this collaboration could significantly reduce the coding effort required—from 40% to about 20% of the total development effort.

There are two main collaborative approaches: Centaur and Cyborg. Both offer similar productivity benefits and can be used in tandem. For instance, one might start with the Centaur approach for high-level coding and switch to the Cyborg method for detailed work and code refactoring.

These strategies could also benefit solo developers, who previously faced challenges compared to larger teams. With generative AI, a single developer can efficiently produce substantial software solutions without the need for extensive meetings or team dynamics.

Undoubtedly, we are entering a new era. By the end of 2024, programming will likely no longer be predominantly a human endeavor. The good news is that we have the opportunity to shape how we integrate generative AI into our teams.

Imagine the possibilities when you can walk through a software design and have the code written by generative AI as quickly as assigning tasks to a team of programmers. The code will be consistent and high-quality right from the start, and can be endlessly revised and refactored as needed.

The integration of generative AI into the software development lifecycle is poised to revolutionize everything, but good software design skills by humans are still essential – at least for the time being.

Related Articles:?

This is the second of three articles (see below), based on a? single case study.?

Flattening SDLC Estimates (published)

This article explores how generative AI can significantly reduce Software Development Lifecycle (SDLC) estimates by enabling rapid generation of new code and adaptation of existing code to meet changing business requirements.

Time to Adapt: Applying Generative AI in Software Development (this article)

Building on the introduction of GitHub Copilot, this article delves into various ways to integrate generative AI into software development, including the Centaur and Cyborg approaches, based on research by Ethan Mollick. I have firsthand experience with both methods.

Moving from Software Design to Coding with Generative AI (soon to be released)

This article will discuss how to transition from software design to coding when most of the code is written by generative AI, allowing for a seamless and efficient workflow.

Full Disclosure: I used Llama3–8B to correct grammar and improve readability from a first draft. All of the thoughts expressed in this article are my own, and I am human. My pre-training took over 45 years.




要查看或添加评论,请登录

社区洞察

其他会员也浏览了