Write the project promise: full examples and further reading
The original lesson material is preserved here for reference. The main notebook focuses on this lesson's core question.
The original English project below is a log cleaner. The current notebooks use the same file-statistics project as the Chinese route. These preserved examples show another application of the concepts; their inputs and expected outputs belong to the log cleaner.
Turn a log-cleaner idea into exact input, output, and error examples.
Write three acceptance examples before creating project modules.
Run this first
Run it once, change one input, and compare the new result.
%% Describe observable behavior before modules
Examples = [
#{input => <<" INFO ready ">>, output => {ok, {info, <<"ready">>}}},
#{input => <<>>, output => skip},
#{input => <<"BROKEN">>, output => {error, invalid_line}}
],
length(Examples).The brief contains 3 executable examples.
Steps for the full example
- Read
#{input => ..., output => ...}: Store one executable example as a map. - Read
skip: Label a line the project intentionally ignores. - Read
invalid: Label input the project must report.
Original lesson notes
Run the example first. Predict one result, then change one input and run it again.
A concrete input and expected output makes a requirement testable.
Scope records what this small project will and will not do.
Symbols and terms
#{input => ..., output => ...}- Store one executable example as a map.
skip- Label a line the project intentionally ignores.
invalid- Label input the project must report.
- acceptance example
- A concrete input and expected output makes a requirement testable.
- scope
- Scope records what this small project will and will not do.
- invariant
- An invariant is a rule that must hold for every accepted result.
Original full exercise
Add an example for WARN hot.
#{input => <<"WARN hot">>, output => ____}Use {ok,{warn,<<"hot">>}}.
Show hint
Keep the same tagged tuple shape.
Show original answer
#{input => <<"WARN hot">>, output => {ok, {warn, <<"hot">>}}}Why write examples before modules?
They keep implementation choices from quietly changing promised behavior.
Original lesson takeaways
- Start with observable examples.
- Keep the first scope small.
- Write invariants before optimizations.