What's the name for hyphen-separated case?
Asked Answered
D

15

697

This is PascalCase: SomeSymbol

This is camelCase: someSymbol

This is snake_case: some_symbol

So my questions is whether there is a widely accepted name for this: some-symbol? It's commonly used in url's.

Decagram answered 30/6, 2012 at 10:13 Comment(13)
@CatPlusPlus Lisp uses this-case, and because Google treats a - as a space, almost every SEO friendly URL uses it too.Decagram
@lms: URLs are irrelevant to programming languages. And I said "most", I know there are languages that allow that, but they're a minority.Sheepdip
@CatPlusPlus 1) URLs are NOT irrelevant to programming languages. They are one of the most frequent resource programming languages use. Some languages even treat URLs as a first class object. In Go, while not first class, URLs are used for importing packages. 2) The dash-separated-string is quite common in several languages (the LISP family for one), and also in anxilliary languages used in programming, like CSS. What's a "minority" for you, it's the language others work day in and out. We're not all VB6 programmers.Ubangishari
kebab-case isn't just used in LISP, but in CSS and all its new-fangled Turing-complete preprocessors, it's used in XSLT and XPath and in any other XML-based language. They are far from a minority.Bodhisattva
What about UPPERCASE-WITH-DASHES? Admittedly rare today, best name I’m heard is COBOL-CASE, which is accurate, say at UnderscoreVersusCapitalAndLowerCaseVariableNamingElectrolyte
Also -- it's not "UpperCamelCase" -- it's "TitleCase".Ruhnke
Asking "Is separating words with hyphens good or bad?" would be subjective. Asking for what it's called isn't. Nor would "What's the most common capitalisation style of Ruby methods?", for what it's worth.Cheder
I'm voting to close this question as off-topic because you should only ask practical, answerable questions based on actual problems that you face. Chatty, open-ended questions diminish the usefulness of our site and push other questions off the front page.Dependence
GitLab is joining the cause for kebab-case now :)Gertrudegertrudis
I call it anything-but-kebab-case-case.Lylalyle
By the way, there is also screaming snake case, SOME_SYMBOL useful for constants in many languages.Dissimulate
EJoshua: This is a practical question because talking about identifiers, variable names, etc is part of software developer. It is also answerable in the social-science sense, because we can review (1) source code repositories, perhaps combined with popularity weighting as well as (2) natural language trends (via Google or otherwise). Additionally, these terms are just so much fun. Don't poop on our party. So I'm going to officially rain on your party-pooping party.Klarrisa
“kebab-case” considered offensive by some: github.com/Modernizr/Modernizr/issues/2645 . Will I be cancelled if I say it's ridiculous?…Dissever
P
586

This is known as dash-case or kebab-case.

No other terms have achieved wide adoption, though there are various other coinings out there including hyphen-case, caterpillar-case, lisp-case, train-case, url-case, slug-case, and css-case.

It seems kebab-case in particular has entered the lexicon of several javascript code libraries.

