---
title: Centralize Constants
impact: MEDIUM
impactDescription: improves maintainability and prevents magic strings
tags: maintenance, quality, python, pyspark
---

## Centralize Constants

Avoid "magic strings" or numbers scattered across the code. Centralize them in a config or constants file.

**Incorrect:**
```python
df = df.filter(col("status") == "ACTIVE") # Magic string
df.write.save("s3://my-bucket/output")     # Hardcoded path
```

**Correct:**
```python
# constants.py
ORDER_STATUS_ACTIVE = "ACTIVE"
OUTPUT_PATH = "s3://my-bucket/output"

# main.py
df = df.filter(col("status") == ORDER_STATUS_ACTIVE)
df.write.save(OUTPUT_PATH)
```
