Snake case

Snake case (stylized as snake_case) is the naming convention in which each space is replaced with an underscore (_) character, and words are written in lowercase. It is a commonly used naming convention in computing, for example for variable and subroutine names, and for filenames. One study has found that readers can recognize snake case values more quickly than camel case. However, "subjects were trained mainly in the underscore style", so the possibility of bias cannot be eliminated.[1]

Piece of code from a module of the Linux kernel, which uses snake case for identifiers.

A variation is screaming snake case where words are written in all caps (stylized as SCREAMING_SNAKE_CASE).[2] This convention is used for constants in programming languages like C/C++, Python, Java, PHP, as well as for environment variables.

History

The use of underscores as word separators dates back to the late 1960s. It is particularly associated with C, is found in The C Programming Language (1978), and contrasted with pascal case (a type of camel case). However, the convention traditionally had no specific name: the Python programming language style guide refers to it simply as "lower_case_with_underscores".[3]

Within Usenet the term snake_case was first seen in the Ruby community in 2004,[4] used by Gavin Kistner, writing:

BTW...what *do* you call that naming style? snake_case? That's what I'll call it until someone corrects me.

However, former Intel engineer Jack Dahlgren has stated that he was using the term internally at Intel (and perhaps in dialogue with Microsoft engineers) in 2002.[5][failed verification] It is possible that the term developed independently in more than one community.

As of 2015, names for other delimiter-separated naming conventions for multiple-word identifiers have not been standardized, although some terms have increasing levels of usage, such as lisp-case, kebab-case, SCREAMING_SNAKE_CASE, and more.[6][7][8]

Examples

The following programming languages use snake case by convention:

  • ABAP[9]
  • Ada, with initial letters also capitalized[10]
  • C++, Boost[11]
  • C, for some type names in the standard library, but not for function names.
  • Eiffel, for class and feature names[12]
  • Elixir, for atom, variable, and function names[13]
  • Erlang, for function names[14]
  • GDScript, for variable and function names[15]
  • Java uses SCREAMING_SNAKE_CASE for static final constants and enum values.[16]
  • Kotlin uses SCREAMING_SNAKE_CASE for constants and enum values[17]
  • Magik
  • OCaml, for value, type, and module names[18]
  • Perl, for lexical variables and subroutines[19]
  • Oracle SQL and PL/SQL,[20] for all unquoted identifiers (tables, columns, indexes, constraints, PL/SQL variables, constants, procedures/functions, triggers,...), although not official by Oracle itself, still recommended by the majority of known "influencers" and used throughout the official Oracle documentation
    • All unquoted snake_case identifiers are actually internally represented as SCREAMING_SNAKE_CASE identifiers.
  • Prolog, for both atoms (predicate names, function names, and constants) and variables[21]
  • Python, for variable names, function names, method names, and module or package (i.e. file) names[3]
  • PHP uses SCREAMING_SNAKE_CASE for class constants
  • PL/I[22]
  • R, for variable names, function names, and argument names, especially in the tidyverse style[23]
  • Ruby, for variable and method names[24]
  • Rust, for variable names, function names, method names, module names, and macros[25]
  • Tcl
  • Terraform (software), for resources and variables[26]
  • Zig, for variables[27]

See also

References

External links