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 lower case—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]
  • Perl, for lexical variables and subroutines.[13]
  • PHP, for functions, but not class methods. Older conventions were often to use snake case for every type of identifier, except classes and namespaces.[citation needed]
  • Python, for variable names, function names, method names, and module or package (i.e. file) names[3]
  • Ruby, for variable and method names[14]
  • Rust, for variable and function names, among other items[15]
  • Elixir, for atom, variable, and function names[16]
  • Eiffel, for class and feature names[17]

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". 
  3. ^ a b Guido van Rossum, Barry Warsaw, Nick Coghlan (2001-07-05). "PEP 0008 -- Style Guide for Python Code". 
  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 2015-08-13. 
  11. ^ "Boost Library Requirements and Guidelines". Retrieved 2015-08-13. 
  12. ^ "Programming Rules". Retrieved 2017-08-11. 
  13. ^ Damian Conway (2005). Perl Best Practices. O'Reilly Media Inc. p. 44. ISBN 0596001738. 
  14. ^ "Ruby Naming Conventions". 
  15. ^ "Rust Naming Conventions". 
  16. ^ "Elixir Style Guide". 
  17. ^ "Eiffel Class and Feature Names". 

External links[edit]