snake case
{{Short description|Words joined with underscores}}
{{Primary sources|date=August 2015}}
File:alx source snippet.png, which uses snake case for identifiers]]
Snake case (sometimes stylized autologically as snake_case) is the naming convention in which each space is replaced with an underscore (_) character, and words are 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.{{Cite book |chapter=An Eye Tracking Study on camelCase and under_score Identifier Styles |doi=10.1109/ICPC.2010.41 | isbn = 978-1-4244-7604-6 |title=2010 IEEE 18th International Conference on Program Comprehension |year=2010 |last1=Sharif |first1=Bonita |last2=Maletic |first2=Jonathan I. |pages=196–205 |citeseerx=10.1.1.421.6137 |s2cid=14170019 |url=http://www.cs.kent.edu/~jmaletic/papers/ICPC2010-CamelCaseUnderScoreClouds.pdf}}
A variation is screaming snake case, where words are written in all caps (stylized as SCREAMING_SNAKE_CASE).{{Cite web |url=https://developer.mozilla.org/en-US/docs/Glossary/Snake_case |title=Snake Case |website=Mozilla Developer Network |date=8 September 2023 |access-date=November 10, 2023}} This convention is used for constants in programming languages like C/C++, Python, Java, PHP, as well as for environment variables.
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".{{cite web |url=https://www.python.org/dev/peps/pep-0008/ |title=PEP 0008 -- Style Guide for Python Code |date=2001-07-05 |author=Guido van Rossum |author2=Barry Warsaw |author3=Nick Coghlan }}
Within Usenet the term snake_case was first seen in the Ruby community in 2004,{{cite newsgroup|title=Appropriate use of camelCase|author=Gavin Kistner|date=2004-02-23|newsgroup=comp.lang.ruby|message-id=HBn_b.379957$xy6.2073499@attbi_s02|url=https://groups.google.com/d/msg/comp.lang.ruby/ra5WDzNGwGU/oe_mnvRVclUJ|access-date=2015-08-13}} used by Gavin Kistner, writing:
{{quotation|BTW...what *do* you call that naming style? snake_case? That's what I'll call it until someone corrects me.}}
{{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.{{Cite web |title=StackOverflow – What's the name for snake_case with dashes? |url=https://stackoverflow.com/questions/11273282/whats-the-name-for-snake-case-with-dashes }}{{Cite web |title=Programmers – If this is camelCase what-is-this? |url=http://programmers.stackexchange.com/questions/104468/if-this-is-camelcase-what-is-this |access-date=2015-08-13 |archive-date=2016-08-07 |archive-url=https://web.archive.org/web/20160807114459/http://programmers.stackexchange.com/questions/104468/if-this-is-camelcase-what-is-this }}{{Cite web |title=Camel_SNAKE-kebab |website=GitHub |date=23 April 2020 |url=https://github.com/qerub/camel-snake-kebab }}
Examples
The following programming languages use snake case by convention:
- ABAP{{Cite web|title=Naming Conventions in ABAP Objects|url=https://help.sap.com/saphelp_snc_uiaddon_10/helpdata/en/92/c2b084bc1d11d2958700a0c94260a5/content.htm?no_cache=true#:~:text=They%20are%20maintained%20centrally%20in%20the%20table%20TADIR.&text=The%20class%20name%20should%20consist%20of%20singular%20nouns.&text=The%20same%20naming%20convention%20as%20for%20classes.&text=The%20class%20name%20should%20consist%20of%20singular%20nouns.,-LCL_TREE_MANAGEMENT|access-date=2020-07-28|website=help.sap.com}}
- Ada, with initial letters also capitalized{{cite web | title = Ada Programming Guidelines | url = https://www.tesestec.com.br/pasteurjr/rup/manuals/ada/ada.htm#anchor5413805}}
- C++, Boost{{cite web | title = Boost Library Requirements and Guidelines | url = http://www.boost.org/doc/libs/1_34_0/more/lib_guide.htm#Design_and_Programming | access-date = 2015-08-13}}
- C, for some type names in the standard library, but not for function names.
- Eiffel, for class and feature names{{cite web | title = Eiffel Class and Feature Names | date = 28 December 2019 | url = https://www.eiffel.org/doc/solutions/Eiffel%20Class%20and%20Feature%20Names }}
- Elixir, for atom, variable, and function names{{cite web | title = Elixir Style Guide | website = GitHub | date = May 2020 | url = https://github.com/niftyn8/elixir_style_guide/blob/master/README.md }}
- Erlang, for function names{{cite web | url = http://www.erlang.se/doc/programming_rules.shtml#REF10726 | title = Programming Rules | access-date = 2017-08-11 | archive-date = 2010-09-04 | archive-url = https://web.archive.org/web/20100904160816/http://www.erlang.se/doc/programming_rules.shtml#REF10726 }}
- GDScript, for variable and function names{{cite web |title=GDScript Style Guide |url=https://docs.godotengine.org/en/3.0/getting_started/scripting/gdscript/gdscript_styleguide.html#functions-and-variables }}
- Java uses SCREAMING_SNAKE_CASE for static final constants and enum values.{{cite web |title=Code Conventions for the Java Programming Language – Naming Conventions |publisher=Oracle |url=https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html |access-date=2021-08-03}}
- Kotlin uses SCREAMING_SNAKE_CASE for constants and enum values{{cite web |title=Coding Conventions |url=https://kotlinlang.org/docs/coding-conventions.html#property-names |access-date=2023-02-03}}
- Magik
- OCaml, for value, type, and module names{{cite web |title=Xen wiki |url=https://wiki.xenproject.org/wiki/OCaml_Best_Practices_for_Developers#Names_of_Identifiers |access-date=2017-03-15}}
- Perl, for lexical variables and subroutines{{cite book |title=Perl Best Practices |url=https://archive.org/details/perlbestpractice00conw |url-access=limited |publisher=O'Reilly Media Inc. |author=Damian Conway |year=2005 |isbn=978-0-596-00173-5 |page=[https://archive.org/details/perlbestpractice00conw/page/n67 44]}}
- Oracle SQL and PL/SQL,{{Cite web|title=Quick Guide to Some Sources for Naming Conventions for Oracle Database Development|url=http://stevenfeuersteinonplsql.blogspot.com/2016/10/naming-conventions-for-oracle-database.html|access-date=2020-12-30|website=stevenfeuersteinonplsql.blogspot.com}} 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{{cite arXiv |title=Coding Guidelines for Prolog (v.3) |author1=Michael A. Covington |author2=Roberto Bagnara |author3=Richard A. O'Keefe |author4=Jan Wielemaker |author5=Simon Price |page=14 |year=2009 |class=cs.PL |eprint=0911.2899 }}
- Python, for variable names, function names, method names, and module or package (i.e. file) names
- PHP uses SCREAMING_SNAKE_CASE for class constants
- PL/I{{cite book |last1=IBM |title=IBM Operating System/360 PL/I: Language Specifications |date=July 1965 |page=16 |url=https://bitsavers.org/pdf/ibm/360/pli/C28-6571-1_PL_I_Language_Specifications_Jul65.pdf |access-date=November 12, 2023}}
- R, for variable names, function names, and argument names, especially in the tidyverse style{{Cite book|url=http://style.tidyverse.org/|title=The tidyverse style guide|last=Wickham|first=Hadley}}
- Ruby, for variable and method names{{cite web |title=Ruby Naming Conventions |website=GitHub |date=May 2020 |url=https://github.com/styleguide/ruby/naming }}
- Rust, for variable names, function names, method names, module names, and macros{{cite web |title=Naming – Rust API Guidelines |url=https://rust-lang-nursery.github.io/api-guidelines/naming.html |access-date=2019-10-27 |archive-date=2018-09-16 |archive-url=https://web.archive.org/web/20180916230852/https://rust-lang-nursery.github.io/api-guidelines/naming.html }}
- Tcl
- Terraform (software), for resources and variables{{cite web |title=Terraform Naming Conventions |date=Feb 2022 |url=https://www.terraform-best-practices.com/naming }}
- Zig, for variables{{Cite web| title = Documentation - The Zig Programming Language| access-date = 2024-03-10| url = https://ziglang.org/documentation/0.11.0/}}
See also
- Camel case, more common in Java and C#
- Kebab case, more common in LISP
- Naming convention (programming)
References
{{Reflist}}
External links
- [https://en.toolpage.org/tool/snakecase Snake case converter]
{{Typography}}