liveBook · Manning

Code generation

As explained in Introduction to Generative AI, Second Edition

The automated production of source code from a natural-language description, specification, or other input.

Code generation uses a natural-language description, comment, docstring, or other input to produce code for a specified programming language. Large language models (LLMs) are especially suited to code because code contains clear structures and repeated patterns. section 1.7 section 6.6

Common uses include:

  • Suggesting code as a programmer types, completing repetitive code, offering alternatives, and converting comments into implementations. section 1.7 section 6.6
  • Making a quick first attempt at a function, although complex functions can still fail and require iteration. section 6.6
  • Generating documentation such as comments, docstrings, and type hints, and transforming code or schemas into visual diagrams. section 6.6
  • Supporting coding interviews, testing, and programmers who are not native English speakers. section 1.7

Most tools began as pair programmers that complemented human developers rather than replacing them. Newer agentic systems can take actions directly, while “vibe coding” relies on prompts for much or all of a project. Greater autonomy does not guarantee reliability: one assessment found an autonomous system spending days on dead ends that a human engineer might have recognized quickly. section 1.7 section 6.6

Generated code remains subject to security, transparency, licensing, accuracy, and privacy concerns. Proprietary code should not be pasted into an external application programming interface (API), and generated output needs human checking before it is trusted. section 1.7 section 6.6

A practical prompt

A developer can describe what a function should do in a comment or docstring and ask an LLM to implement it. The result may provide a useful starting point, but the developer must assess whether it is correct and suitable for the task. section 6.6

Figure 6.4 The docstring produced by ChatGPT correctly describes the function given and each input.
A screenshot of a computer

AI-generated content may be incorrect.

A generated docstring demonstrates how code-generation tools can describe a function and each of its inputs. section 6.6

How Introduction to Generative AI, Second Edition covers it

How deep it goes
Explains prompting, autocomplete, agentic action, and risks, but stops short of implementation details or systematic evaluation methods.
Examples
Uses GitHub Copilot, Cursor, Devin, Claude Code, Replit Agent, Windsurf, DiagramGPT, and generated docstrings as examples.
What it assumes
Assumes familiarity with programming tasks while explaining natural-language prompts and code-generation assistance in accessible terms.
What you can do after
Apply it via LLM-assisted programming tools to draft functions, complete code, generate documentation, and visualize code or schemas.
How it connects
Connects code generation with large language models, pair programming, software development, documentation, testing, and programming languages.

Also explained in

Compare how 17 books explain code generation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Introduction to Generative AI, Second Edition. The section links point to the parts of the book it draws on.