スネーク‐ケース【snake case】
スネークケース
出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2024/11/08 06:07 UTC 版)
   スネークケース(snake_case)とは、単語間の区切りをスペースの代わりにアンダースコア(_)を使い、全て小文字で記述する命名規則である。変数名やサブルーチン名、ファイル名など、コンピュータ業界で一般的に使用される。ある研究によると「読者はキャメルケースよりもスネークケースの値(value)をより早く認識できることがわかった」としている。しかし、その読者は主にアンダースコアスタイルで訓練されていたため、どちらが優れているかは実際の所は定かではない[1]。
歴史
単語の区切り文字としてアンダースコアが使用されるようになったのは、1960年代後半にまで遡る。これは特にC言語に関連しており、『The C Programming Language』(1978)にも見られるスタイルで、「パスカルケース」(キャメルケースの一種) と対比されている。ただし、このスタイルには従来、特定の名前は付いていなかった。2001年にリリースされたPythonコーディング規約の決定版「PEP8」では、単に「lower_case_with_underscores」と呼ばれていた[2]。
「snake_case」という用語の初出は、2004年のUsenet内のRubyコミュニティで[3]、Gavin Kistner が以下のようなコメントにおいて使用した。
ところで…この命名スタイルをお前らなんて呼んでる?スネークケースか〜?誰かが直してくれるまで俺はこう呼ぶことにするよ。
しかし、元IntelエンジニアのJack Dahlgrenによると、2002 年にIntel社内で (そしておそらくはMicrosoftエンジニアとの会話の中で)この用語を使用していたとのこと[4][出典無効]。ひょっとすると、この用語は複数のコミュニティにおいて独自に生み出されたのかもしれない。
2015年現在[update]、複数の単語からなる識別子を区切り文字で区切るような命名規則の名前は標準化されていないが、リスプケース(lisp-case)、ケバブケース(kebab-case)、スクリーミングスネークケース(SCREAMING_SNAKE_CASE)など、一部の用語に関しては使用される機会は増えている[5][6][7]。
用例
以前よりスネークケースを使用しているプログラミング言語のリスト
- ABAP[8]
 - Ada - なお頭文字は大文字[9]
 - C++ - Boost C++ライブラリ[10]
 - C - 標準ライブラリの一部の型名には使用されるが、関数名には使用されない。
 - Eiffel - クラスと特性(フィーチャー)名[11]
 - Elixir - アトム、変数、関数名[12]
 - Erlang - 関数名[13]
 - GDScript - 変数名と関数名[14]
 - Java - static final定数と列挙型に SCREAMING_SNAKE_CASE を使用する[15]
 - Kotlin - 定数に SCREAMING_SNAKE_CASE を使用 [16]
 - Magik
 - OCaml - 値、型、モジュール名[17]
 - Perl - レキシカル変数とサブルーチン[18]
 - Oracle SQL and PL/SQL - [19] 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[20]
 - Python - for variable names, function names, method names, and module or package (i.e. file) names[2]
 - PHP - uses SCREAMING_SNAKE_CASE for class constants
 - R - for variable names, function names, and argument names, especially in the tidyverse style[21]
 - Ruby - for variable and method names[22]
 - Rust - for variable names, function names, method names, module names, and macros[23]
 - Tcl
 - Terraform - for resources and variables[24]
 
関連項目
参照
- ^ 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. pp. 196–205. doi:10.1109/ICPC.2010.41. ISBN 978-1-4244-7604-6
 - ^ a b van Rossum, Guido; Warsaw, Barry; Coghlan, Nick (2001年7月5日). “PEP 0008 -- Style Guide for Python Code”. 2023年8月9日閲覧。
 - ^ Gavin Kistner (23 February 2004). "Appropriate use of camelCase". Newsgroup: comp.lang.ruby. Usenet: HBn_b.379957$xy6.2073499@attbi_s02. 2015年8月13日閲覧。
 - ^ “What is the history of the term "snake case" (snake_case)?”. Quora (2013年5月10日). 2023年8月9日閲覧。
 - ^ “StackOverflow – What's the name for snake_case with dashes?”. 2023年8月9日閲覧。
 - ^ “Programmers – If this is camelCase what-is-this?”. 2016年11月5日時点のオリジナルよりアーカイブ。2016年11月5日閲覧。
 - ^ “Camel_SNAKE-kebab”. GitHub (23 April 2020). 2023年8月9日閲覧。
 - ^ “Naming Conventions in ABAP Objects”. help.sap.com. 2020年7月28日閲覧。
 - ^ “Ada Programming Guidelines”. 2021年12月19日時点のオリジナルよりアーカイブ。2021年12月19日閲覧。
 - ^ “Boost Library Requirements and Guidelines”. 2015年8月13日閲覧。
 - ^ “Eiffel Class and Feature Names” (28 December 2019). 2023年8月9日閲覧。
 - ^ “Elixir Style Guide”. GitHub (May 2020). 2023年8月9日閲覧。
 - ^ “Programming Rules”. 2017年8月11日閲覧。
 - ^ “GDScript Style Guide”. 2023年8月9日閲覧。
 - ^ “Code Conventions for the Java Programming Language – Naming Conventions”. Oracle. 2021年8月3日閲覧。
 - ^ “Coding Conventions”. 2023年2月3日閲覧。
 - ^ “Xen wiki”. 2017年3月15日閲覧。
 - ^ Damian Conway (2005). Perl Best Practices. O'Reilly Media Inc.. p. 44. ISBN 978-0596001735
 - ^ “Quick Guide to Some Sources for Naming Conventions for Oracle Database Development”. stevenfeuersteinonplsql.blogspot.com. 2020年12月30日閲覧。
 - ^ 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]。
 - ^ Wickham, Hadley. The tidyverse style guide
 - ^ “Ruby · Naming Convention”. namingconvention.org. 2023年8月9日閲覧。
 - ^ “Naming – Rust API Guidelines”. 2023年8月9日閲覧。
 - ^ “Terraform Naming Conventions” (Feb 2022). 2023年8月9日閲覧。
 
外部リンク
- スネークケースのページへのリンク