Case Styles in Coding (camelCase, snake_case, and more)

Case Styles in Programming

Developing software at scale requires you to write code that is easy to manage. One of the main ways to enforce manageable code is by writing code that is easy to read. The easiest way to write readable code is by naming objects logically and carefully.

For example, you don’t want to use names like this:

myfavcol = "Blue"
alcons = 10

Instead, you should use complete words for easier understandability.

myfavoritecolor = "Blue"
allowedconnections = 10

But this gives rise to a new problem. Long multi-word literals look messy too. In some cases, the above object names can look overwhelming and be less readable. This all happens because programming languages don’t let you use blank spaces when naming objects. To overcome this issue, you can apply a case style for compound words to make them more readable.

In programming, the most common case styles are:

  1. Camel case. In the camel case, compound words start with a capital first letter. Only the first word in the chain starts with a small first letter. This makes the multi-word names easier to read.
  2. Snake case. In the snake case, compound words are separated by underscores. This adds a clear separator between words to make names more readable.
  3. Pascal case. In the Pascal case, compound words start with a capital first letter. Unlike in the camel case, the first word also starts with a capital letter.
# Camel case
myFavoriteColor = "Blue"
allowedConnections = 10

# Snake case
my_favorite_color = "Blue"
allowed_connections = 10

# Pascal case
MyFavoriteColor = "Blue"
AllowedConnections = 10

Also, in web development, URLs and path names commonly use kebab case, in which words are separated by dashes.

Why Use a Case Style?

Notice that using a particular case style is not mandatory. Your program code runs whether you use case styles or not. But if you choose to use a case style, you should stick with it throughout the project.

With case styles, you can make your code more readable and concise. This is because you are not allowed to use blank spaces when naming objects in your code. So instead of using spaces, you can visually separate words from one another by using different case styles, such as camel case or snake case.

4 Popular Case Styles in Programming

Let’s take a more detailed look at the 4 popular case styles in programming.

  1. Camel case
  2. Snake case
  3. Pascal case
  4. Kebab case

Besides, you’ll see some examples and common use cases for these case styles.

1. Camel Case (camelCase)

In the camel case, each compound word starts with a capital letter—except for the very first letter of the first word.

Camel case is one of the most commonly used naming conventions in coding. In the camel case, compound words start with a capital letter. This helps visually differentiate words from one another when there are many words.

Notice that in the camel case, the first letter of the very first word starts with a lowercase letter.

Common Use Cases

Many programming languages use camel case to declare variables.

Let’s take a look at a Python example:

myAccountBalance = 100
distanceToMoon = 3.844e8

2. Pascal Case (PascalCase)

In the Pascal case, each compound word starts with a capital letter.

Pascal case is sometimes called the upper camel case. The only difference between the Pascal case and the camel case is that the very first letter is also capitalized in the Pascal case.

In other words, in the Pascal case, all compound words start with a capital letter. This helps distinguish words from one another in name literals of multiple words.

Common Use Cases

Pascal case originates from the Pascal programming language. But it has spread out to be a popular naming convention in other programming languages too.

The most common use case for the pascal case is for naming classes.

For example:

class MainViewController: UIViewController { ... }

3. Snake Case (snake_case)

In the snake case, words are separated by underscores.

Snake case is a case style where each compound word is separated by an underscore. This greatly improves the readability of values with long multi-word names.

Common Use Cases

Snake case is a really common naming convention in Python programming language.

my_age = 26
date_today = "2022-09-15"

It’s also common to see database fields labeled with snake-cased names.

As an example:

    first_seen: "2021-07-02",
    last_modified: "2022-09-15"

Sometimes, when declaring constant values, you might use capitalized snake case where each letter is capitalized.


This variation of snake case is sometimes called the macro case or screaming snake case. But more often than not developers call it the capital snake case or just the snake case.

4. Kebab Case (kebab-case)

In the kebab case, words are separated by a dash.

In the kebab case, you separate words with a dash. This is reminiscent of the snake case where you separate words with an underscore.

But the kebab case is not commonly used in programming languages. This is because your typical coding language doesn’t allow adding dashes between words that make up the names of the objects.

Common Use Cases

You typically use a kebab case when creating URLs.

For example:

In URLs, you typically don’t see capital letters. This is because the URLs shouldn’t look like they are yelling at you. Thus, the Pascal case and camel case are not good options for visually separating compound words in a URL slug. This is why the kebab case is commonly used. Instead of capitalizing the letters, they are separated by dashes.

What Is the Best Case Style?

When it comes to case styles, there is no agreed answer as to what is the best one for them. Each case style serves the same purpose—to improve the readability of compound words.

To choose a case style, you need to keep in mind:

  • Language-specific best practices.
  • Team-level conventions.
  • Your personal preferences.

In many languages, the case style you “should” use depends on the type of object you are naming. It’s typical to name variables, functions, and class definitions all using different case styles!

Let me show you a demonstrative example in Swift, the iOS development language.

Example: Case Styles in Swift

In Swift, you commonly see the following case styling best practices in use:

  • Name variables, constants, functions, and methods using camel case.
  • Name class definitions using the Pascal case.
// Pascal case for creating a class
class MainViewController { ... }

// Camel case for creating variables, constants, and functions
let allowedConnections = 10
var numberOfStudents = 100
func circleArea(r: Int) -> Int { ... }

Also, sometimes you see developers naming constants in snake case with all characters in upper case.


Mind Your Team Preferences

Using a “wrong” case style convention doesn’t crash your code. But you need to mind your teammates when writing code. After all, the case style must be consistent across the different code files of the project.

If (and when) your development team has specified team-specific case-styling guidelines, you should follow them. Usually, these best practices follow language-specific conventions. But this is not always the case. For example, if you are part of the math-heavy code base, you will probably use snake cases more often than not.

Wrap Up

Today you learned about the case styles of coding languages.

The case styles are used to make code more readable and understandable. The reason why case styles are needed is that you cannot use blank spaces when separating words in object names. To help make the distinction between words, case styles, such as the camel case can help.

In coding, there are three case styles that you see frequently:

  1. Camel case
  2. Snake case
  3. Pascal case

In web development, you see paths and URLs using the kebab case. In the kebab case, compound words are separated by dashes.

There is no right or wrong case style. To choose the case style, check the language-specific best practices and common conventions. Also, don’t forget to check your team-specific guidelines if you are coding in a team.

Thanks for reading. Happy coding!

Read Also