This article relies too much on references to primary sources. (August 2015) (Learn how and when to remove this template message)
Snake case (or snake_case) is the practice of writing compound words or phrases in which the elements are separated with one underscore character (_) and no spaces, with each element's initial letter usually lowercased within the compound and the first letter either upper- or lowercase—as in "foo_bar" and "Hello_world". It is commonly used in computer code for variable names, and function names, and sometimes computer filenames. At least one study found that readers can recognize snake case values more quickly than camelCase.
The use of underscores as word separators in identifiers in programming languages is old, dating to the late 1960s. It is particularly associated with C, being 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 style guide refers to it simply as "lower_case_with_underscores".
"BTW...what *do* you call that naming style? snake_case? That's what I'll call it until someone corrects me."
However, a former Intel engineer, Jack Dahlgren, has stated on Quora that he was using the term internally at Intel (and perhaps in dialogue with Microsoft engineers) in 2002. It is possible that the same term has developed independently in more than one community.
As of 2015[update], 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, etc.
Examples of languages that use snake case as convention
- OCaml, for value, type, and module names
- C, for the standard library
- C++, for the standard library and Boost
- Erlang, for function names
- GDScript, for variable and function names
- Perl, for lexical variables and subroutines
- Python, for variable names, function names, method names, and module or package (i.e. file) names
- R, for variable names, function names, argument names, especially in the tidyverse style
- Ruby, for variable and method names
- Rust, for variable and function names, among other items
- Elixir, for atom, variable, and function names
- Eiffel, for class and feature names
- e.g. in Python and Ruby; see Naming convention (programming)
- "An Eye Tracking Study on camelCase and under_score Identifier Styles". (pdf)
- Guido van Rossum, Barry Warsaw, Nick Coghlan (2001-07-05). "PEP 0008 -- Style Guide for Python Code".CS1 maint: Uses authors parameter (link)
- 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?".
- "Xen wiki". Retrieved 2017-03-15.
- "Library Design Guidelines". Retrieved 2018-12-13.
- "Boost Library Requirements and Guidelines". Retrieved 2015-08-13.
- "Programming Rules". Retrieved 2017-08-11.
- "GDScript Style Guide".
- Damian Conway (2005). Perl Best Practices. O'Reilly Media Inc. p. 44. ISBN 978-0596001735.
- Wickham, Hadley. The tidyverse style guide.
- "Ruby Naming Conventions".
- "Rust Naming Conventions".
- "Elixir Style Guide".
- "Eiffel Class and Feature Names".