Basic

What actually happens when you ask an AI to review your code?

Ask an AI to review some code and it hands back a list of notes, one problem, a couple of slow spots, and something about a variable name you'd never have caught on your own. This is AI code review. It isn't a bot fixing your code for you. It's a second person looking at the screen while you do the work.

What you will see

Suggestion: Hash passwords before saving Suggestion: Add a comment here Suggestion: Rename variable for clarity

About 3 min of reading

Try It

Asking an AI to review your code gives you a list of notes, not a bot rewriting your files. I spot a raw-password bug, catch a crash that only happens on an empty list, then list the three kinds of suggestions a review hands back.

1

The AI reads your code and writes back a note about something most people miss on day one. I write a login check that compares a raw password and print that the comparison is wrong and the secret is exposed to anyone who can read the file.

def login(user, password): if password == user: return True return False user = "alice_abc" result = login("alice_abc", "correct_horse_batterystaple") print(f"login accepted: {result}") print(f"Raw password exposed to file readers: True")

Before you run it, say out loud what it will print. Then open the answer.

What it prints
login accepted: False Raw password exposed to file readers: True
The note does not fix anything. It just points at the password check, so the reviewer is a stranger's opinion, not a verdict you must follow.
2

A review can catch a crash that only happens under a rare condition. I write a function that returns the first item and print what happens when the list is empty, showing the cliff the function drives into.

def first(items): try: return items[0] except IndexError: return "ERROR: empty list crashes index 0" print(first([]))

Before you run it, say out loud what it will print. Then open the answer.

What it prints
ERROR: empty list crashes index 0
Reviewing is not running your tests. The AI can read the code, but you are still the one who decides which notes to act on.
3

Notes are suggestions, not fixes. I list three kinds of review output and print each one to show how a good review loop leaves you the final decision.

def review_notes(): return ["Hash passwords before saving", "Add a comment here", "Rename variable for clarity"] for note in review_notes(): print(f"Suggestion: {note}")

Before you run it, say out loud what it will print. Then open the answer.

What it prints
Suggestion: Hash passwords before saving Suggestion: Add a comment here Suggestion: Rename variable for clarity
The AI does not own your codebase, so it recommends. You take only the notes that fit your project and leave the rest.

Put it in order

Before you write anything, put these lines back in the right order. Click a line to move it up one step. This support step is easier than writing code from scratch, and it is here to make the last example stick.

Data Flow

You share code, the AI reads it and returns notes, and you pick which ones to act on.
1 You paste a function or file
↓
2 The AI reads it and looks for issues
↓
3 It returns a short list of notes
↓
4 You decide which notes become changes
Line by line

Read the first example one line at a time. A line that prints shows what appears on screen; the rest set things up quietly.

def login(user, password): sets nothing on screen
if password == user: sets nothing on screen
return True sets nothing on screen
return False sets nothing on screen
user = "alice_abc" sets nothing on screen
result = login("alice_abc", "correct_horse_batterystaple") sets nothing on screen
print(f"login accepted: {result}") login accepted: False
print(f"Raw password exposed to file readers: True") Raw password exposed to file readers: True
Why this works
What AI review actually does

It reads your code and writes back a list of notes: bugs it thinks it sees, spots that look slow, names that are hard to read, patterns that tend to cause trouble. It's fast, it never gets tired, and it's ready at any hour. It does not run your tests.

What it misses

It doesn't know the rules your project only has in your head, and it can't see the edge case that keeps you up at night. Treat its notes as a careful stranger's opinion, not a verdict. Verify the ones that matter before trusting them.

Examples

The first review you ever ask for

You: "Review this login function."
AI: "The function works. One issue: passwords should be hashed before saving."

def login(user, password):
    if password == user.password:   # readable, but not safe
        return True
    return False

The AI noticed something most of us miss on day one: comparing raw passwords means anyone who can read the file can log in. That single catch is the whole idea of this feature.

When it catches the crash before you do

You: "Review this function."
AI: "It works now. But if the list is empty, this line 4 will crash."

def first(items):
    return items[0]   # index 0 does not exist when the list is empty

You'd been using this function for a while without a problem, it only breaks when the list is empty, and you hadn't hit that yet. The review didn't rewrite anything; it just pointed at the cliff you were about to drive into.

Notes are suggestions, not fixes

You: "Review this code."
AI: "Here are three suggestions. You decide which to apply."

The AI doesn't own your codebase, so it doesn't get to change it. It recommends. A good review loop looks like this:

  • Take only the notes that fit your project
  • Ask it to explain anything that isn't clear
  • Apply one change, then look again

You stay the one driving.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

Next Lesson
Not every note needs a fix
Not every note needs a fix →