Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 6 min read

AI Can Write Code: 5 Things You Still Need to Learn

AI can write code for you now. But you still need to understand how software works, because you are the one who has to check the result. Here are five things worth learning. Each one has a plain example, a small piece o

AI can write code for you now. But you still need to understand how software works, because you are the one who has to check the result.

Here are five things worth learning. Each one has a plain example, a small piece of code you can try, and the tools to practise with. You do not need to become a developer. You need to know enough to ask the right question and to recognise a wrong answer.

1. Databases: how to store information

A database stores information in tables, like a set of very strict spreadsheets. An online shop has one table for customers, one for products and one for orders.

CREATE TABLE orders (
    id          SERIAL PRIMARY KEY,
    customer_id INT NOT NULL,
    product     TEXT NOT NULL,
    quantity    INT NOT NULL,
    created_at  TIMESTAMP DEFAULT now()
);

When an app becomes slow, the problem is often here. Imagine the shop wants all orders of one customer:

SELECT * FROM orders WHERE customer_id = 1042;

With 20 rows this is instant. With 2 million rows the database reads every single row to find the few that match. Think of a book with no page numbers and no table of contents: to find one line you read every page.

An index is the table of contents.

CREATE INDEX idx_orders_customer ON orders (customer_id);

With it, the database jumps straight to the right rows. The same query goes from seconds to milliseconds. AI rarely adds indexes on its own, because with test data the app is fast anyway.

Practise with: SQL on a small PostgreSQL database. Put 100,000 rows in a table, time a query, add an index, time it again.

2. Transactions: how to handle many users at once

An online shop has one phone left. Two customers press Buy in the same second.

The simple code checks the stock, then takes one away:

SELECT stock FROM products WHERE id = 7;      -- both customers see 1
UPDATE products SET stock = stock - 1 WHERE id = 7;

Both customers ran the first line before either ran the second. Both saw "1 in stock". Both orders go through, both get an order confirmation, and the stock is now minus one. One phone, two orders.

A transaction is a group of steps that either all happen or none happen, and that other users cannot cut into halfway.

BEGIN;
SELECT stock FROM products WHERE id = 7 FOR UPDATE;   -- locks the row
UPDATE products SET stock = stock - 1 WHERE id = 7 AND stock > 0;
COMMIT;

The second customer has to wait until the first one is finished, then sees stock 0 and gets "sold out". Only one customer gets the last phone.

Practise with: SQL transactions. Open two database windows and try to buy the same item from both.

3. Security basics: how to protect information

Three questions cover most of it.

Who can access the application? There must be a sign-in, and it should not be one you wrote yourself. Use an identity service such as Microsoft Entra ID, and turn on multi-factor authentication.

Who can see customer information? A normal employee should not see the company's financial records. Each person gets only the access their job needs. That idea is called least privilege, and on Azure it is done with role-based access control (RBAC): you give a person a role, and the role says what they may do.

Where are passwords and secret keys stored? This is the mistake AI-written code makes most often:

# Wrong: the secret sits in the code
db_password = "Sp8#kd!2x"

Code gets copied, shared, and uploaded to places you did not plan. Anyone who sees the code sees the password. The secret belongs in a vault, and the app asks for it when it runs:

# Right: the app reads the secret from Azure Key Vault at run time
from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient

client = SecretClient(vault_url="https://kv-contoso-lab.vault.azure.net",
                      credential=DefaultAzureCredential())
db_password = client.get_secret("db-password").value

Practise with: Microsoft Entra ID, RBAC and Key Vault in a free Azure lab subscription.

4. Testing: how to find mistakes

AI can write code, and it can also make mistakes. A test is a small piece of code that checks another piece of code, so you do not have to click through the app by hand every time.

Test the strange cases, not only the normal one. For a shopping app:

  • What happens when the price is zero?
  • What happens when the quantity is negative?
  • What happens when someone orders on 31 December?
  • What happens when two people buy the same product?
import pytest
from shop import total_price

def test_normal_order():
    assert total_price(price=30, quantity=2) == 60

def test_price_zero():
    assert total_price(price=0, quantity=3) == 0

def test_negative_quantity_is_rejected():
    with pytest.raises(ValueError):
        total_price(price=30, quantity=-1)

Ask AI to write the tests too. It is good at that. Then add the cases it missed, because it tends to test the same happy path it had in mind when it wrote the code.

Practise with: Pytest for code, Postman for testing a web API by hand.

5. Reading code: understand what AI creates

Never use code that you cannot explain. You do not need to remember every line, but for each piece you should be able to answer four questions:

  • What does this code do?
  • Where does the data come from?
  • What happens when something goes wrong?
  • Is the code safe?

A useful habit: after the AI gives you code, ask it to explain the code line by line, then close the chat and explain it yourself, out loud or in a comment. Where you get stuck is exactly the part you do not understand yet.

Practise with: Python for applications and PowerShell for administration scripts. Read other people's scripts before you run them.

What to practise with

Knowledge Tech to practise
Database SQL, PostgreSQL
Transactions SQL transactions
Security Microsoft Entra ID, RBAC, Key Vault
Testing Pytest, Postman
Reading code Python, PowerShell

A four-week plan

  • Week 1: install PostgreSQL, create the orders table above, load test data, and see what an index does.
  • Week 2: write the "last phone" transaction by hand and break it on purpose from two windows.
  • Week 3: put a tiny app behind Entra ID sign-in and move its password into Key Vault.
  • Week 4: write five tests for that app, including two strange cases, and explain every file of it to a friend.

After four weeks you will not be a senior engineer. You will be someone who can look at AI-written code and say "this part is wrong", which is the skill most people who build with AI do not have.

The short version

Use AI to work faster, but always check its work. AI can write the code. You are responsible for understanding the result. That is a skill worth learning.

Sources

Made by CD with love from VietNam. One short Microsoft security video a day at 20:00 (Vietnam time) on YouTube: CD Security Lab.

Thanks for reading! I'm Cuong, and on CD Security Lab I rebuild real Microsoft security cases in a safe lab and explain them simply. Follow along:

Got a question about your own tenant? Drop it in the comments.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.