Question:

What is snake case?

Snake case is a way of writing multi-word names in code without spaces, like first_name or get_user_by_id, where words are written in lowercase and separated by underscores. Since programming languages don’t allow spaces in variable or function names, conventions like this exist to keep code readable. The name comes from the way the underscores sit low between the words, like a snake on the ground.

It’s the standard in Python, Ruby, and most database column names. If you’re writing Python, the convention is snake case for variables, functions, and method names. SQL tables and columns are almost always snake case too, which is why you see things like created_at or user_id so often.

The main alternative is camel case, which uses capital letters instead of underscores. JavaScript developers typically use camel case, while Python developers use snake case. When you work across both, it’s easy to mix them up.

There’s also screaming snake case, which is the same style but all uppercase: MAX_RETRIES, API_KEY. That’s the conventional way to write constants in many languages.

You might also like