Skip to content
griesemer-precise-go logo

Robert Griesemer Style Guide

griesemer-precise-go

Write Go code in the style of Robert Griesemer, co-creator of Go. Emphasizes clean syntax, precise semantics, and well-defined type system behavior. Use when designing APIs, type hierarchies, or code that requires precise specification.

SKILL.md

Full skill instructions

Robert Griesemer Style Guide

Overview

Robert Griesemer co-created Go and was the primary designer of Go's generics. He previously worked on the V8 JavaScript engine and the Java HotSpot VM. His focus: precise semantics, clean syntax, and type system clarity.

Core Philosophy

"The language should help you think clearly."

"Every feature adds complexity. Is the complexity worth it?"

Griesemer values precision and clarity. Go's spec is remarkably small and clear because every construct has well-defined semantics.

Design Principles

  1. Precise Semantics: Every language construct has exactly one meaning.

  2. Orthogonal Features: Features should combine predictably.

  3. No Surprises: Behavior should be obvious from reading the code.

  4. Spec-Driven: If it's not in the spec, it's not guaranteed.

When Writing Code

Always

  • Understand the exact semantics of operations
  • Use types to express constraints
  • Make nil behavior explicit and safe
  • Write code that matches Go's spec, not implementation details
  • Use generics when type safety improves clarity
  • Define clear type constraints

Never

  • Rely on unspecified behavior
  • Assume implementation details (memory layout, etc.)
  • Create ambiguous APIs
  • Use empty interface when a constraint works
  • Ignore the distinction between value and pointer receivers

Prefer

  • Explicit type constraints over any
  • Named types for domain concepts
  • Method receivers that match semantics (value vs pointer)
  • Clear zero values

Code Patterns

Generics Done Right (Go 1.18+)

// BAD: Empty interface loses type safety
func Max(a, b interface{}) interface{} {
    // runtime type assertion needed
    switch v := a.(type) {
    case int:
        if v > b.(int) { return v }
        return b
    // ... repeat for every type
    }
    panic("unsupported type")
}

// GOOD: Type constraints preserve safety
type Ordered interface {
    ~int | ~int8 | ~int16 | ~int32 | ~int64 |
    ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
    ~float32 | ~float64 | ~string
}

func Max[T Ordered](a, b T) T {
    if a > b {
        return a
    }
    return b
}

// Usage: type-safe, no assertions
result := Max(3, 5)        // int
result := Max(3.14, 2.71)  // float64

Precise Type Constraints

// Constraint: any type with these methods
type Stringer interface {
    String() string
}

// Constraint: underlying type is int
type Integer interface {
    ~int | ~int64
}

// Constraint: must be pointer to struct with Name field
type Named[T any] interface {
    *T
    GetName() string
}

// Combining constraints
type OrderedStringer interface {
    Ordered
    Stringer
}

// Generic data structure with constraint
type Set[T comparable] struct {
    items map[T]struct{}
}

func (s *Set[T]) Add(item T) {
    if s.items == nil {
        s.items = make(map[T]struct{})
    }
    s.items[item] = struct{}{}
}

func (s *Set[T]) Contains(item T) bool {
    _, ok := s.items[item]
    return ok
}

Value vs Pointer Semantics

// Value receiver: method doesn't modify, type is small
type Point struct {
    X, Y float64
}

func (p Point) Distance(q Point) float64 {
    dx := p.X - q.X
    dy := p.Y - q.Y
    return math.Sqrt(dx*dx + dy*dy)
}

// Pointer receiver: method modifies, or type is large
func (p *Point) Scale(factor float64) {
    p.X *= factor
    p.Y *= factor
}

// IMPORTANT: Be consistent within a type
// If ANY method needs pointer receiver, use pointer for ALL
type Buffer struct {
    data []byte
}

func (b *Buffer) Write(p []byte) (int, error) {
    b.data = append(b.data, p...)
    return len(p), nil
}

func (b *Buffer) String() string {  // Also pointer, for consistency
    return string(b.data)
}

Safe Nil Handling

// Make nil receiver safe
type Stack[T any] struct {
    items []T
}

func (s *Stack[T]) Push(item T) {
    if s == nil {
        panic("nil stack")  // Or return error
    }
    s.items = append(s.items, item)
}

func (s *Stack[T]) Len() int {
    if s == nil {
        return 0  // Safe: nil stack has zero length
    }
    return len(s.items)
}

// Named types for clarity
type UserID int64
type OrderID int64

// Now these can't be accidentally swapped
func GetOrder(uid UserID, oid OrderID) (*Order, error) {
    // ...
}

Precise Interface Design

// Small, precise interfaces
type Reader interface {
    Read(p []byte) (n int, err error)
}

type Writer interface {
    Write(p []byte) (n int, err error)
}

type Closer interface {
    Close() error
}

// Compose precisely
type ReadCloser interface {
    Reader
    Closer
}

type WriteCloser interface {
    Writer
    Closer
}

type ReadWriteCloser interface {
    Reader
    Writer
    Closer
}

// Generic interface with type parameter
type Container[T any] interface {
    Add(T)
    Remove(T) bool
    Contains(T) bool
    Len() int
}

Mental Model

Griesemer designs by asking:

  1. What does the spec say? Not the implementation—the specification.
  2. Is this unambiguous? Can two people read this differently?
  3. What are the edge cases? nil, zero values, overflow?
  4. Is the type constraint minimal? Don't over-constrain.

Spec-Level Thinking

FeatureSpec Guarantee
Map iterationRandom order
Goroutine schedulingUnspecified
Struct layoutUnspecified
String indexingBytes, not runes
Interface nilnil interface ≠ interface holding nil

Write code that works regardless of implementation details.

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

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...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

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...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

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.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View