Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Go generate everything

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

Go generate everything

Avatar for Alexey Palazhchenko

Alexey Palazhchenko

November 08, 2016
Tweet

More Decks by Alexey Palazhchenko

Other Decks in Programming

Transcript

  1. Зачем? • Парсеры, лексеры • Конвертация данные (Unicode-таблицы) • Встраивание

    бинарных данных • Bailerplate, автодополнение в редакторе
  2. Зачем? • Парсеры, лексеры • Конвертация данные (Unicode-таблицы) • Встраивание

    бинарных данных • Bailerplate, автодополнение в редакторе • Mocks
  3. Зачем? • Парсеры, лексеры • Конвертация данные (Unicode-таблицы) • Встраивание

    бинарных данных • Bailerplate, автодополнение в редакторе • Mocks • Generics?!
  4. Как? • go/build • go/token, go/scanner • go/ast, go/parser •

    go/constants, go/types • go/printer, go/format
  5. github.com/josharian/impl $ impl 'c *Connected' events.Event func (c *Connected) String()

    string { panic("not implemented") } func (c *Connected) Type() string { panic("not implemented") }
  6. golang.org/x/tools/cmd/stringer $ stringer -type Type func (i Type) String() string

    { i -= 1 if i < 0 || i >= Type(len(_index)-1) { return fmt.Sprintf("Type(%d)", i+1) } return _name[_index[i]:_index[i+1]] }
  7. Generics func NewQueue() *Queue { return &Queue{items: make([]T, 0)} }

    func (q *Queue) Push(item T) {} func (q *Queue) Pop() T {}