Skip to content
Back to skills

Slice

ASecurity

Slice zero-value behavior - nil slice is usable

  • 3 stars
  • 0 votes
  • 0 copies
  • 17 views
  • Added February 7, 2026
developmentgo

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add JamesPrial/claudefiles --skill slice --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Slice?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Slice
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/jamesprial-slice/badge)](https://www.skillsdirectory.com/skills/jamesprial-slice)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

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

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.