Understanding AI Coding Assistants

First lesson of the Coding with an AI Assistant (Prompts, Code Review) course, free to read: about 15 minutes, 3 exercises and 3 quiz questions. This is the catalogue's base lesson; in the student space, it is rewritten for your profile.

Objectives

  • Explain in simple terms how a coding assistant generates a response
  • Identify its strengths and limits, including hallucinations
  • Adopt the mindset of a developer who is responsible for their code

Language model (LLM)HallucinationsContext window

Coding assistants (built into the editor, used through chat, or run as agents) have become everyday tools for many developers and analysts. Used well, they save a considerable amount of time. Used badly, they produce wrong code that looks right. This course teaches you to get the most out of them without losing control.

How it works, in simplified terms

A coding assistant is built on a large language model (LLM), trained on immense amounts of text and code. From your request, it produces, piece by piece, the most plausible continuation. It does not “understand” your project like a colleague would and, unless it has tools to do so, it does not run the code it suggests: so it doesn’t know whether that code works.

Practical consequences:

  • it excels at frequent, well-documented tasks: writing a classic function, explaining an error message, converting code from one language to another, suggesting tests;
  • it is less reliable on what is rare, recent or specific to your project: a little-known library, an internal business rule, a very recent version of a tool.

Three forms of assistants

Form Typical use
Conversation (chat) ask a question, request an explanation or a function
In-editor completion code suggestions as you type
Agent the tool reads your files, modifies the code, runs commands or tests

The more autonomous the tool, the more important it is to review what it does.

Context

The model only sees what you give it: your message, the files that are open or shared, the conversation history. This amount is limited (the context window). If it doesn’t know that you are using Python 3.15, pandas or a naming convention, it will guess. And the same question can produce different answers from one time to the next.

Hallucinations

A model can invent things with great confidence: a function that doesn’t exist, an imaginary parameter, a fictitious package name. A typical example:

notes = [12, 15, 9]
moyenne = notes.mean()      # suggested by an assistant: AttributeError!
# Python lists have no mean() method.
# Correct: sum(notes) / len(notes), or statistics.mean(notes)

The code “looks like” pandas or NumPy, hence the confusion. How to protect yourself:

  1. run the code and read the errors;
  2. check any unfamiliar function in the official documentation;
  3. be wary when the assistant cites a precise source, version or figure.

The golden rule

The assistant is a fast colleague but not always a reliable one. You remain responsible for the code you integrate:

  • only keep code that you understand line by line;
  • test it as if you had written it yourself;
  • when learning, try on your own first, then compare with the AI’s suggestion: this is how you make progress instead of depending on the tool.

Exercises

Solutions and tests stay on the server. In the student space, your code is run and checked, and the tutor gives hints before the solution.

  1. CodeDifficulty 1Python in the browser1 hint

    Fix a hallucination

    An assistant suggested this code, which raises an AttributeError because Python lists have neither .mean() nor .max_value(). Fix resume(notes) so that it returns a tuple (moyenne, maximum) using tools that actually exist.

    def resume(notes):
        moyenne = notes.mean()
        maximum = notes.max_value()
        return (moyenne, maximum)
  2. Multiple choiceDifficulty 11 hint

    Why a hallucination?

    Why can a coding assistant suggest a function that doesn’t exist?

    • Because it is broken
    • Because it generates the most plausible text without checking that it is accurate
    • Because the function was removed from Python
  3. Multiple choiceDifficulty 21 hint

    A suitable task

    For which of these tasks is a coding assistant generally the most reliable?

    • Applying an undocumented internal billing rule
    • Writing a function that reverses a string
    • Using a library released last week

End-of-lesson quiz

  1. By default, does a chat-based coding assistant verify that its code works?

    • Yes, always
    • No, unless it has tools to run it
    • Only in Python
  2. Who is responsible for the code integrated into a project?

    • The AI assistant
    • The developer who integrates it
    • The tool's vendor
  3. What is the context window?

    • The editor window
    • The amount of information the model takes into account to respond
    • The duration of a session

The rest of the course

  1. Writing a Good Prompt for Code15 min
  2. Reviewing Generated Code20 min
  3. Testing and Debugging with AI20 min
  4. Responsible Use: Security, Data and Learning20 min

Coding with an AI Assistant (Prompts, Code Review) · Beginner · 2 h 30 min