What is CONSTANT_CASE?
CONSTANT_CASE, also known as SCREAMING_SNAKE_CASE, is a naming convention where words are separated by underscores and all letters are uppercase. It's the standard convention for naming constants in most programming languages.
Examples:
MAX_VALUE
API_KEY
DATABASE_CONNECTION
DEFAULT_TIMEOUTWhen to Use CONSTANT_CASE
- Constants: Values that never change throughout the program
- Environment variables: Configuration settings (API_KEY, DATABASE_URL)
- Global configuration: Application-wide settings
- Enum values: In some programming languages
- Magic numbers: Important numerical constants
- Static final fields: In Java and similar languages
Examples in Code
JavaScript/TypeScript:
const MAX_RETRIES = 3;
const API_BASE_URL = "https://api.example.com";
const DEFAULT_TIMEOUT = 5000;Python:
MAX_CONNECTIONS = 100
DATABASE_HOST = "localhost"
PI_VALUE = 3.14159Java:
public static final int MAX_SIZE = 1000;
public static final String API_KEY = "your-key";
public static final double TAX_RATE = 0.08;Why Use CONSTANT_CASE?
Visual Distinction
The uppercase format makes constants immediately recognizable in code, distinguishing them from variables.
Convention
It's a widely accepted standard across multiple programming languages including C, C++, Java, Python, JavaScript, and more.
Immutability Signal
Indicates that the value should not be modified during program execution.
Best Practices
- ✓ Use for true constants that never change
- ✓ Keep names descriptive and meaningful
- ✓ Group related constants together
- ✓ Use for configuration values
- ✗ Don't use for regular variables
- ✗ Avoid overly long constant names