Text Formatting

CONSTANT_CASE for Constants and Environment Variables

Why constants and environment variables are written in uppercase snake case, naming tips, and common mistakes to avoid.

CONSTANT_CASE, also called SCREAMING_SNAKE_CASE, uses uppercase letters with words joined by underscores: MAX_UPLOAD_SIZE, DATABASE_URL. It is the most widely used convention for values that do not change.

Where it is used

  • Constants in code: const MAX_RETRIES = 3; in JavaScript, MAX_RETRIES = 3 in Python, define('MAX_RETRIES', 3); in PHP.
  • Environment variables: APP_ENV, API_KEY, PORT.
  • Configuration files such as .env files.
  • Enum values in some languages.

Why uppercase?

The capitals tell anyone reading the code, "this value is fixed; do not change it at runtime". It also distinguishes configuration from ordinary variables at a glance.

Naming tips

  1. Be specific: SESSION_TIMEOUT_MINUTES is clearer than TIMEOUT.
  2. Include units where relevant: _MS, _SECONDS, _BYTES.
  3. Use prefixes to group settings: MAIL_HOST, MAIL_PORT, MAIL_USER.
  4. Avoid starting with a digit, which many systems reject.
  5. Use only letters, digits and underscores for portability across shells and operating systems.

Security note

Environment variables often hold secrets such as API keys and database passwords. Never commit .env files to public code repositories; add them to .gitignore. Generate strong secrets with a password generator and rotate them if they are exposed.

Converting quickly

Turning "mail server port" into MAIL_SERVER_PORT is one click in our case converter: choose CONSTANT_CASE. It also converts existing camelCase names, so mailServerPort becomes MAIL_SERVER_PORT.

Frequently asked questions

What is screaming snake case?

Screaming snake case is another name for CONSTANT_CASE: uppercase words joined by underscores, such as MAX_RETRIES. It is the standard for constants and environment variable naming.

How do I convert names in different programming languages?

For case conversion in Python, use .upper(), .lower() and the Python title method (.title()), though .title() capitalizes letters after apostrophes. In JavaScript, use JavaScript toUpperCase and toLowerCase. In PHP, use strtoupper, strtolower and PHP ucwords. In SQL, the LOWER function in SQL normalizes text for comparisons.

Try the free Case Converter

Switch text between UPPERCASE, lowercase, Title Case, Sentence case and coding cases.

Open Case Converter