~/talk

Inception: Go programs that generate Go code

links:none on file
slides:none on file

Shows techniques for reducing boilerplate in Go by writing programs that generate Go source code. Covers multiple approaches to building code generators for Go programs, illustrating how to produce the repetitive code automatically.

AI-written summary · about

  1. 0:00Intro
  2. 0:33and the stdlib is amazing
  3. 1:21reducing boilerplate
  4. 1:55Parsing data to generate Go code
  5. 4:17Modifying Go code
  6. 4:38a big part of Go's brilliant tooling
  7. 5:04powered by the stdlib
  8. 5:23import "go/scanner" import "go/parser" // read and parse to source code
  9. 6:02import "go/printer" // generating code from AST nodes
  10. 6:32Parse Go code to generate Go code
  11. 7:49generating mocks
  12. 9:53$ go generate
  13. 12:03go/ast provides very raw data
  14. 13:19generating any mock
  15. 14:34tens of assertion helpers
  16. 15:363 boilerplate functions per each assertion
  17. 16:48go/types go/doc
  18. 17:24codegen: 239 lines of code removed: 839 lines of code
  19. 19:35avoid goimports on generated code
  20. 20:25Generating decoders
  21. 21:02import "reflect"
  22. 22:31Read code Analyze code Generate code and tests
  23. 23:19Go DSLS (Domain-Specific Languages)
  24. 24:41How does goa do it?
  25. 24:54Magic
  26. 25:37you can reduce boilerplate
  27. 25:52stdlib has great packages to build your own tools
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.