Snake case

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
Piece of code from a module of the Linux kernel, which uses snake case for identifiers.

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.[1] At least one study found that readers can recognize snake case values more quickly than camelCase.[2]

History[edit]

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".[3]

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

"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[5] 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, 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.[6][7][8]

Examples of languages that use snake case as convention[edit]

  • OCaml, for value, type, and module names[9]
  • ABAP
  • C, for the standard library
  • C++, for the standard library[10] and Boost[11]
  • Erlang, for function names[12]
  • GDScript, for variable and function names[13]
  • Perl, for lexical variables and subroutines[14]
  • Python, for variable names, function names, method names, and module or package (i.e. file) names[3]
  • R, for variable names, function names, argument names, especially in the tidyverse style[15]
  • Ruby, for variable and method names[16]
  • Rust, for variable and function names, among other items[17]
  • Elixir, for atom, variable, and function names[18]
  • Eiffel, for class and feature names[19]

See also[edit]

References[edit]

  1. ^ e.g. in Python and Ruby; see Naming convention (programming)
  2. ^ "An Eye Tracking Study on camelCase and under_score Identifier Styles". (pdf)
  3. ^ a b Guido van Rossum, Barry Warsaw, Nick Coghlan (2001-07-05). "PEP 0008 -- Style Guide for Python Code".CS1 maint: Uses authors parameter (link)
  4. ^ Gavin Kistner (2004-02-23). "Appropriate use of camelCase". Newsgroupcomp.lang.ruby. Usenet: HBn_b.379957$xy6.2073499@attbi_s02. Retrieved 2015-08-13.
  5. ^ "Quora". 2013-05-10.
  6. ^ "StackOverflow - What's the name for snake_case with dashes?".
  7. ^ "Programmers - If this is camelCase what-is-this?".
  8. ^ "Camel_SNAKE-kebab".
  9. ^ "Xen wiki". Retrieved 2017-03-15.
  10. ^ "Library Design Guidelines". Retrieved 2018-12-13.
  11. ^ "Boost Library Requirements and Guidelines". Retrieved 2015-08-13.
  12. ^ "Programming Rules". Retrieved 2017-08-11.
  13. ^ "GDScript Style Guide".
  14. ^ Damian Conway (2005). Perl Best Practices. O'Reilly Media Inc. p. 44. ISBN 978-0596001735.
  15. ^ Wickham, Hadley. The tidyverse style guide.
  16. ^ "Ruby Naming Conventions".
  17. ^ "Rust Naming Conventions".
  18. ^ "Elixir Style Guide".
  19. ^ "Eiffel Class and Feature Names".

External links[edit]