Snake case

Last updated
Piece of code from a module of the Linux kernel, which uses snake case for identifiers. Alx source snippet.png
Piece of code from a module of the Linux kernel, which uses snake case for identifiers.

Snake case (stylized 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. [1]

Contents

A variation is screaming snake case where words are written in all caps (stylized as SCREAMING_SNAKE_CASE). [2] 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". [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] [ failed verification ] 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

The following programming languages use snake case by convention:

See also

Related Research Articles

<span class="mw-page-title-main">Camel case</span> Writing words with internal uppercase letters

Camel case is the practice of writing phrases without spaces or punctuation and with capitalized words. The format indicates the first word starting with either case, then the following words having an initial uppercase letter. Common examples include YouTube, PowerPoint, HarperCollins, FedEx, iPhone, eBay, and LaGuardia. Camel case is often used as a naming convention in computer programming. It is also sometimes used in online usernames such as JohnSmith, and to make multi-word domain names more legible, for example in promoting EasyWidgetCompany.com.

<span class="mw-page-title-main">Case sensitivity</span> Defines whether uppercase and lowercase letters are treated as distinct

In computers, case sensitivity defines whether uppercase and lowercase letters are treated as distinct (case-sensitive) or equivalent (case-insensitive). For instance, when users interested in learning about dogs search an e-book, "dog" and "Dog" are of the same significance to them. Thus, they request a case-insensitive search. But when they search an online encyclopedia for information about the United Nations, for example, or something with no ambiguity regarding capitalization and ambiguity between two or more terms cut down by capitalization, they may prefer a case-sensitive search.

In a computer language, a reserved word is a word that cannot be used as an identifier, such as the name of a variable, function, or label – it is "reserved from use". This is a syntactic definition, and a reserved word may have no user-defined meaning.

This is a "genealogy" of programming languages. Languages are categorized under the ancestor language with the strongest influence. Those ancestor languages are listed in alphabetic order. Any such categorization has a large arbitrary element, since programming languages often incorporate major ideas from multiple sources.

A string literal or anonymous string is a literal for a string value in the source code of a computer program. Modern programming languages commonly use a quoted sequence of characters, formally "bracketed delimiters", as in x = "foo", where "foo" is a string literal with value foo. Methods such as escape sequences can be used to avoid the problem of delimiter collision and allow the delimiters to be embedded in a string. There are many alternate notations for specifying string literals especially in complicated cases. The exact notation depends on the programming language in question. Nevertheless, there are general guidelines that most modern programming languages follow.

ABAP is a high-level programming language created by the German software company SAP SE. It is currently positioned, alongside Java, as the language for programming the SAP NetWeaver Application Server, which is part of the SAP NetWeaver platform for building business applications.

An underscore or underline is a line drawn under a segment of text. In proofreading, underscoring is a convention that says "set this text in italic type", traditionally used on manuscript or typescript as an instruction to the printer. Its use to add emphasis in modern finished documents is generally avoided.

In computer programming, glob patterns specify sets of filenames with wildcard characters. For example, the Unix Bash shell command mv *.txttextfiles/ moves all files with names ending in .txt from the current directory to the directory textfiles. Here, * is a wildcard and *.txt is a glob pattern. The wildcard * stands for "any string of any length including empty, but excluding the path separator characters ".

<span class="mw-page-title-main">PL/pgSQL</span>

PL/pgSQL is a procedural programming language supported by the PostgreSQL ORDBMS. It closely resembles Oracle's PL/SQL language. Implemented by Jan Wieck, PL/pgSQL first appeared with PostgreSQL 6.4, released on October 30, 1998. Version 9 also implements some ISO SQL/PSM features, like overloading of SQL-invoked functions and procedures.

In computer programming, a naming convention is a set of rules for choosing the character sequence to be used for identifiers which denote variables, types, functions, and other entities in source code and documentation.

In computer programming, an enumerated type is a data type consisting of a set of named values called elements, members, enumeral, or enumerators of the type. The enumerator names are usually identifiers that behave as constants in the language. An enumerated type can be seen as a degenerate tagged union of unit type. A variable that has been declared as having an enumerated type can be assigned any of the enumerators as a value. In other words, an enumerated type has values that are different from each other, and that can be compared and assigned, but are not specified by the programmer as having any particular concrete representation in the computer's memory; compilers and interpreters can represent them arbitrarily.

This comparison of programming languages compares the features of language syntax (format) for over 50 computer programming languages.

<span class="mw-page-title-main">Comment (computer programming)</span> Explanatory note in the source code of a computer program

In computer programming, a comment is a programmer-readable explanation or annotation in the source code of a computer program. They are added with the purpose of making the source code easier for humans to understand, and are generally ignored by compilers and interpreters. The syntax of comments in various programming languages varies considerably.

The null coalescing operator is a binary operator that is part of the syntax for a basic conditional expression in several programming languages, including C# as of version 2.0, PowerShell as of version 7.0.0, Perl as of version 5.10, Swift, and PHP 7.0.0. While its behavior differs between implementations, the null coalescing operator generally returns the result of its left-most operand if it exists and is not null, and otherwise returns the right-most operand. This behavior allows a default value to be defined for cases where a more specific value is not available.

This comparison of programming languages compares how object-oriented programming languages such as C++, Java, Smalltalk, Object Pascal, Perl, Python, and others manipulate data structures.

In computer programming, a constant is a value that is not altered by the program during normal execution. When associated with an identifier, a constant is said to be "named," although the terms "constant" and "named constant" are often used interchangeably. This is contrasted with a variable, which is an identifier with a value that can be changed during normal execution. To simplify, constants' values remains, while the values of variables varies, both hence their names.

<span class="mw-page-title-main">SonarQube</span> Open-source platform for continuous inspection of code quality

SonarQube is an open-source platform developed by SonarSource for continuous inspection of code quality to perform automatic reviews with static analysis of code to detect bugs and code smells on 29 programming languages. SonarQube offers reports on duplicated code, coding standards, unit tests, code coverage, code complexity, comments, bugs, and security recommendations.

PL/SQL is Oracle Corporation's procedural extension for SQL and the Oracle relational database. PL/SQL is available in Oracle Database, Times Ten in-memory database, and IBM Db2. Oracle Corporation usually extends PL/SQL functionality with each successive release of the Oracle Database.

References

  1. 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. S2CID   14170019.
  2. "Snake Case". Mozilla Developer Network. Retrieved November 10, 2023.
  3. 1 2 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". 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?". Archived from the original on 2016-08-07. Retrieved 2015-08-13.
  8. "Camel_SNAKE-kebab". GitHub . 23 April 2020.
  9. "Naming Conventions in ABAP Objects". help.sap.com. Retrieved 2020-07-28.
  10. "Ada Programming Guidelines".
  11. "Boost Library Requirements and Guidelines" . Retrieved 2015-08-13.
  12. "Eiffel Class and Feature Names". 28 December 2019.
  13. "Elixir Style Guide". GitHub . May 2020.
  14. "Programming Rules". Archived from the original on 2010-09-04. Retrieved 2017-08-11.
  15. "GDScript Style Guide".
  16. "Code Conventions for the Java Programming Language – Naming Conventions". Oracle. Retrieved 2021-08-03.
  17. "Coding Conventions" . Retrieved 2023-02-03.
  18. "Xen wiki" . Retrieved 2017-03-15.
  19. Damian Conway (2005). Perl Best Practices . O'Reilly Media Inc. p.  44. ISBN   978-0-596-00173-5.
  20. "Quick Guide to Some Sources for Naming Conventions for Oracle Database Development". stevenfeuersteinonplsql.blogspot.com. Retrieved 2020-12-30.
  21. 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].
  22. IBM (July 1965). IBM Operating System/360 PL/I: Language Specifications (PDF). p. 16. Retrieved November 12, 2023.
  23. Wickham, Hadley. The tidyverse style guide.
  24. "Ruby Naming Conventions". GitHub . May 2020.
  25. "Naming – Rust API Guidelines". Archived from the original on 2018-09-16. Retrieved 2019-10-27.
  26. "Terraform Naming Conventions". Feb 2022.
  27. "Documentation - The Zig Programming Language" . Retrieved 2024-03-10.