go-data-idioms
Skill0 starsChanged 40 days agoMITView on GitHub
Use when working with Go slices, maps, defer, or named returns — covers new vs make, slice capacity and backing-array aliasing, append reallocation, defer LIFO and argument-capture timing, named returns mutated by defer, and zero-value-useful design
In this repository66 other files it gives its agents.
- AGENTS.mdAGENTS.md
- postgres-locking-joinsSkill
- ai-bug-patternsSkill
- compressed-ndjson-boundariesSkill
- http-resume-integritySkill
- linux-io-latency-triageSkill
- macos-disk-space-recoverySkill
- minimal-sufficient-evidenceSkill
- modularize-large-filesSkill
- patch-reproducer-validitySkill
- prompt-cache-boundariesSkill
- proton-drive-selective-backupSkill
- transactional-outbox-deliverySkill
- conventional-commitsSkill
- git-advanced-mergingSkill
- git-bisect-forensicsSkill
- git-data-recoverySkill
- git-hooksSkill
- git-rerereSkill
- git-reset-mechanicsSkill
- git-revisions-syntaxSkill
- git-rewriting-historySkill
- git-submodulesSkill
- git-worktreesSkill
- github-ssh-keysSkill
- npm-publish-ci-pitfallsSkill
- sapling-stacked-pr-workflowSkill
- go-concurrency-patternsSkill
- go-error-handlingSkill
- go-interfaces-embeddingSkill
- go-pprof-profilingSkill
- marketing-funnel-diagnosisSkill
- marketing-geo-experimentsSkill
- marketing-incrementalitySkill
- marketing-positioning-testsSkill
- python-descriptors-mroSkill
- python-logging-cookbookSkill
- python-scaling-regression-testsSkill
- python-unicode-gotchasSkill
- rust-compile-time-invariantsSkill
- rust-deterministic-concurrency-testsSkill
- rust-error-identity-boundariesSkill
- rust-regex-search-contractsSkill
- rust-runtime-bug-classesSkill
- rust-tokio-actor-deliverySkill
- rust-tokio-cancellation-safetySkill
- sales-discovery-qualificationSkill
- sales-mutual-action-plansSkill
- sales-pipeline-forecast-calibrationSkill
- sales-value-negotiationSkill
- ai-triage-evaluationSkill
- container-image-patchingSkill
- dependency-artifact-integritySkill
- dnssec-sentinel-diagnosticsSkill
- iam-policy-change-replaySkill
- rbvm-applicabilitySkill
- rbvm-asset-evidenceSkill
- rbvm-guarded-remediationSkill
- rbvm-priority-decisionsSkill
- rbvm-risk-exceptionsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 83
deferin a loop: all defers run at function exit, not per iteration — handles accumulate.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Go Data Idioms
Slices are (ptr, len, cap) headers over a shared backing array; aliasing is the default. defer evaluates args at the defer site, not at return. Design types so the zero value is usable.
new vs make
| Call | Returns | For |
new(T) | *T, zeroed | structs, ints, arrays |
make(T, …) | T, initialized | slices, maps, channels |
new([]int) yields *[]int pointing to a nil slice — rarely useful. Use make([]int, n).
Slices: aliasing and append
s := []int{1, 2, 3, 4}
t := s[1:3] // shares backing; t[0]=9 mutates s[1]
u := append(s, 5) // may or may not reallocate
s = append(s, x) // MUST reassign
append(s, x) // lost — returned header discardedReallocation when len + added > cap. Before realloc, original and returned share memory; after, they don't. Treat the return as authoritative.
Maps: comma-ok for absence
v, ok := m[k] // ok=false means absent
_, ok := m[k] // presence-onlyMissing key silently returns zero value; without ok you cannot tell "absent" from "present and zero".
Defer: LIFO and argument capture
for i := 0; i < 3; i++ {
defer fmt.Println(i) // args evaluated NOW → 2, 1, 0
}
x := 1
defer func() { fmt.Println(x) }()
x = 2 // prints 2 — closure reads at call timeDirect-call defer captures args at the defer statement. A func(){} literal reads variables when it runs.
Named returns + defer = post-return mutation
func parse() (out T, err error) {
defer func() {
if err != nil { err = fmt.Errorf("parse: %w", err) }
}()
...
return // defer sees and rewrites err
}Works only with named returns. Defer runs after return operands evaluate, before control leaves the frame.
Zero-value-useful
type Buf struct {
mu sync.Mutex // zero: unlocked
buf bytes.Buffer // zero: empty, usable
}
var b Buf // no constructor neededPitfalls
- Forgetting to reassign
append: silent element loss when cap is exceeded. - Slice retention:
big[0:1]keeps the whole backing array alive.copyinto a fresh slice when keeping a small prefix. deferin a loop: all defers run at function exit, not per iteration — handles accumulate. Wrap iteration in a helper.- Closure vs argument capture:
defer f(x)captures x now;defer func(){ f(x) }()captures x at execution. - Nil map write panics:
var m map[string]int; m["k"] = 1panics. Alwaysmakebefore writing. - Two-dim slice allocation: one contiguous
make([]T, x*y)sliced into rows beats per-rowmakewhen rows have fixed size.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

