100×worker · task analysis

Can AI Write Code?

By Hendrik De Winne Last updated: Lees dit in het Nederlands
Partly Yes, partly. AI writes functions, scripts, tests, and boilerplate today, based on a clear description or existing code. For architecture, complex business logic, and security, you still need an experienced developer. AI speeds up the writing, but control and final responsibility stay with the human.

How to do it

You start by describing the function or feature you need in plain language: what goes in, what comes out, and which edge cases matter. The more concrete the description, the more usable the first draft. If you already have code, style guides, or API documentation, paste them into the same conversation so the model matches your conventions instead of inventing its own.

From there, treat the AI as a fast first-draft writer, not a finished developer. Ask it to generate a function or small module, then read every line. For repetitive work such as unit tests, data transformations, or converting code from one language to another, AI often produces something close to final on the first try. For anything touching authentication, payments, or shared state, expect to rewrite parts of it yourself.

Many teams now run this inside their existing editor or terminal, so the generated code lands directly in the project and goes through the normal review and test pipeline. That pipeline is what turns a raw AI draft into code you can actually ship.

Step by step

  1. Describe the function or feature in plain language: input, output, and edge cases.
  2. Add relevant existing code, API documentation, or style conventions as context.
  3. Let AI write a first version and read the code line by line.
  4. Run the code, execute the tests, and confirm any suggested libraries or functions really exist.
  5. Have a colleague review the logic and security before you merge it.
  6. Document what AI wrote and what you changed, for future maintenance.

Where it breaks down

AI sometimes invents libraries, functions, or parameters that do not exist, and it writes code that compiles but still contains vulnerabilities, such as missing input validation or unsafe query construction. The model does not know your architecture, your business rules, or the decisions your team made six months ago, unless you spell them out in the prompt. Without that context, generated code often looks correct while missing something only a human on the team would know.

Because of this, you run the code, execute the tests, and check that any suggested library or function actually exists before you trust it. A second person reviews the logic and security before anything merges into production. For sensitive systems (payments, personal data, authentication), human review stays mandatory, not optional.

A prompt to start with

Prompt for generating a code function with AI

Write a [language] function called [function name] that does the following: [describe the goal in plain language]. Input: [describe expected input, types, and format]. Output: [describe expected output]. Handle these edge cases: [list edge cases, e.g. empty input, null values, invalid types]. Follow this style/convention: [paste style guide or example code]. Do not use libraries other than: [list allowed libraries, or 'standard library only']. After the code, list any assumptions you made.

Jobs where this task is shifting

Which of your tasks can AI take over?

The free scan builds your personal task map in 30 seconds.

Run the free task scan

Frequently asked questions

Can AI write an entire application by itself?

Not reliably. AI can generate individual functions, scripts, or small modules well, but stitching those into a full application requires decisions about architecture, data flow, error handling, and how components depend on each other. Those decisions need context the model does not have unless you provide it in detail. For small, well-defined tools, AI can produce most of the code, but someone still has to design the overall structure, test it end to end, and take responsibility for what ships.

Is AI-generated code safe to use in production?

Only after review. AI-generated code can compile and run correctly while still containing security gaps, such as missing input validation, unsafe query construction, or outdated dependencies. It can also reference libraries or functions that do not exist. Before anything reaches production, run the code, execute your test suite, and have a second person review the logic and security. For systems handling payments, personal data, or authentication, this review is not optional.

Does AI replace the need to learn programming?

No. AI works best as a tool for someone who already understands what correct code looks like, because you need to judge whether its output is right, secure, and appropriate for your system. Without that background, it becomes harder to catch invented functions, subtle logic errors, or security issues. Learning to program still matters. AI changes how much of the routine writing you do yourself, not whether you need to understand the code you ship.

Sources

This article was drafted with AI assistance and editorially reviewed.