Quick Guide to Programming Case Types

A few weeks ago, I encountered a reference to screaming snake case used to describe something named in all uppercase letters with underscores between the words: SCREAMING_SNAKE_CASE. Although the thought of screaming snakes is somewhat horrifying (especially in 2020), I also found it rather entertaining. We use various case types during our programming work and I though it might be fun to write a post on the different case types and their names. Where possible, I’ll be tying the cases to conventions in Java, JavaScript, HTML and CSS as those are the languages I use most frequently.

Camel Case

a.k.a. dromedary case and hump case

Camel case most typically refers to the case where we place all the words together and capitalize the first letter of each word, except for the first word which is lower case.

LanguageConventional UseExamples
Javainstance and local variable names, methodslastLoginDate or processData
JavaScriptinstance and local variable names, methodscolorOptions or onClick
JSONelement names{ firstName : ‘Bob’, lastName : ‘Bobbington’}
Conventional uses with examples

Upper Camel Case

a.k.a. Pascal Case

After defining camel case, upper camel case should be pretty self-explanatory. It’s camel case, but with the first letter capitalized. Some people don’t bother to distinguish between upper camel case and camel, so you may see upper camel case names referred to as camel case.

LanguageConventional UseExamples
Javaclasses, interfaces and enumsPurchaseOrderLines
JavaScriptclassesUserSettings
Conventional uses with examples

Flat Case

Flat case involves just smooshing all the words together in all lower case. There’s also an all caps variant, upper flat case. So our last login date from the camel case example would become lastlogindate.

LanguageConventional UseExamples
HTMLelements and attributes<textarea> and tabindex
Conventional uses with examples

If there are conventions in Java or JavaScript for using flat case, I’m not aware of them. It makes for hard to read variable names.

Note: HTML is not case sensitive and there isn’t anything preventing you from using onMouseOver, for example, as an attribute name. You could just as easily uppercase your HTML tags too (e.g. <TEXTAREA>) but that’s generally frowned upon these days.

Snake Case

a.k.a. pothole case

When using snake case, we use all lower case and separate words with an underscore (_).

Java, JavaScript, CSS and HTML don’t have conventional uses of snake case, so I mostly see it in database table and column names.

Screaming Snake Case

a.k.a. Upper case snake case, macro case, constant case

Screaming snake case involves separating the words with underscores but then capitalizing all the words. Thus the screaming part.

LanguageConventional UseExamples
JavaConstantsMAX_LOGIN_ATTEMPTS
JavaScriptConstantsSTART_VALUE
Conventional uses with examples

Before we move on, there’s a third flavor of snake case called camel snake case which separates each word with underscores and uppercases the first letter. I’ve never seen it used in Java, JS, HTML or CSS, so I’m not creating a section for it.

Kebab Case

a.k.a. spinal case, dash case, lisp case, css case, caterpillar case and hyphen case

Kebab case separates each word with a hyphen, so the hyphen is the skewer and the words are the meat and vegetables of the kebab. The words are all lower case.

LanguageConventional UseExamples
CSSclass namesred-rounded-box
HTMLids<div id=”my-div”>
Java/JSREST endpoints/customer-by-id/{id}
Conventional uses with examples

Train Case

a.k.a. HTTP-Header-Case

Train case is basically kebab case but which the first letter of each word capitalized.

LanguageConventional UseExamples
Java HTTP HeadershttpServletResponse.setHeader("Accept-Language", "en-US");
JavaScriptHTTP Headers$.ajaxSetup({ headers: { 'Accept-Charset': 'utf-8' } });
Conventional uses with examples

Screaming Kebab Case

a.k.a. Uppercase train case, cobol case

Screaming kebab case, is just kebab case in all caps. It’s not a case that I’ve used much, if at all. Since one of it’s aliases is cobol case, I’m going to guess it might be used there.

Conclusion

In this post, I covered more than eight cases that I would generally group into four case families:

  • not separated at all (e.g. flat case)
  • separated with capitalization (e.g. camel case)
  • separated with an underscore (e.g. snake case)
  • separated by a hyphen (e.g. kebab case)

Within each family there are variants surrounding capitalization.

I tried to be thorough when I put together my list, but I’m definitely not claiming that it’s exhaustive (especially since I’ve only covered languages I use regularly). Please feel free to leave a comment, if you feel like I left something out and I’ll update the post as needed.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s