Polak answered 23/7, 2013 at 20:12 Comment(26)
The linked wikipedia article currently has a reference that links back to this stack overflow question... specifically to the kebab-case question. Maybe using wikipedia as a source wasn't a clever idea.Respiration
Let me rephrase: linking an easy to vandalize website as source isn't a clever idea. Of course in this case, "vandalism" is hard to define - the linked wiki page does not have any good references to verify either version. In wikipedia terms, both spinal-case and kebab-case are as good as original research.Respiration
Also just to clear any possible misunderstandings: I was not aware the kebab-case edit was done a few days ago, and I am not involved in that at all.Respiration
@BenLee I'm the one you felt butchered the copy - for which apologies. Note that spinal-case/Train-Case were added to Wikipedia on 2012-10-07 without reference by an anonymous user from an IP address without other Wikipedia history. I couldn't find any other evidence for those terms that didn't circularly go back to Wikipedia. On the other hand, I felt this StackOverflow question did offer evidence ‎that kebab-case has a community of users that doesn't depend on something entered into a Wikipedia article without evidence. I hope that's enough to avoid the original research charge.Navvy
I was tempted to remove spinal-case and Train-Case entirely (as likely vandalism); but maybe longstanding Wikipedia vandalism can actually create evidence for itself. That's what seems to have happened here.Navvy
@BenLee as much as I love spinal-case, it looks like it might actually be called lisp-case. See this wikipedia post and this answer on Programmer Stack Exchange and the second reply on that answer.Daiquiri
@Tsiege Yeah I actually agree. I updated my answer to reflect all the possibilities (putting lisp-case first), and explained how none of them are really standard, all of them relatively new coinings, and how there is currently disagreement over which should be standard.Polak
I like "catipillar-case" since it's squished and then long, and keeps with the animal themeBeau
I don't get the idea behind "kebab-case". If you say "sausage-case", yeah, I get it. But "kebab-case"??? Anyway, I use "dash-case".Tetroxide
'kebab-case' FTW!Mcentire
kebab-case-because it-looks-like-the-words-are skewered-on-a-kebabSparker
CSS-case? #7561313Jaquiss
The kebab case is referring to shish kebab (vegetables and meat intermittent on a small skewer) more than it is to the only meat döner kebab that you see everywhere.Dissimulate
@alper: I, too, feel like I see döner kebab everywhere, but I spend at least half of my time in the Netherlands and Australia. ☺ It's pretty unknown in most parts of the US, though, and we must take care not to offend the Americans by referring to anything that's different from their little media bubble (date format, gallons/pints/inches/calories, Fahrenheit, proprietary mobile networks, weird spellings, etc.) 😉Onehorse
@jv110 do you have a source for that? from my research (a couple years ago when i wrote this answer) there was no source suggesting a widespread use of any of thesePolak
@BenLee I'm not sure how I would back up my claim, I know it's widespread because out of all the times I saw anyone talking about it, most were using "kebab-case". Plus, it's the only name that makes sense in this context, since it's pretty much a joke, and the programming community (this part of it, at least) loves jokes. GNU is more than proof of that.Stretcher
Dammit .. I like both kebab case and caterpillar case. Especially caterpillar case because it's so cute and visual.Rodarte
Thank you for the tip on kebab-case; coming from the US, it makes sense to me, as the shish kebab is quite popular here. It's a shame though that skewer-case isn't the winning name, because not all regions of the world cook kebabs on a skewer (en.wikipedia.org/wiki/Kebab).Boffa
it's 2019 now and kebab-case is quite widely understoodIngeringersoll
I so want this to be not called kebab-case widespread. I would rather say words-separated-with-dashes-case, if I ever have to call it a case. I mean c'mon guys, why should this even be called a case in the first place??? If anything, I might even call it lisp-case, but kebab-case??? Never.Lylalyle
@Respiration Should we call this a Wikipedia circular reference? Haha.Outage
skeleton case... definitelyCenacle
vs code has transform to kebab case as of 1.69 now tooToomey
-surely-kebab-case-should-have-a-leading-and-trailing-hyphen-like-a-real-kebab-then!-Pieeyed
I know this answer is very old buy why does the Google trend link posted in the answer uses - in search terms. This is not what a user would search for, right? So the correct link would be using spaces and then dash case wins. trends.google.com/trends/…Prater
@Prater How has this been up for 11 years with 250k views and nobody noticed this until now? Fixed that. And also seems that as of 2024 "dash case" and "kebab case" have become standard, so I removed the line about there not being any standard.Polak
B
521

It's referred to as kebab-case. See lodash docs.

