---
title: No Duplicate Variable Names in Scope
impact: MEDIUM
impactDescription: prevents shadowing and logic errors
tags: naming, clean-code, quality, python
---

## No Duplicate Variable Names in Scope

Reusing variable names in the same scope (shadowing) makes code hard to read and can lead to unexpected behavior.

**Incorrect:**
```python
def filter_data(df):
    df = df.filter(col("id") > 0)
    # Reusing 'df' name for a different purpose might be confusing if logic grows
    df = 10 
    return df
```

**Correct:**
```python
def filter_data(df):
    filtered_df = df.filter(col("id") > 0)
    count = 10
    return filtered_df
```
