Advanced · Building with AI · module 142 of 155
Programming with an AI assistant
Let AI help with code in small steps, with tests, explanations and human oversight before anything goes into use.
After this lesson
You describe what code should do, let AI work in small steps, test the result and understand what you are putting into use.
In view · An improvement loop
Code in small, tested steps
Input, output, edge cases and a few tests before the code exists.
One function at a time, explained line by line.
First on a test folder, then review and save in version control.
Part 1 of 3 · Describe and test
Your preference for less movement is on. Choose each part yourself.
First describe what it should do
An AI assistant writes code quickly, even for people who do little programming themselves (lesson 79). Start with a clear description: what input, what output and which edge cases. For example: a script that renames files by date, but does not overwrite anything if a name already exists. Give a small example of input and the expected output. Work in small steps: one function at a time is easier to check than a complete program in one go.
Test and understand what you get
First write or ask for a few tests: small checks that verify whether the code does what you described, including in edge cases such as an empty file or an odd name. Have the AI explain the code line by line, and ask further about anything you do not understand. Run the code first on a copy or a test folder, never straight away on real data. An AI can invent a function or a package; so do not install a package you do not know without checking whether it exists and is reliable.
Store, share and maintain securely
Do not put passwords, keys or personal data in your code or in the prompt (lesson 5). Keep code in version control, so that you can see and undo every change. Have code that others use, or that works with real data, reviewed by someone with experience. Note alongside the script what it does, who maintains it and how to stop it. A script that works today can fail tomorrow because of a different file name or an update.
New practice example
From explanation to a usable result.
Have AI write code in small steps, with tests and explanations, and try it out on copies first.
Fictional practice situationFictional: a secretary wants to use a small script to remove duplicate registrations from a membership list. Two members are called Jan Peeters, with a different year of birth.
View a possible solution
This is how it can be done
Description: a registration is a duplicate if both name and date of birth are the same. Test: the two members called Jan Peeters both stay on the list. The first AI version only compared names and deleted one Jan Peeters; the test caught it. After the change, the original list was kept as a copy.
Why this works
A clear definition and a test with an edge case prevent a member from disappearing.
Make it slightly more difficult
Think of another edge case for this script, for example an extra space in a name. What does your test look like?
Extra practice, at your own pace. You do not need to submit anything. This does not count towards an automatic assessment.
Your workplace · learning by doing
Make something. See what changes.

Checking the AI connection… You can already view the written example.

Present your assignment to Ende.
Read the answer, change one thing, and compare.
Previously held
New version
You remain in control
What do you want to improve in your next attempt?
On this device only. AI answers remain only in this page memory. This is self-review, not a grade.
Why this approach works
A clear definition and a test with an edge case prevent a member from disappearing.
A step further
Think of another edge case for this script, for example an extra space in a name. What does your test look like?
Try & discover · no obligation
Put the steps in a workable order
Move the steps with the arrows. Check whether each step has its necessary input and control.
What does a step depend on?
- Describe input, output and edge cases must precede Write a few tests first
- Describe input, output and edge cases must precede Let AI make a small first version
- Write a few tests first must precede Run it on a test folder with copies
- Let AI make a small first version must precede Have the code explained and read it yourself
- Have the code explained and read it yourself must precede Run it on a test folder with copies
- Run it on a test folder with copies must precede Have someone with experience look over it
- Have someone with experience look over it must precede Store it in version control with an explanation
Move a step and then check the sequence. The arrows also work with your keyboard.
This model checks dependencies, not duration, capacity, or actual execution. With multiple agents, the human decision remains a separate step.
This trial works locally with fictitious data and does not count towards your lesson completion. It starts anew with a new lesson or reload.
A prompt to get you started
Write a small Python script that renames all .jpg files in a given folder to their creation date, in the form YYYY-MM-DD_number.jpg. The script must never overwrite an existing file and first shows a list of the planned changes, without doing anything. Write three tests for it, including one for two photos from the same day. Then explain each part of the code.
Apply it
A colleague had AI write a script that cleans up old files. He wants to run it on the shared drive straight away, without testing it.
Which approach best fits this situation?
- Run it; the AI said the script is safe.
- First run it on a test folder with copies, have it show what it would delete and have someone review the code.
- Run it, and check afterwards whether any important files have disappeared.
With JavaScript, you can check your approach and receive immediate feedback.
Test your insight
An AI assistant suggests installing a package you do not know, to solve a problem. What do you do first?
- Install it straight away, because the assistant knows what it is suggesting.
- Check whether the package really exists, who maintains it and whether it is reliable, before you install it.
- Install the package and test the code afterwards.
Extra practice
Have AI make a small script for a task from your work. Run it on a test folder with copies, check the result and write down what the script does and how to stop it.
Description: rename photos by date, without overwriting, and show a preview first. Tests: one photo, two photos from the same day (sequence number 1 and 2) and a folder without photos. Execution: first on a test folder with ten copies. The first version overwrote the second photo from the same day; the test caught that. After the fix, all tests passed and I ran the script on the real folder.

