Snake Case
Snake case (or "snake_case") is a naming convention that replaces spaces in compound words with underscores (_). It is commonly used by software developers for writing method and variable names in their source code, as well as when naming files used by their projects. While snake_case typically uses all lower-case letters, a version known as SCREAMING_SNAKE_CASE uses all capital letters.
In most programming languages, the names of methods, variables, and other elements cannot contain spaces. Developers use naming conventions like snake_case, camelCase, and PascalCase to make compound names readable while avoiding compilation errors. For example, the variable name my_first_variable is easier to read than myfirstvariable.
In many cases, it is up to the developer's preference which convention to use, but some programming languages have style guides that specify certain conventions for certain uses. For example, Python's style guide recommends a mix of several naming conventions for different uses:
- Classes: PascalCase — class UserInfo
- Functions: snake_case — print_message()
- Methods: snake_case — draw_image()
- Variables: snake_case — new_user_name
- Constants: SCREAMING_SNAKE_CASE — MAX_VALUE
Other programming languages that use snake_case for variables, functions, and methods include Ruby, Rust, PHP, and Perl. Shell scripting languages, like Bash, also often use snake_case for variables and functions.