t27.aiEnglish

Описать, запустить, проверить

Вы узнаете

Вайбкодинг - это цикл из трёх шагов: вы описываете, что хотите, программа запускается, а проверка отвечает да или нет.

Вайбкодинг значит, что вы описываете простыми словами, чего хотите, а ИИ-агент пишет программу. На этом ваша часть не заканчивается. Вы запускаете программу и сверяете результат со своим описанием, потому что программа может завершиться без ошибки и всё равно быть неверной. В спеке этого урока счёт в кафе - это число напитков, умноженное на цену одного: 3 напитка по 4 - это 12. Запуск, который складывает вместо умножения, печатает 7, спокойно завершается, и проверка его отвергает. Проверка - это тест, и тест судит результат, а не человека и не программу, которая его написала.

Попробуйте

Откройте спек в плеере и запустите: 3 теста проходят. Потом поменяйте RAN_TAB с 12 на 7 и запустите снова: тест the_run_matches_the_wish краснеет. Верните 12 на место.

Открыть интерактивный урок →

Vibecoding 1: describe, run, check ↗

A wish in plain words, a run that prints a number, and a check that says yes or no. A run that only looks fine is rejected. Lesson 1 of the vibecoding course.

specs/vibecoding/describe_run_check.t27

// SPDX-License-Identifier: Apache-2.0
; Vibecoding lesson 1: describe, run, check.
; You describe what you want, a program runs, and a test judges the result.
; The test is the part that does not take the program's word for it.

module vc_describe_run_check;

; 1. DESCRIBE: the wish, in plain words, written before any code.
pub const WISH : str = "A cafe tab is the number of drinks times the price of one drink. Change is the money paid minus the tab.";
pub const STEPS : [3]str = ["describe", "run", "check"];

; 2. RUN: the program an agent could write from that wish.
pub fn tab(drinks: u16, price: u16) -> u16 {
    return drinks * price;
}

pub fn change(paid: u16, owed: u16) -> u16 {
    return paid - owed;
}

; The inputs of one example, and what the run printed for tab(3, 4) and change(20, 12).
pub const DRINKS : u16 = 3;
pub const PRICE : u16 = 4;
pub const PAID : u16 = 20;
pub const RAN_TAB : u16 = 12;
pub const RAN_CHANGE : u16 = 8;

; A run that finishes without an error and is still wrong: the sum instead of the product.
pub const WRONG_RAN_TAB : u16 = 7;

; 3. CHECK: the test says yes or no against the wish, not against the program.
test the_run_matches_the_wish {
    assert RAN_TAB == DRINKS * PRICE;
    assert RAN_CHANGE == PAID - DRINKS * PRICE;
}

test the_check_rejects_a_run_that_only_looks_fine {
    assert WRONG_RAN_TAB == DRINKS + PRICE;
    assert WRONG_RAN_TAB != DRINKS * PRICE;
}

test three_steps_in_order {
    assert STEPS[0] == "describe";
    assert STEPS[1] == "run";
    assert STEPS[2] == "check";
}

Открыть спеку урока в плеере ↗

Все уроки