Generative AI in code generation

Written by Ramakrishnan Jonnagadla

Anyone, literally anyone, can code in just about any language today – be it Python scripts, Java classes, COBOL assembler or RPG. The only support one needs is in the form of a Generative AI assistant. It can help creating new applications, but Generative AI can also help modernize legacy code or translate code from one programming language to another, test the code, complete the code – it can help perform any task in the software development lifecycle, useful to developers at all levels.

How is it made possible, now?

Generative AI for coding is seeing an uptick because of advancements in NLP, i.e., natural language processing, deep learning algorithms, and the latest sensation, large language models or LLMs. The LLMs are trained on a vast dataset of existing source code (the more diverse the source code, the better), taken from publicly available code, such as those produced by open source projects, like Github. If needed, we can further fine-tune LLMs with proprietary code data sets.

How do programmers invoke AI assistance?

In principle, it’s as simple as typing a text to an interface to generate code / intended output.

1. Programmers enter the text “PROMPTS” into the LLM.
(A PROMPT describes what they want the code to do. For eg., a prompt could read “sort this row of data” or “create a submit button”, etc.).

2. Then add how they want the generative AI system to actually process that text.
(This could be in the form of a number of different things – form of code snippets, full functions of actual code).

Generative AI can do the rest and produce a usable output. If one can build a nice prompt-library, it can streamline the coding process by handling repetitive tasks that a human programmer is more than happy to offload.

For e.g., Looking at error reporting to log files; and translating code from one language to another are methods that are particularly useful in modernization projects such as updating legacy applications by transforming COBOL to Java. It can also serve as a very efficient way of testing and it’s a great way to perform debugging.

Generative AI an assistant, NOT a replacement:

The generative AI driven coding works best as an assistant rather than a complete replacement for human programmers. Even though code produced by the generative AI and the LLM technologies are becoming more accurate, it can still contain flaws, and it should be reviewed, edited and refined by real life people. So one can think of generative AI as enabling developers to generate code faster, reducing the work of manually writing lines of code, and freeing developers to focus on higher value work.

How is generative AI for code different from low/no code?

Another way to generate code quickly and well-known in the industry are the “Low and no code tools”.

These are built on a series of templates that provide input, and they also use a series of libraries of components. People without coding skills can use a visual interface to do things like drag and drop components to create applications quickly. The code a LCNC platform creates is hidden in the background from the user.

Generative AI for code, on the other hand, do not use templates, nor libraries of components. The software is reading the developer’s plain language prompts and suggests code snippets from scratch that will produce the desired results.

Thus, while low code and no-code tools generally target non-developers and business users, both pro developers and other users can use AI code generation software.

Two different ways of using Generative AI for code:

There are two categories of generative AI code generation that happens widely today.

1. General purpose

  • Driven by generative AI applications like OpenAI’s ChatGPT, Google Bard etc.
  • Typically, free-standing and not plugged into development environments

2. Code Generation tools

  • Driven by ‘Copilots’ like Github, Microsoft etc.
  • Pre-trained AI model for code completion in many languages JavaScript, Go, Perl, Ruby, Swift etc.
  • Typically uses machine learning to suggest code, based on the context & analyze vulnerabilities.
  • Available as extensions to various IDEs like Visual Studio, Eclipse

Ultimately, with an accelerated ability to automate code development, find bugs, generate test cases, and optimize, generative AI for code is driving a tectonic shift to the paradigm of software development– that is poised to change course of coding history permanently and usher in a new era of innovation and efficiency.