convertCASEpro

MODE
Developers5 min read

CONSTANT_CASE: How to Name Constants Across Every Language

CONSTANT_CASE (also called SCREAMING_SNAKE_CASE or UPPER_SNAKE_CASE) is the universal convention for naming constants in code. Here's where it's used, why it exists, and how it differs from regular snake_case.

Published October 2, 2025 · By Sudip Bhowmick

Walk through almost any serious codebase and you'll see a pattern: certain identifiers are written in ALL_CAPS_WITH_UNDERSCORES. These are constants — values that don't change once assigned. CONSTANT_CASE (also known as SCREAMING_SNAKE_CASE or UPPER_SNAKE_CASE) is the widely adopted convention for making constants visually distinct from variables and functions. Understanding it helps you write code that communicates intent at a glance.

What Is CONSTANT_CASE?

CONSTANT_CASE is a naming convention where all letters are uppercase and words are separated by underscores. It is the uppercase variant of snake_case, applied specifically to values that are fixed — constants, configuration values, environment variable names, and enumeration members.

  • MAX_RETRIES
  • DATABASE_URL
  • NODE_ENV
  • API_KEY
  • DEFAULT_TIMEOUT_MS
  • HTTP_STATUS_NOT_FOUND
  • MAX_FILE_SIZE_BYTES

The all-caps visual weight immediately distinguishes these identifiers from regular variables and function names. When a developer sees ALL_CAPS in code, it signals: this value is fixed — don't try to reassign it.

Where CONSTANT_CASE Is Used

Python: PEP 8 mandates CONSTANT_CASE (called UPPER_CASE in the style guide) for module-level constants. If you define a value at the top of a Python module that shouldn't change, it goes in CONSTANT_CASE: MAX_CONNECTIONS = 100, DEFAULT_ENCODING = 'utf-8'.

JavaScript and TypeScript: While JavaScript doesn't enforce immutability at the language level, the convention of writing constants in CONSTANT_CASE is widely followed for values defined with const at module scope: const API_BASE_URL = '...', const MAX_UPLOAD_SIZE = 10 * 1024 * 1024.

Java: Java defines constants as public static final fields. By convention, these use CONSTANT_CASE: public static final int MAX_VALUE = Integer.MAX_VALUE.

C and C++: #define macros and compile-time constants conventionally use CONSTANT_CASE — BUFFER_SIZE, NULL, TRUE, FALSE, HTTP_OK.

Environment variables: Environment variable names are always CONSTANT_CASE by universal convention — DATABASE_URL, SECRET_KEY, NODE_ENV, DEBUG, PORT, REDIS_HOST. This applies across all platforms and languages.

Why CONSTANT_CASE Exists

The purpose of CONSTANT_CASE is readability and intent communication. When you read a function or block of logic, you need to quickly determine which values are fixed inputs (constants) and which values are dynamic (variables). CONSTANT_CASE gives you that information at a glance.

Without this convention: if (retries > maxRetries) — is maxRetries a parameter, a local variable, or a module-level constant? With CONSTANT_CASE: if (retries > MAX_RETRIES) — immediately clear, MAX_RETRIES is a fixed value defined elsewhere.

This is why the convention has spread to virtually every mainstream language despite not being enforced by compilers in most cases. The signal it sends is too useful to ignore.

CONSTANT_CASE vs snake_case

CONSTANT_CASE and snake_case use the same underscore separator — the only difference is case. snake_case is all lowercase (my_variable_name); CONSTANT_CASE is all uppercase (MY_CONSTANT_NAME).

In Python, which uses snake_case for everything, the distinction between a variable and a constant is entirely conveyed through case. A Python developer reading get_user_by_id knows it's a function; reading MAX_RETRY_COUNT knows it's a constant.

In languages that use camelCase for variables (like JavaScript and Java), CONSTANT_CASE still uses underscores even though the rest of the codebase uses camelCase. This makes constants stand out even more visually — which is exactly the intent.

Conclusion

CONSTANT_CASE is one of the most universally adopted coding conventions across all major languages. The logic behind it is simple: all-caps text is visually heavy and attention-grabbing, which is exactly right for values that matter enough to be defined as fixed constants. Whether you're writing Python, JavaScript, Java, or defining environment variables, CONSTANT_CASE is the convention that tells every reader: this value is fixed, intentional, and defined at a scope that outlasts this function.

Free Tool

Try the CONSTANT_CASE Converter

Try It Free →