Anytime you create something new, you should give it a name. But what to choose? And how should it look? In terms of what, a good rule of thumb is descriptive but concise yet unique. In terms of look, it all comes down to “case,” from which there are quite a few to choose. The only thing they share is a refusal to use a space with multi-word identifiers. But how to style the rest? Do you want to replace the spaces with underscores? Do you want to alternate uppercase and lowercase letters? The decision gets particularly tricky because different scenarios call for different cases. Here are the four most common types of cases (as applied to the string “my identifier”), along with their common names, alternative names, and when to use them—plus some of their important variants.
myidentifier : flat case (lazy case); Java packages
- MYIDENTIFIER : screaming flat case (upper flat case); SQL
myIdentifier : camel case (dromedary case, lower camel case); JavaScript
- MyIdentifier : capital camel case (upper camel case, mixed case, medical case, Pascal case); Pascal, JavaScript classes, Python classes, Ruby classes
my_identifier : snake case (pothole case, underscore case); Python, Ruby, C
- My_Identifier : capital snake case (camel snake case, mixed underscore case); Ada
- MY_IDENTIFIER : screaming snake case (macro case, constant case); Python constants, Ruby constants, Java constants, C constants and macros
my-identifier : kebab case (caterpillar case, spinal case, dash case); HTML, CSS, URL, Lisp
- My-Identifier : capital kebab case (big caterpillar case); HTTP headers
- MY-IDENTIFIER : screaming kebab case (train case); COBOL
MORE INFO:
https://en.wikipedia.org/wiki/Naming_convention_(programming)#Multiple-word_identifiers
https://stackoverflow.com/questions/17326185/what-are-the-different-kinds-of-cases
https://stackoverflow.com/questions/60244301/where-does-the-word-pascal-case-come-from
FUN FACT:
Camel case was created in the 19th century by chemists, mostly for labeling elements in compounds. They capitalized the first letter of each chemical abbreviation and wrote chemical combinations without spaces between them (e.g., NaOH, NaCl). As a result, it was eventually known as "medical case.” In the 20th century, commercial companies adapted it for branding purposes (e.g., CinemaScope, VistaVision). In the 1970s, various computer programming languages adapted it as a naming convention for identifiers (e.g., WriteSymbol in Christopher Strachey’s GPM). In the 1990s, lower camel case became a popular trend with technology brands, which used “i” for internet or information and “e” for electronic (e.g., iMac, eBay). Around this time, calling the convention “medical case” was falling out of use, and some proposed alternatives were InterCaps and BiCapitalization. In 1995, Newton Love first used the term camel case, and it’s stuck ever since.
Top comments (0)