Refactoring Go Programs
Guidelines and techniques for evolving your code.
Roger Peppe
Canonical Ltd
Roger Peppe
Canonical Ltd
func foo(x int) { }
renaming to:
func bar(x int) { }
func Foo(x int) { }
renaming to:
func Bar(x int) { }
func x(i int) string { return y("something", i) } func y(s string, n int) string { return s + strings.Repeat("foo", i)) }
->
type repeater struct { count int } func (r *repeater) x(i int) string { r.count++ return y("something", i) } func (r *repeater) y(i int, s string) string { r.count++ return s + strings.Repeat("foo", i)) }
func x(i int, c counter) string { c.inc() return y(i, c) }
gofmt -w -r 'Foo(x, y) -> Foo(x, y, nil)' .
sam -d *.go
doc.cat-v.org/bell_labs/sam_lang_tutorial/sam_tut.pdf
18govers -m github.com/foo/bar github.com/me/bar
e.g.
if err := foo(bar); err != io.EOF { return err }
->
if err := foo(bar); errgo.Cause(err) != io.EOF { return errgo.Mask(err) }