Back to list
JamesPrial

go-nil-slice

by JamesPrial

WIP - collection of various Claude stuff i make/use/have_Claude_hallucinate

2🍴 0📅 Jan 23, 2026

SKILL.md


name: go-nil-slice description: Slice zero-value behavior - nil slice is usable

Slice Zero-Value

Problem

Nil slices are valid and usable, but behavior differs from empty slices.

Pattern

CORRECT - Nil slice works with append

var s []int  // nil slice
s = append(s, 1, 2, 3)  // OK, creates new backing array
fmt.Println(s)  // [1 2 3]

Nil vs Empty Slice

var nilSlice []int           // nil slice
emptySlice := []int{}        // empty slice (non-nil)

len(nilSlice) == 0           // true
len(emptySlice) == 0         // true

nilSlice == nil              // true
emptySlice == nil            // false

json.Marshal(nilSlice)       // "null"
json.Marshal(emptySlice)     // "[]"

When It Matters

// JSON encoding differs
type Response struct {
    Items []string  // Will encode as null if nil, [] if empty
}

Quick Fix

  • Nil slices work with append, len, range
  • Use nil for "no data", []T{} for "empty data"
  • Check JSON encoding behavior if needed

Score

Total Score

65/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

1ヶ月以内に更新

+10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

Reviews

💬

Reviews coming soon