learning-it by example

#169 AI coding and productivity 6.4 min

Write Coding-Assistant Rules That Work

Two of my seven rules could not be checked; a script checks the other five.

1. What does the video say makes a rule for a coding assistant worth writing?
2. In a Python script that checks five concrete rules from a rules file, how many did the hand-written before and after files pass?
3. Does the video show that a coding assistant follows concrete rules better than vague ones?
4. How does the video's check for the rule about no print calls work?
5. The Claude Code docs say a rules file is context, not enforced configuration. What does the video say to do with a rule that must never be broken?

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

  1. Break the after file

    Copy the code folder first. In after.py delete the docstring line inside apply_discount. Predict which rule fails, then run python run.py. On my machine the after line said 4 of 5 rules pass, failed R3.

    A hint

    The docstring check asks Python for each function's docstring.

  2. Find the gap in the key rule

    In after.py change the default in os.environ.get("SHOP_KEY", "") to "abc123". Predict whether R4 still passes, then run python run.py. Next replace the whole line with SHOP_KEY = "abc123", then with SHOP_TOKEN = "abc123", and run each time. On my machine the first and third versions passed 5 of 5 and the second failed R4.

    A hint

    The key check looks for the capital letters KEY followed by an equals sign and a quote.

  3. Add a sixth concrete rule

    Add the line - R6 Function names are lower case to the concrete section of RULES.md. In checks.py write r6 with the same two arguments as the other checks, using ast.walk to find every FunctionDef and checking that name == name.lower(), and add it to CHECKS. Run python run.py. On my machine before.py then passed 1 of 6 and after.py passed 6 of 6.

    A hint

    Copy the shape of r3_docstrings, which also collects FunctionDef nodes.

  4. Turn a vague rule into a check

    Think of a vague rule you might give an assistant, such as keep functions short. Rewrite it as a concrete rule with a number, add it to RULES.md as R7, and write a check for it in checks.py. Then run python run.py on before.py and after.py and see which files pass.

    A hint

    Each check must answer pass or fail from the code text and the parsed tree. A line count per function needs end_lineno on each FunctionDef.

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

What this does not show

The before and after files are hand-written examples, not output from any assistant; no assistant was run.

Up next in AI coding and productivity

More in AI coding and productivity

All AI coding and productivity videos

Related videos