Barbey answered 5/9, 2012 at 0:39 Comment(21)
Here's a reference, that makes it official ;)Uncharted
Here's another reference: github.com/qerub/camel-snake-kebab ;)Nedry
The recursion in the reference means it's that much more Lisp-like.Pilar
I upvoted this answer not because I believe it's the right one, but because I want it to be the right one.Sworn
I hope no human is stupid enough to get kebab-case confused with case subtracted from kebab.Koralie
I love the citogenesis going on here. This answer links to lodash which links to wikipedia which links to this answer!Fierce
Completing another loop: http://en.wikipedia.org/wiki/citogenesisBarbey
Hey, who doesn't love camel-flavoured kebab? github.com/Alhadis/Snippets/blob/master/js/utils.js#L510Fabri
Congrats, this appears to be the earliest use of the term "kebab-case", and thus perhaps the origin! I've updated Wikipedia to make it clear that this is a non-standard term, but appears to be gaining currency: en.wikipedia.org/w/… For example, no usenet uses before 2015: groups.google.com/forum/#!search/… ...but now has appeared in print (Living Clojure (2015), Carin Meier, p. 91)!Electrolyte
:) Dashes (--) are made of two hyphens (-). I would say kebab case represents hyphenated name sequences, but dashed would be insane a--big--name--with--emphasis--you--cannot--ignore... let's call it Drama-Case.Endstopped
Also there is another common variant, the SCREAMING_SNAKE_CASEStanfill
Just because it looks like a constant to my C-trained eyes, I'd call that CONST_CASE. Snakes don't scream.Izabel
For those who are wondering: Why the hell kebab?Adviser
@Adviser That's not a kebab... it's a skewer. So now we find out that it should have been called skewer-case?Plano
AngularJS docs call it this as well. Usage creates and defines terms, not dictionaries. angular.io/docs/ts/latest/tutorial/toh-pt3.htmlElementary
Microsoft doc's point here ;) learn.microsoft.com/en-us/aspnet/core/mvc/views/view-componentsGwendolyngweneth
For anyone checking the circular reference from here to lodash to Wiki to here — it has been broken as of 1 January 2016, caused by an edit to the Wiki article. Too bad, I love recursion.Debrahdebrecen
Shouldn't it be Shish Case? Otherwise we may confuse it for Durum Case or Doner Case, which are totally different. We must be precise.Remittance
techdebug.com/blog/2008/04/19/…Sikang
SO answer as the canon source for a term. /me likes!Fourier
We need more references to this, to give it the full reddit switcharoo treatment. I'll be adding this to as many places as possible.Kileykilgore
S
40

It's also sometimes known as caterpillar-case

Shingles answered 22/2, 2014 at 16:23 Comment(9)
caterpillar-case makes much more sense than kebab-case, because camels, snakes, and caterpillars are all kinds of living creature while a kebab is not.Heaviness
@DairaHopwood cs.helsinki.fi/u/hhallama/pics/kebabelain.jpgHusain
As "caterpillar" has four syllables whereas "kebab", "dash" and "hyphen" have one or two, I think arguing for caterpillar-case is a losing battleCodex
"caterpillar-case" is too long to be a case name, I think "worm-case" would be a better choice. :DNikola
I like caterpillar-case ! If there had to be a worm-case I think it would be all lowercase attached words ie: somethinglikethisisdifficulttoreadUlrich
@DairaHopwood fully agree.. Pascal was also a living creature.Santana
Living creatures may not be the theme though. Perhaps it is things that are edible?Perplexity
@JohnMitchell en.m.wikipedia.org/wiki/Gonimbrasia_belina 😉Shingles
@Shingles en.m.wikipedia.org/wiki/Kebab 🍽Perplexity
E
25

This is the most famous case and It has many names

  • kebab-case: It's the name most adopted by official software
  • caterpillar-case
  • dash-case
  • hyphen-case or hyphenated-case
  • lisp-case
  • spinal-case
  • css-case
  • slug-case
  • friendly-url-case
Engels answered 23/1, 2019 at 15:1 Comment(0)
R
22

As the character (-) is referred to as "hyphen" or "dash", it seems more natural to name this "dash-case", or "hyphen-case" (less frequently used).

