---
title: Do Not Use Dead Code
impact: LOW
impactDescription: reduces codebase noise and maintenance burden
tags: dead-code, cleanup, maintenance, quality
---

## Do Not Use Dead Code

Dead code confuses readers and increases cognitive load. Git history preserves deleted code.

**Incorrect (keeping dead code):**

```go
func ProcessOrder(order *Order) float64 {
	// Old implementation - keeping for reference
	// total := 0.0
	// for _, item := range order.Items {
	// 	total += item.Price * float64(item.Quantity)
	// }
	// return total

	total := calculateTotal(order)
	return total
}

// Unused function - someone might need it later
func legacyCalculation() { }
```

**Correct (clean code):**

```go
func ProcessOrder(order *Order) float64 {
	return calculateTotal(order)
}

// Delete unused functions - git history preserves them
// Delete commented code - git history preserves it
```

**Types of dead code:**
- Commented-out code
- Unused functions/structs/methods
- Unreachable code
- Unused variables (Go compiler will error on these locally, but they may exist in long-lived branches)

**Tools:** gofmt, govet, staticcheck, GolangCI-Lint
