Microblog: TestMain can cause one to question reality
A debugging story about a Go test suite failing silently due to a commented-out line in TestMain, causing confusion and a frantic search for the bug.
Dave Cheney explores Go programming with practical examples, pop quizzes, and deep dives into performance, correctness, and real-world pitfalls in software development.
15 articles from this blog
A debugging story about a Go test suite failing silently due to a commented-out line in TestMain, causing confusion and a frantic search for the bug.
Explains a surprising heap allocation in a Go benchmark when sorting strings, diving into interface internals and compiler behavior.
A developer's reflection on how writing a test for a simple one-line bug fix can become a complex, time-consuming task.
Explains how to use the GOSSAFUNC environment variable to generate SSA debugging output for Go functions and methods.
Explains Go 1.14's new feature allowing embedding of interfaces with overlapping method sets, solving diamond composition issues.
Explains why Go's json.Unmarshal behaves differently when passed a pointer variable vs. the address of a pointer, clarifying pointer mechanics.
Explores how prohibiting comparisons on Go struct types can reduce binary size by eliminating equality functions and padding.
Explains the limits of function inlining in Go, including the inlining budget and trade-offs between binary size and performance.
Explains how the Go compiler implements inlining, its importance for performance, and the mechanics of function call overhead.
Explains the Go 1.14 improvement where `go test -v` streams `t.Log` output in real-time, aiding debugging of long-running tests.
Explains that assigning large slices in Go is not more expensive than small ones, as all slices are the same size (three machine words).
Explores the philosophy of writing good, idiomatic Go code, questioning common mantras and seeking better principles for the community.
Explores using dynamically scoped variables in Go to improve test helper APIs, reducing boilerplate and passing of testing.T.
Explores using three complementary metrics—delivery date accuracy, feature completeness, and defect rates—to measure software team health and prevent gaming single metrics.
Explains how to use Go's internal/ directory to create private packages, reducing a project's public API surface and improving design.