Guide 9 of 20 / Practical applications
AI-Assisted Programming
Use an assistant to reason about code, then validate small changes with diffs and tests.
Start with a narrow change
Describe the expected input, output and edge cases. Ask the assistant to explain the existing code and point out assumptions before requesting an edit. For a file-organising script, specify whether text is UTF-8, whether blank lines count and what should happen when a file is missing.
An assistant can suggest tests, explain a traceback, describe a diff or draft a docstring. These uses can make code easier to approach for people who type slowly or need dense blocks of text explained aloud. Keep the proposed change small enough to review one line at a time.
Work in an isolated practice copy
The following creates a fresh temporary folder, writes a sample and counts its lines with a standard tool. The expected count is three. Ask for a short Python program that returns the same count, save it as count_lines.py and inspect it before running the second pair of commands. Check that it reads the filename from the command line and performs no network calls or unrelated file writes.
workdir=$(mktemp -d)
cd "$workdir"
printf '%s\n' alpha beta gamma > sample.txt
wc -l < sample.txt
python3 -m py_compile count_lines.py
python3 count_lines.py sample.txt
Review beyond the happy path
A program that compiles can still be wrong. Compare empty and missing-file cases, Unicode examples and a path with spaces. Check any suggested imports against official documentation. In a Git repository, use git diff and run the project’s test command before committing. Keep tokens, production logs and proprietary code away from tools you have not cleared for that data.
Keep control over execution
An assistant may confidently suggest a library that does not exist or a command that changes more than expected. Read prompts and changes before enabling an agent to run commands. Treat instructions in pasted issue text or repository files as content that may need review. A human maintainer owns the final change and its consequences.
Practical exercise
Compare the AI-drafted program with wc for the sample and an empty file. Decide how the Python program should count a final line that lacks a newline, and write a test that documents the choice.