As mentioned in Wikipedia, "kebab-case" is also used. Apparently (see answer) this is because the character would look like a skewer... It needs some imagination though.
Used in lodash lib for example.

Recently, "dash-case" was used by

Ruthannruthanne answered 2/6, 2017 at 10:30 Comment(1)
The kebab case is referring to shish-kebab more than it is to döner kebab if that is any help.Dissimulate
F
16

Adding the correct link here Kebab Case

which is All lowercase with - separating words.

Frock answered 5/9, 2016 at 13:39 Comment(0)
D
11

I've always called it, and heard it be called, 'dashcase.'

Dicentra answered 27/1, 2017 at 9:35 Comment(2)
It shall forever be known as Dashy McDash CaseKorea
@Korea I think you mean dashy-mcdash-case ;)Sirotek
E
7

I've always known it as kebab-case.

On a funny note, I've heard people call it a SCREAM-KEBAB when all the letters are capitalized.

Kebab Case Warning

I've always liked kebab-case as it seems the most readable when you need whitespace. However, some programs interpret the dash as a minus sign, and it can cause problems as what you think is a name turns into a subtraction operation.

first-second  // first minus second?
ten-2 // ten minus two?

Also, some frameworks parse dashes in kebab cased property. For example, GitHub Pages uses Jekyll, and Jekyll parses any dashes it finds in an md file. For example, a file named 2020-1-2-homepage.md on GitHub Pages gets put into a folder structured as \2020\1\2\homepage.html when the site is compiled.

Snake_case vs kebab-case

A safer alternative to kebab-case is snake_case, or SCREAMING_SNAKE_CASE, as underscores cause less confusion when compared to a minus sign.

Esmeralda answered 17/12, 2020 at 14:52 Comment(0)
P
6

There is no standardized name.

Libraries like jquery and lodash refer it as kebab-case. So does Vuejs javascript framework. However, I am not sure whether it's safe to declare that it's referred as kebab-case in javascript world.

Pyroxylin answered 8/12, 2016 at 18:48 Comment(0)
N
5

I'd simply say that it was hyphenated.

Nubbly answered 29/11, 2016 at 9:37 Comment(1)
Hyphenated might be a good answer to an English question, but for code it's not specific enough. For example, in kebab-case all letters are lowercase.Lennalennard
B
5

Worth to mention from abolish:

https://github.com/tpope/vim-abolish/blob/master/doc/abolish.txt#L152

dash-case or kebab-case

Bechuanaland answered 30/9, 2017 at 2:0 Comment(0)
P
4

In Salesforce, It is referred as kebab-case. See below

https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.js_props_names

Plum answered 5/3, 2019 at 14:50 Comment(0)
R
2

Here is a more recent discombobulation. Documentation everywhere in angular JS and Pluralsight courses and books on angular, all refer to kebab-case as snake-case, not differentiating between the two.

Its too bad caterpillar-case did not stick because snake_case and caterpillar-case are easily remembered and actually look like what they represent (if you have a good imagination).

Rockabilly answered 19/4, 2017 at 17:48 Comment(0)
D
1

My ECMAScript proposal for String.prototype.toKebabCase.

String.prototype.toKebabCase = function () {
  return this.valueOf().replace(/-/g, ' ').split('')
    .reduce((str, char) => char.toUpperCase() === char ?
      `${str} ${char}` :
      `${str}${char}`, ''
    ).replace(/ * /g, ' ').trim().replace(/ /g, '-').toLowerCase();
}
Dirac answered 13/3, 2019 at 16:53 Comment(4)
any response to the proposal?Ingeringersoll
any response to your response?Illustrate
his-idea-was-skeweredHierophant
well it was more of a joke hahaPreciosa
S
1

This casing can also be called a "slug", and the process of turning a phrase into it "slugify".

https://hexdocs.pm/slugify/Slug.html

Semi answered 2/7, 2020 at 15:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.