Random notes about naming conventions (for my small research). Send more examples along the way.
Letter case (or just case) is the distinction between the letters that are in larger uppercase or capitals (or more formally majuscule) and smaller lowercase (or more formally minuscule) in the written representation of certain languages.
These terms originated from the common layouts of the shallow drawers called type cases used to hold the movable type for letterpress printing. Traditionally, the capital letters were stored in a separate shallow tray or “case” that was located above the case that held the small letters.
My guess that
camelCase, etc. were derived from “letter case”. I would say it is more correct to use the word “notation” here.
Classically camelCase is supposed to start with a small letter. If it starts with a capital letter it is called PascalCase. For simplicity, I would refer to both variations as camelCase.
Other names (variations): dromedaryCase, PascalCase, UpperCamelCase, StudlyCase.
Used in: Pascal, Modula, Java, .NET, etc.
- how to represent abbreviations in camelCase. Should we use HTTPHeader or HttpHeader? What about XMLHTTPRequest? I would prefer to capitalize the only first letter of the abbreviation - it is easier to see the boundaries of a word that way.
Other names: pothole case, c_case.
- camel_Snake_Case, Pascal_Snake_Case
- SCREAMING_SNAKE_CASE, MACRO_CASE, CONSTANT_CASE (less readable)
Used in: Python, Ruby, C/C++ standard libraries, etc.
Other names: dash-case, lisp-case, css-case
- Train-Case, HTTP-Header-Case
- TRAIN-CASE, COBOL-CASE, SCREAMING-KEBAB-CASE (less readable)
Used in: COBOL, Lisp, Perl 6, CSS, etc.
- many language parsers would interpret
-as infix minus operation, so it is not widely adopted. It is not a problem in Lisp, because subtraction operation looks like this
(- 1 2)
- an additional problem if
-is used at the beginning of a word, for example,
-moz-column-count- Google interprets
NOToperation, which makes those identifiers ungoogleable. Use quotes to find them
I don’t consider: flat case (twowords), upper flat case (TWOWORDS), doner|case (two|words). Because they are unreadable.
- What are the different kinds of cases?
- Multiple-word identifiers
- Special case styles
- Naming Conventions
In Hungarian notation name contains information about the type, for example,
iCount means that the variable is of type integer. It comes from Fortran where variables starting with i-n (mnemonics INteger) were considered integers, other variables were floats.
Have you seen
for (i = 0; i < 100; i++)? This code uses
i, because of Fortran.
I guess static type systems and LSP make this notation obsolete, except when type doesn’t provide enough information (for example,
In Ruby and some Lisps predicates (which are boolean values) denoted with the question mark in the end (
is prefix (
isNumber). The problem with
is prefix it is easy to miss preceding
! in the end of the word to destructive functions. See this wiki.
Some languages use
__ at the beginning of a word to denote private variables and non-public APIs (for example, Pony).
? at the end of the word to denote partial function.
Pony uses the first capital letter (PascalCase) to denote types (and classes, traits, interfaces).
Ruby on Rails uses singular nouns to denote models and plural nouns to denote collections of these models, for example,
organization.members. Also, it is considered a good practice to use verbs for methods (functions).
Punctuation-based names, typically used for operators or built-in functions. For example,
- It is hard to search on the internet because search engines were built to search natural-language words (it is still possible to find using quotes). To address this issue people build special pages to lookup punctuation based syntax, for example Operator Lookup
- Hard to pronounce - not everybody knows that Ruby programmers call
=>“hash rocket”, JS programmers would call it “fat arrow”, Haskell programmers call