by Leon Rosenshein

String Style

Text is hard. Ascii is fairly straightforward, but Unicode is hard, and UTF-8 is NOT Ascii. Styling your text is hard too. Markdown is supposed to be simple and hopefully transportable, but …

And that doesn’t even get into how you type out an identifier, even if you’re using ASCII. Most (all?) languages use a space as a separator, so if you want a variable for the number of words in a paragraph you can’t use “number of words”. That makes sense. So eliminating spaces is a common pattern.

But there’s no one way to eliminate spaces. You could just drop them, or you could replace them. Or keep them? But what do you replace them with? An underscore is a common replacement, and sometimes, but not always, you can use a dash. And what about letter case?

For your pleasure, a list of possible string cases

Name/Example

Description

flatcase

Remove the spaces and don’t capitalize anything

UPPERFLATCASE

Remove the spaces. Capitalize everything

camelCase

Remove the spaces. Capitalize the first letter of all but the first word

PascalCase

Remove the spaces. Capitalize the first letter of all the words

snake_case

Replace the spaces with underscores. Don’t capitalize anything

camel_Snake_Case

Replace the spaces with underscores. Capitalize the first letter of all but the first word

Pascal_Snake_Case

Replace the spaces with underscores. Capitalize the first letter of all the words

SCREAMING_SNAKE_CASE.

Replace the spaces with underscores. Capitalize everything

kebab-case

Replace the spaces with dashes. Don’t capitalize anything

camel-Kebab-Case

Replace the spaces with dashes. Capitalize the first letter of all but the word

Pascal-Kebab-Case

Replace the spaces with dashes. Capitalize the first letter of all the words

SCREAMING-KEBAB-CASE.

Replace the spaces with dashes. Capitalize everything

Given all of those options, which do you choose? First and foremost, use whatever is in the file you’re editing. After that, use one of our style guides (C++, Go, Python). Then listen to your language and it’s style. And whatever you do, don’t use StUdLYcaPSfOrAnythinG