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.
Language | Conventional Use | Examples |
---|---|---|
Java | instance and local variable names, methods | lastLoginDate or processData |
JavaScript | instance and local variable names, methods | colorOptions or onClick |
JSON | element names | { firstName : ‘Bob’, lastName : ‘Bobbington’} |
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.
Language | Conventional Use | Examples |
---|---|---|
Java | classes, interfaces and enums | PurchaseOrderLines |
JavaScript | classes | UserSettings |
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.
Language | Conventional Use | Examples |
---|---|---|
HTML | elements and attributes | <textarea> and tabindex |
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.
Language | Conventional Use | Examples |
---|---|---|
Java | Constants | MAX_LOGIN_ATTEMPTS |
JavaScript | Constants | START_VALUE |
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.
Language | Conventional Use | Examples |
---|---|---|
CSS | class names | red-rounded-box |
HTML | ids | <div id=”my-div”> |
Java/JS | REST endpoints | /customer-by-id/{id} |
Train Case
a.k.a. HTTP-Header-Case
Train case is basically kebab case but which the first letter of each word capitalized.
Language | Conventional Use | Examples |
---|---|---|
Java | HTTP Headers | httpServletResponse.setHeader("Accept-Language", "en-US"); |
JavaScript | HTTP Headers | $.ajaxSetup({ headers: { 'Accept-Charset': 'utf-8' } }); |
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.
Useful insights. Thanks for sharing
LikeLike