Snake case
Snake case (stylized as snake_case) is the naming convention in which each space is replaced with an underscore (_) character, and the first letter of each word is 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]
![](../I/Alx_source_snippet.png.webp)
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".[2]
Within Usenet the term snake_case was first seen in the Ruby community in 2004,[3] 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.[4] 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.[5][6][7]
Examples
A list of programming languages that conventionally use snake case
- ABAP[8]
- Ada, with initial letters also capitalized[9]
- C++, Boost[10]
- C, for some type names in the standard library, but not for function names.
- Eiffel, for class and feature names[11]
- Elixir, for atom, variable, and function names[12]
- Erlang, for function names[13]
- GDScript, for variable and function names[14]
- Java uses SCREAMING_SNAKE_CASE for static final constants and enum values.[15]
- Kotlin uses SCREAMING_SNAKE_CASE for constants and enum values[16]
- Magik
- OCaml, for value, type, and module names[17]
- Perl, for lexical variables and subroutines[18]
- Oracle SQL and PL/SQL,[19] 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[20]
- Python, for variable names, function names, method names, and module or package (i.e. file) names[2]
- PHP uses SCREAMING_SNAKE_CASE for class constants
- R, for variable names, function names, and argument names, especially in the tidyverse style[21]
- Ruby, for variable and method names[22]
- Rust, for variable names, function names, method names, module names, and macros[23]
- Tcl
- Terraform (software), for resources and variables[24]
See also
- Camel case, more common in Java and C#
- Kebab case, more common in LISP
- Naming convention (programming)
References
- Sharif, Bonita; Maletic, Jonathan I. (2010). "An Eye Tracking Study on camelCase and under_score Identifier Styles". 2010 IEEE 18th International Conference on Program Comprehension (PDF). pp. 196–205. CiteSeerX 10.1.1.421.6137. doi:10.1109/ICPC.2010.41. ISBN 978-1-4244-7604-6. S2CID 14170019.
- Guido van Rossum; Barry Warsaw; Nick Coghlan (2001-07-05). "PEP 0008 -- Style Guide for Python Code".
- Gavin Kistner (2004-02-23). "Appropriate use of camelCase". Newsgroup: comp.lang.ruby. Usenet: HBn_b.379957$xy6.2073499@attbi_s02. Retrieved 2015-08-13.
- "Quora". 2013-05-10.
- "StackOverflow – What's the name for snake_case with dashes?".
- "Programmers – If this is camelCase what-is-this?". Archived from the original on 2016-08-07. Retrieved 2015-08-13.
- "Camel_SNAKE-kebab". GitHub. 23 April 2020.
- "Naming Conventions in ABAP Objects". help.sap.com. Retrieved 2020-07-28.
- "Ada Programming Guidelines".
- "Boost Library Requirements and Guidelines". Retrieved 2015-08-13.
- "Eiffel Class and Feature Names". 28 December 2019.
- "Elixir Style Guide". GitHub. May 2020.
- "Programming Rules". Archived from the original on 2010-09-04. Retrieved 2017-08-11.
- "GDScript Style Guide".
- "Code Conventions for the Java Programming Language – Naming Conventions". Oracle. Retrieved 2021-08-03.
- "Coding Conventions". Retrieved 2023-02-03.
- "Xen wiki". Retrieved 2017-03-15.
- Damian Conway (2005). Perl Best Practices. O'Reilly Media Inc. p. 44. ISBN 978-0-596-00173-5.
- "Quick Guide to Some Sources for Naming Conventions for Oracle Database Development". stevenfeuersteinonplsql.blogspot.com. Retrieved 2020-12-30.
- Michael A. Covington; Roberto Bagnara; Richard A. O'Keefe; Jan Wielemaker; Simon Price (2009). "Coding Guidelines for Prolog (v.3)". p. 14. arXiv:0911.2899 [cs.PL].
- Wickham, Hadley. The tidyverse style guide.
- "Ruby Naming Conventions". GitHub. May 2020.
- "Naming – Rust API Guidelines". Archived from the original on 2018-09-16. Retrieved 2019-10-27.
- "Terraform Naming Conventions". Feb 2022.