Case Styles in programming

Case Styles in programming

Learn most popularly used Case Styles in a Programming language.

Hello, there! In this Blog article, we will learn about different Case Styles in programming.

Check out the Repository for Ultimate Resource in python. Drop a star if you find it useful! Got anything to add? Open a PR on the same!

You can refer to my YouTube video Tutorial to see a working tutorial for better Understanding and a step by step Guide of the same.

What will be covered in this Blog

1. What is Case Style?
2. Different types of Case Styles:
    - Camel case
    - Snake case & Capitalized Snake Case
    - Kebab case
    - Pascal case

Let's get started!

What is Case Style?

If you are a programmer, chances are that you daily come across scenarios where you have to follow certain naming conventions. It's considered a good practice to know which case style to use in which scenario because say for example we cannot name a like this:no of students = 25

In programming, Case Style is the most common way to combine words into a single string. There are many ways in which we can combine words, the most popularly known are:

  • Camel case
  • Snake case & Capitalized Snake Case
  • Kebab case
  • Pascal case

Let's have a look at each one of them in detail. You can find all the code at my GitHub Repository. Drop a star if you find it useful.

1. Camel case

Screenshot_5.png

camel Case starts with a lowercase letter and the first letter of every new subsequent word has its first letter capitalized and is compounded(removing the space between two words) with the previous word. This is a very popular way to combine words to form a single one.

Use: It is often used in variable declaration in many languages.

Let's have a look at an example:

RAW:

hello world!

camel Case:

helloWorld!

So, this case combined words by capitalizing the first letter of each word except the first one.

2. Snake case

Screenshot_6.png Snake case combines words by replacing each space with an underscore (_) and lowercasing all the words. This one is the most used in Python. This is a nice, clean, readable way to combine words.

Use: Often used as in declaring constants in many languages.

Let's have a look at an example:

RAW:

my name is Ayushi

Snake case:

my_name_is_Ayushi

In the all caps version, all letters are capitalized, called as Capitalized Snake Case:

Let's have a look at an example:

RAW:

max student marks

Capitalized Snake Case:

MAX_STUDENT_MARKS

3. Kebab case

Screenshot_7.png This one is like Snake Case but instead of underscore, the dash is used, it combines words by replacing each space with a dash (-).

Use: This is rarely used in Python, but is often used in URLs.

Let's have a look at an example:

Raw:

total student count

Kebab Case:

total-student-count

4. Pascal case

Screenshot_9.png This case is also called Upper Camel Case, it combines all words by capitalizing all them(even the first word) and removing the space between them.

Use: It is often used as a convention in declaring classes in many languages such as Python like CalculateSum.

Let's have a look at an example:

Raw:

python is cool

Pascal Case:

PythonIsCool

Concluding Thoughts:

There is no best way to combine words. It majorly depends on the use case. Although it is suggested to be consistent with case style used and considered best to agree upon a common case style when working with a team.

Simple, isn't it? Hope this tutorial has helped and you have understood all Case Styles in programming.

I would strongly recommend you to Check out the YouTube video of the same and don't forget to subscribe to my Channel.

You can find all the code at my GitHub Repository. Drop a star if you find it useful.

Thank you for reading, I would love to connect with you at Twitter | LinkedIn.

Do share your valuable suggestions, I appreciate your honest feedback!

You should definitely check out my other Blogs:

See you in my next Blog article, Take care!!

Did you find this article valuable?

Support Ayushi Rawat by becoming a sponsor. Any amount is appreciated!