Dynamically scoped variables in Go

1 · Dave Cheney · Dec. 8, 2019, 2:16 a.m.
Summary
This is a thought experiment in API design. It starts with the classic Go unit testing idiom: func TestOpenFile(t *testing.T) { f, err := os.Open("notfound") if err != nil { t.Fatal(err) } // ... } What’s the problem with this code? The assertion. if err != nil { ... } is repetitive and in the […]...