Learn Go with AI · Free online book
Appendix C: The SURE loop at a glance
In short: Appendix C puts the whole method on one page: the one rule (be SURE you can explain it), the four SURE steps, the check command and how to commit. Keep it open while you work.
Keep these pages open while you work. Every command here was run for this edition (Go 1.27.4).
The one rule
If you hit a line you can’t explain, go back to Use the AI and ask about it until you can. That’s not a failure. That’s the loop working.
The four steps
- Specify. Before you talk to the AI, decide what “done” looks like. Write it down. (In
SPEC.md; from Chapter 2 on, also as a test that fails.) - Use the AI. Ask the AI to explain, help or build, depending on the chapter. Give it what you wrote down. (Commit first.)
- Review. Let Go check the code first: the compiler, the formatter, the tests. Then read the code yourself until you can explain every line.
- Explain. Say what you built in your own words, note what you learned, and let the AI quiz you. (Commit with a
Learned:line.)
Use the AI and Review get the work done. Specify and Explain are the steps that make you smarter. Don’t skip them.
The AI’s role: tutor (it explains, you type) → pair (you write, it reviews) → implementer (you write the tests and review the code, it writes the code).
The check command
go run ./check runs gofmt -l . → go vet ./... → go test ./... → govulncheck ./..., stopping at the first failure. govulncheck must be installed (Appendix A.1) and needs the internet. If goroutines share the code, also run go test -race ./...; it may need a C compiler (Chapter 7; on Windows, Appendix A.10).
Reviewing the AI’s code and deciding on its suggestions: Appendix D.
Committing
git add .
git commit -m "<what changed>" -m "Learned: <your sentence>"
Before you paste anything into a chat, check “What not to give the AI” (Appendix A.8).