learning-it by example

#180 AI coding and productivity 6.3 min

Spec-Driven Development: Write the Spec First

A quick first try passed 1 of 7 spec rules; code written to the spec passed 7 of 7.

1. What does spec driven development mean at the first level the video uses, spec first?
2. The seven-rule spec for make_slug was turned into checks. How many rules did the quick first try pass, and how many did the version written rule by rule pass?
3. The spec has a question nobody could answer: what about accented letters? What does the video, following Spec Kit, advise for a gap like this?
4. In the spec driven make_slug example, how does check.py decide that a rule has failed?
5. Why does the video say that 7 of 7 passing checks are not proof that make_slug is right?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. Run the checks on both versions

    Copy the code folder first. Predict how many of the 7 rules each version passes, then run python run.py. When I ran it, first_try passed 1 of 7 and slug.py passed 7 of 7, and one open question was listed as not checked.

    A hint

    The first try only lower cases the title and swaps spaces for dashes.

  2. Add a rule to the spec

    Add a new line at the end of the rules in spec.txt: R8 | keep one letter | A | a. Predict how many rules each version passes now, then run python run.py. When I ran it, the spec showed 8 rules, first_try passed 2 of 8 and slug.py still passed 8 of 8.

    A hint

    Keep the same bar-separated shape as the other rules: id, meaning, input, expected output.

  3. Make the length limit shorter

    In slug.py, change MAX_LENGTH from 20 to 10. Predict which rules of the spec now fail, then run python run.py. When I ran it, slug.py passed 4 of 7 and R1, R5 and R6 failed, for example the title Hello World came back as hello.

    A hint

    A slug longer than the limit is cut at a whole word, so check which expected outputs are longer than 10 characters.

  4. Find a case the spec does not cover

    Put MAX_LENGTH back to 20. Add a rule to spec.txt: R9 | a long single word | Supercalifragilisticexpialidocious | supercalifragilisticexpialidocious. Predict whether slug.py passes it, then run python run.py. Keep the R8 line from the earlier exercise, so the spec has 9 rules (without it the spec has 8 rules and slug.py passes 7 of 8). When I ran it with R8 kept, slug.py passed 8 of 9 and R9 failed because the word came back as untitled. The video says no rule decided whether that is right, so decide for yourself what the spec should say.

    A hint

    No word fits in 20 characters, so the slug stays empty and the function returns untitled.

These tasks are for you to try on your own machine. Nothing is checked or saved.

What this does not show

Both versions of the function are hand-written for this video; no assistant wrote any code, so this does not test how well an assistant follows a spec.

Up next in AI coding and productivity

More in AI coding and productivity

All AI coding and productivity videos

Related videos