Code Story

Code Story: Chat Bots

analysis, generation, documentation, limitations

2.  Chat Bots

A chat bot session is the simplest form of AI-assisted development: open a browser, describe a problem in plain language, and get a response. No API key, no install, no code required. This chapter covers what chat bots are good for, how to prompt them effectively for code tasks, and when to move to a more capable tool.
Why start with chat bots?
  1. Zero setup — the fastest path from a question to an answer.
  2. Good for understanding an unfamiliar API, pattern, or error message before writing any code.
  3. Prompting for a chat bot and prompting for the API use the same vocabulary — roles, context, constraints — so skills transfer directly.
  4. The limitations of a chat session (no file access, fixed context window, no tool use) make the step up to a CLI agent feel motivated rather than arbitrary.

2.1  Prompting for Code Analysis

Give the bot the code, then ask a specific question. Vague prompts get vague answers. Effective patterns:
  • “What does this function do? Focus on the return value.”
  • “What would happen if I passed an empty slice to this function?”
  • “Explain the ownership rules that apply to this block.”
  • “What is the time complexity of this algorithm and why?”

2.2  Prompting for Code Generation

State the function signature, the inputs, the expected output, and any constraints. The more precise the spec in the prompt, the less revision the output needs.
  • Always specify the language and version (e.g., “Python 3.12”, “C++23”, “Rust 2021 edition”).
  • Include one concrete example: input → expected output.
  • State what the code must NOT do (allocate, panic, use unsafe, etc.).

2.3  Prompting for Documentation

Chat bots produce good first-draft documentation when given the code and the audience.
  • “Write a one-paragraph description of this module for a README.”
  • “Write a doc comment for each public function in this file.”
  • “Summarize this diff in three sentences for a commit message.”

2.4  Limitations and When to Move On

Know when to switch tools:
  • Context window fills up — the bot forgets earlier parts of a long conversation.
  • No file access — you must paste code manually; large codebases are impractical.
  • No tool use — it can suggest a command but cannot run it or read the output.
  • Hallucination risk — always run generated code before trusting it.
When you hit these limits, move to a CLI agent (Chapter 3) or the API (Chapter 4).

2.5  References

ResourceDescription
Claude Anthropic’s chat interface. Best for long-context code tasks.
ChatGPT OpenAI’s chat interface. Large model family with code interpreter.
Gemini Google’s chat interface. Strong at multi-modal and search-grounded tasks.
CodeBites: Chat Bots Track page with example sessions and prompt templates.