#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.
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.
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.
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.
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
Related videos
- #169 Write Coding-Assistant Rules That Work AI coding and productivity
- #171 TDD With an AI Assistant: Red, Green, Refactor (unittest) AI coding and productivity
- #172 Refactor Safely With AI: Characterisation Tests (pytest) AI coding and productivity
- #174 Review AI-Generated Code Fast: Checklist vs Bandit vs Tests AI coding and productivity
