Back to skills
SKILL.md
Slice
ASecuritySlice zero-value behavior - nil slice is usable
- 3 stars
- 0 votes
- 0 copies
- 17 views
- Added February 7, 2026
Security analysis
100/100npx -y skills add JamesPrial/claudefiles --skill slice --agent claude-codeAre you the author of Slice?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/jamesprial-slice)---
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
```go
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
```go
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
```go
// 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
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.