The before code hardcodes sensitive and environment-specific values, making it unsafe and inflexible. The after code reads configuration from environment variables, allowing different values per environment without code changes.
### Before: Hardcoded configuration
class ServiceConfig:
DATABASE_URL = "postgres://prod-db:5432/app"
API_KEY = "prod-secret-key"
### After: Environment-based configuration
import os
class ServiceConfig:
DATABASE_URL = os.getenv("DATABASE_URL", "postgres://localhost:5432/app")
API_KEY = os.getenv("API_KEY", "default-key")
# Usage example
config = ServiceConfig()
print(f"DB URL: {config.DATABASE_URL}")
print(f"API Key: {config.API_KEY}")