Suvarna Garge (Editor)

Snake case

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

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. At least one study found that readers can recognize snake case values more quickly than camel case.

Contents

History

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, an older term for camel case. However, the convention traditionally had no specific name: the Python style guide refers to it simply as "lower_case_with_underscores".

The name "snake_case" comes from the Ruby community, where it was coined in 2004 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."

The name is evidently in line with camel case (as the subject of the message notes), continuing the animal theme with a long creature, low to the ground.

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.

Examples of languages that use snake case as convention

  • OCaml, for variable and function names
  • C++, for the standard library and Boost
  • Erlang, for function names
  • Perl
  • PHP, for functions, but not class methods. Older conventions were often using snake case for every type of identifiers, except classes and namespaces.
  • Python, for variable names, function names, and method names
  • Ruby, for variable and function names
  • Rust, for variable and function names
  • Elixir, for variable and function names
  • Eiffel, for variable and function names
  • References

    Snake case Wikipedia