AI Coding Assistants
How do you understand code you didn't write, fast? Advitha joins the Campus Helper code mid-project and opens a file full of functions she has never seen. Reading every line cold would take her an afternoon. An AI coding assistant explains each function in plain words in seconds, and she still reads the code to confirm.
This lesson covers where coding assistants work, what they're good at, and the rules that keep you safe.
Three Places Assistants Work
| Where | What it does | Good for |
|---|---|---|
| In the editor | Suggests code as you type; answers questions about open files | Small functions, explanations, quick fixes |
| In the terminal | Runs commands and edits files when you ask | Setting up projects, running tests, refactoring |
| As an agent | Plans and carries out multi-step tasks, such as fixing a failing test | Larger changes, with you approving each step |
Understanding Unfamiliar Code
Here is the Campus Helper function from the picture, run with two inputs:
def find_fee(fees, grade, item):
"""Return the fee for one item in one grade, or None if it isn't listed."""
for row in fees:
if row["grade"] == grade and row["item"].lower() == item.lower():
return row["amount"]
return None
fees = [
{"grade": 10, "item": "Lab fee", "amount": 45},
{"grade": 10, "item": "Field trip", "amount": 30},
{"grade": 11, "item": "Lab fee", "amount": 50},
]
print(find_fee(fees, 10, "lab fee"))
print(find_fee(fees, 12, "lab fee"))45
NoneThe explanation's last point matters most: the function returns None for grade 12, so any code that uses it must handle a missing fee. Running the code confirmed what the explanation said, which is the habit to build: read the explanation, then check it.
Everyday Uses
| Use | Example prompt |
|---|---|
| Explain code | "Explain this function line by line, and list what could go wrong." |
| Explain an error | "What does this error mean, and what are the likely causes?" |
| Learn a framework | "Show the smallest working example of a route in this framework." |
| Prototype | "Write a first version of a script that reads this CSV and totals column B." |
| Use a model API | "Show how to call this API with the key read from an environment variable." |
Common Mistakes
Accepting suggestions without reading them. Every suggestion is a draft.
Letting an agent change many files unchecked. Review each change, and keep it in version control.
Asking about code without giving context. Include the relevant files and the error message.
Interview Corner
How do you use AI coding assistants responsibly?
For explaining code, drafting functions, tests and docs, and explaining errors, while reviewing and testing every suggestion, keeping secrets and proprietary code out of unapproved tools, and owning the result.
What is the difference between an editor assistant and an agent?
An editor assistant suggests code as you work; an agent plans and carries out multi-step tasks, such as editing several files and running tests, with a person approving its changes.
Practice
Exercise: explain, then confirm. Pick a function you didn't write, from an open-source project or your own old code. Ask an assistant to explain it line by line and list what could go wrong. Then run it with two inputs that test one of the risks it named. Was the explanation right?
Check your understanding:
- Name the three places coding assistants work.
- What did running
find_feeconfirm? - What should never be pasted into an unapproved tool?
Key Takeaways
Quick reference
| Task | Prompt starter |
|---|---|
| Explain | "Line by line, and what could go wrong..." |
| Error | "What does this mean, and likely causes?" |
| Prototype | "A first version that..." |
| API | "...with the key from an environment variable" |
Was this tutorial helpful?