Kebab case -- or kebab-case -- is a programming variable naming convention where a developer replaces the spaces between words with a dash.
Programming variable names should be descriptive. Two or more words are often required to properly convey a resource's meaning. However, most programming languages don't allow spaces between words.
The kebab case naming convention attempts to overcome this limitation by replacing spaces between words with a dash.
The term comes from the associated imagery of a skewer in a kebab. The skewer pierces multiple piece of food together on a shish kebab. In code, the dash represents the skewer and keeps multiple words together to describe a resource's meaning, a la a shish kebab.
Kebab case examples
Here are three examples of the kebab case naming convention:
Kebab case vs. snake case
Kebab case is a similar naming convention to snake case -- or snake_case. Both conventions help a developer read code because the white space -- either a dash in kebab case or an underscore in snake case -- between words reads like a normal sentence.
Snake case contrasts more distinctly with the CamelCase naming convention. In CamelCase, whitespace is removed between compound words. It replaces the dash or underscore with an uppercase letter to represent the start of the next word. For example:
If a developer uses all uppercase letters in a variable with the kebab case convention, it's known as a scream kebab. The term owes its name to the thought that when people on social media type sentences with upper case letters, they're screaming. For example:
Problems with kebab case
The biggest problem with kebab case lies mainly on the use of a dash. Many programming languages will interpret the dash as a minus sign, and it unintentionally creates software bugs that are difficult to isolate and troubleshoot.
Similarly, many programming languages -- such as Jekyll -- will assume numbers separated by a dash are dates. This misinterpretation can cause problems when a developer uses kebab case with spreadsheets or calendar-based applications.
In the software development community, snake case is typically the preferred naming convention. Snake case creates the maximum white space between compound words in a variable with an underscore.
While kebab case can be useful, a developer must be aware that a dash can cause unintentional issues with non-letter code.