Snake case

Snake case (stylized as snake_case) refers to the style of writing in which each space is replaced by an underscore (_) character, and the first letter of each word written in lowercase. It is the most common naming convention used in computing as identifiers for variable, function, and file names.[1] One study has found that readers can recognize snake case values more quickly than camel case.[2]

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

History

The use of underscores as word separators dates back 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 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] 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

A list of programming languages which conventionally use snake case

  • ABAP[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, for static final constants and enum values.
  • OCaml, for value, type, and module names[15]
  • Perl, for lexical variables and subroutines[16]
  • Prolog, for both atoms (predicate names, function names and constants) and variables[17]
  • Python, for variable names, function names, method names, and module or package (i.e. file) names[3]
  • PHP use SCREAMING_SNAKE_CASE for class constants
  • R, for variable names, function names, argument names, especially in the tidyverse style[18]
  • Ruby, for variable and method names[19]
  • Rust, for variable names, function names, method names, module names and macros[20]
gollark: How can you *measure* that?
gollark: It's not like there seems to be any "conservation of intelligence" law; how would that even work?
gollark: It seems to have been.
gollark: I mean, while technically sort of true, I find that when people say that sort of thing they mean to drag along a lot of connotations.
gollark: You can *somewhat* change them.

See also

References

  1. e.g. in Python and Ruby; see Naming convention (programming)
  2. 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.
  3. 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". Newsgroup: comp.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". 23 April 2020.
  9. "Naming Conventions in ABAP Objects". help.sap.com. Retrieved 2020-07-28.
  10. "Boost Library Requirements and Guidelines". Retrieved 2015-08-13.
  11. "Eiffel Class and Feature Names". 28 December 2019.
  12. "Elixir Style Guide". May 2020.
  13. "Programming Rules". Retrieved 2017-08-11.
  14. "GDScript Style Guide".
  15. "Xen wiki". Retrieved 2017-03-15.
  16. Damian Conway (2005). Perl Best Practices. O'Reilly Media Inc. p. 44. ISBN 978-0596001735.
  17. 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].
  18. Wickham, Hadley. The tidyverse style guide.
  19. "Ruby Naming Conventions". May 2020.
  20. "Naming - Rust API Guidelines".
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.