What are the different kinds of cases?
CaseNamingCamelcasingCase Problem Overview
I'm interested in the different kinds of identifier cases, and what people call them. Do you know of any additions to this list, or other alternative names?
myIdentifier
: Camel case (e.g. in java variable names)MyIdentifier
: Capital camel case (e.g. in java class names)my_identifier
: Snake case (e.g. in python variable names)my-identifier
: Kebab case (e.g. in racket names)myidentifier
: Flat case (e.g. in java package names)MY_IDENTIFIER
: Upper case (e.g. in C constant names)
Case Solutions
Solution 1 - Case
flatcase
kebab-case
. Also calledcaterpillar-case
,dash-case
,hyphen-case
,lisp-case
,spinal-case
andcss-case
camelCase
PascalCase
orCapitalCamelCase
snake_case
orc_case
MACRO_CASE
orUPPER_CASE
COBOL-CASE
orTRAIN-CASE
Solution 2 - Case
Names are either generic, after a language, or colorful; most don’t have a standard name outside of a specific community.
There are many names for these naming conventions (names for names!); see Naming convention: Multiple-word identifiers, particularly for CamelCase (UpperCamelCase, lowerCamelCase). However, many don’t have a standard name. Consider the Python style guide PEP 0008 – it calls them by generic names like “lower_case_with_underscores”.
One convention is to name after a well-known use. This results in:
- PascalCase
- MACRO_CASE (C preprocessor macros)
…and suggests these names, which are not widely used:
- c_case (used in K&R and in the standard library, like size_t)
- lisp-case, css-case
- COBOL-CASE
Alternatively, there are illustrative names, of which the best established is CamelCase. snake_case is more recent (2004), but is now well-established. kebab-case is yet more recent and still not established, and may have originated on Stack Overflow! (What's the name for dash-separated case?) There are many more colorful suggestions, like caterpillar-case, Train-case (initial capital), caravan-case, etc.
Solution 3 - Case
+--------------------------+-------------------------------------------------------------+
| Formatting | Name(s) |
+--------------------------+-------------------------------------------------------------|
| namingidentifier | flat case/Lazy Case |
| NAMINGIDENTIFIER | upper flat case |
| namingIdentifier | (lower) camelCase, dromedaryCase |
| NamingIdentifier | (upper) CamelCase, PascalCase, StudlyCase, CapitalCamelCase |
| naming_identifier | snake_case, snake_case, pothole_case, C Case |
| Naming_Identifier | Camel_Snake_Case |
| NAMING_IDENTIFIER | SCREAMING_SNAKE_CASE, MACRO_CASE, UPPER_CASE, CONSTANT_CASE |
| naming-identifier | Kebab Case/caterpillar-case/dash-case, hyphen-case, |
| | lisp-case, spinal-case and css-case |
| NAMING-IDENTIFIER | TRAIN-CASE, COBOL-CASE, SCREAMING-KEBAB-CASE |
| Naming-Identifier | Train-Case, HTTP-Header-Case |
| _namingIdentifier | Undercore Notation (prefixed by "_" followed by camelCase |
| datatypeNamingIdentifier | Hungarian Notation (variable names Prefixed by metadata |
| | data-types which is out-dated) |
|--------------------------+-------------------------------------------------------------+
Solution 4 - Case
MyVariable
: Pascal Case
=> Used for Class
myVariable
: Camel Case
=> Used for variable
at Java, C#, etc.
myvariable
: Flat Case
=> Used for package
at Java, etc.
my_variable
: Snake Case
=> Used for variable
at Python, PHP, etc.
my-variable
: Kebab Case
=> Used for css
Solution 5 - Case
The most common case types: Camel case Snake case Kebab case Pascal case Upper case (with snake case)
camelCase camelCase must (1) start with a lowercase letter and (2) the first letter of every new subsequent word has its first letter capitalized and is compounded with the previous word.
An example of camel case of the variable camel case var
is camelCaseVar
.
snake_case snake_case is as simple as replacing all spaces with a "_" and lowercasing all the words. It's possible to snake_case and mix camelCase and PascalCase but imo, that ultimately defeats the purpose.
An example of snake case of the variable snake case var
is snake_case_var
.
kebab-case kebab-case is as simple as replacing all spaces with a "-" and lowercasing all the words. It's possible to kebab-case and mix camelCase and PascalCase but that ultimately defeats the purpose.
An example of kebab case of the variable kebab case var
is kebab-case-var
.
PascalCase PascalCase has every word starts with an uppercase letter (unlike camelCase in that the first word starts with a lowercase letter).
An example of pascal case of the variable pascal case var
is PascalCaseVar
.
Note: It's common to see this confused for camel case, but it's a separate case type altogether.
UPPER_CASE_SNAKE_CASE UPPER_CASE_SNAKE_CASE is replacing all the spaces with a "_" and converting all the letters to capitals.
an example of upper case snake case of the variable upper case snake case var
is UPPER_CASE_SNAKE_CASE_VAR
.
Solution 6 - Case
For Python specifically, it is best to use snake_case
for variable and function names, UPPER_CASE
for constants (even though we don't have any keywords that specifically say that our variable is a constant) and PascalCase
for class names.
camelCase
is not recommended for Python (although languages such as Javascript have it as their main casing), and kebab-case
would be invalid as Python names cannot contain a hypen (-
).
variable_name = 'Hello World!'
def function_name():
pass
CONSTANT_NAME = 'Constant Hello World!!'
class ClassName:
pass