xiaohongshu
xiaohongshu
kennedy-mechanical-sympathy
Write Go code in the style of Bill Kennedy, author of Go in Action. Emphasizes mechanical sympathy, data-oriented design, and understanding how Go code executes. Use when writing performance-critical Go or when teaching Go fundamentals.
Full skill instructions
Bill Kennedy is the author of "Go in Action" and founder of Ardan Labs. His teaching emphasizes mechanical sympathy: understanding how software interacts with hardware. His "Ultimate Go" course is legendary for deep-dive explanations.
"Integrity, readability, and simplicity—in that order."
"If you don't understand the data, you don't understand the problem."
"Mechanical sympathy: understanding how the hardware and runtime work."
Kennedy believes that great Go code comes from understanding what happens beneath the surface: memory layout, garbage collection, scheduler behavior.
Data-Oriented Design: Design around data transformations, not object hierarchies.
Mechanical Sympathy: Write code that works with the hardware, not against it.
Value Semantics First: Prefer values over pointers unless you have a reason.
Integrity First: Correctness beats performance, readability beats cleverness.
// BAD: Object-oriented thinking, pointer-heavy
type Node struct {
Value int
Children []*Node // Pointers scattered in memory
}
// GOOD: Data-oriented, cache-friendly
type Tree struct {
Values []int // Contiguous memory
Children [][]int // Indices into Values
}
// For hot loops, struct of arrays beats array of structs
// BAD: Array of structs (AoS)
type Particle struct {
X, Y, Z float64
VX, VY, VZ float64
Mass float64
}
particles := make([]Particle, 1000)
// GOOD: Struct of arrays (SoA) - better cache utilization
type Particles struct {
X, Y, Z []float64
VX, VY, VZ []float64
Mass []float64
}
p := Particles{
X: make([]float64, 1000),
Y: make([]float64, 1000),
// ...
}
// When updating just positions:
for i := range p.X {
p.X[i] += p.VX[i] // Sequential memory access
p.Y[i] += p.VY[i]
p.Z[i] += p.VZ[i]
}
// Value semantics: type is small, immutable logically
type Time struct {
sec int64
nsec int32
}
func (t Time) Add(d Duration) Time {
return Time{sec: t.sec + int64(d), nsec: t.nsec}
}
// Pointer semantics: type represents a resource or is large
type File struct {
fd int
name string
// ...
}
func (f *File) Read(b []byte) (int, error) {
// Modifies state, represents resource
}
// RULE: Pick one semantic and be consistent for a type
// If any method needs pointer, use pointer for all methods
// Stack allocation: fast, automatic cleanup
func sumLocal() int {
numbers := [4]int{1, 2, 3, 4} // Array on stack
sum := 0
for _, n := range numbers {
sum += n
}
return sum // numbers never escapes
}
// Heap allocation: slower, needs GC
func sumHeap() *int {
sum := 0
for i := 0; i < 4; i++ {
sum += i
}
return &sum // sum escapes to heap!
}
// Check with: go build -gcflags="-m"
// ./main.go:10:2: moved to heap: sum
// Slices and interfaces often cause escapes
func process(data []byte) {
// If data is used after function returns
// or passed to interface{}, it may escape
}
// Struct padding wastes memory
// BAD: Poor layout (24 bytes with padding)
type BadLayout struct {
a bool // 1 byte + 7 padding
b int64 // 8 bytes
c bool // 1 byte + 7 padding
}
// GOOD: Optimized layout (16 bytes)
type GoodLayout struct {
b int64 // 8 bytes
a bool // 1 byte
c bool // 1 byte + 6 padding
}
// Check with: unsafe.Sizeof()
// Or use: go vet -fieldalignment
// Slice header: (pointer, length, capacity)
// Understanding this prevents bugs
func modify(s []int) {
s[0] = 999 // Modifies original!
s = append(s, 4) // May or may not affect original
}
func main() {
original := []int{1, 2, 3}
modify(original)
// original[0] is 999
// but append may have created new backing array
}
// Safe pattern: return the slice
func appendSafe(s []int, v int) []int {
return append(s, v)
}
original = appendSafe(original, 4)
func BenchmarkProcess(b *testing.B) {
// Setup outside the loop
data := generateTestData()
b.ResetTimer() // Don't count setup time
for i := 0; i < b.N; i++ {
result := Process(data)
// Prevent compiler from optimizing away
_ = result
}
}
// Compare implementations
func BenchmarkProcessV1(b *testing.B) { ... }
func BenchmarkProcessV2(b *testing.B) { ... }
// Run with: go test -bench=. -benchmem
// BenchmarkProcessV1-8 1000000 1234 ns/op 256 B/op 3 allocs/op
// BenchmarkProcessV2-8 2000000 567 ns/op 0 B/op 0 allocs/op
type Pool struct {
work chan func()
sem chan struct{}
}
func NewPool(size int) *Pool {
p := &Pool{
work: make(chan func()),
sem: make(chan struct{}, size),
}
return p
}
func (p *Pool) Submit(task func()) {
select {
case p.work <- task:
// Worker picked it up
case p.sem <- struct{}{}:
// Start new worker
go p.worker(task)
}
}
func (p *Pool) worker(task func()) {
defer func() { <-p.sem }()
for {
task()
task = <-p.work
}
}
Kennedy teaches by asking:
In that order.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience