---
title: No Unused Variables
impact: LOW
impactDescription: reduces codebase noise and potential bugs
tags: variables, cleanup, quality
---

## No Unused Variables

Unused variables clutter the code and often indicate a bug (missing logic). Go compiler strictly enforces this for local variables.

**Incorrect (unused variables):**

```go
func Calculate(a, b int) int {
	result := a + b
	temp := result * 2 // UNUSED
	
	return result
}
```

**Correct (clean code):**

```go
func Calculate(a, b int) int {
	return a + b
}

// If a variable is needed for its side effect but the value is not, use _
_, err := os.Open("file.txt")
```

**Tools:** Go Compiler, `go vet`, GolangCI-Lint (unused)
