AI Coding Assistants

Updated · 5 min read
mediumPython 3.13aideveloperscoding-assistantspythonproductivity

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

In the editor, in the terminal, and as an agent
WhereWhat it doesGood for
In the editorSuggests code as you type; answers questions about open filesSmall functions, explanations, quick fixes
In the terminalRuns commands and edits files when you askSetting up projects, running tests, refactoring
As an agentPlans and carries out multi-step tasks, such as fixing a failing testLarger changes, with you approving each step

Understanding Unfamiliar Code

Here is the Campus Helper function from the picture, run with two inputs:

Python
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"))
Output
45
None

The 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

UseExample 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:

  1. Name the three places coding assistants work.
  2. What did running find_fee confirm?
  3. What should never be pasted into an unapproved tool?

Quick check: AI coding assistants

4 questions
1Which kind of assistant carries out multi-step tasks?
2What does find_fee return for grade 12?
3Who is responsible for AI-written code that ships?
4What should you do after pasting an API key into a tool by mistake?

Key Takeaways

Quick reference

TaskPrompt 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?

Lesson 70 of 186