DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Most common programming case types
catherineisonline
catherineisonline

Posted on • Updated on

Most common programming case types

When you dive into programming you will notice how casing and naming things is not exactly same as it is in proper English language. Naming a variable UserIput or userinput makes a big difference. You may be learning a language where it does not matter however sticking to the rules will help you in your future learning of other languages.

In this article we will go through the basics of case types however beside the difference, the most important lesson to remember is this: never name the same variable with different case types and be consistent with it.
_Do_not Change it hereAnd there because You MAY EndUp with Bugs! _

camelCase

When it comes to camelCase, you always need to start with lowercase word and every next word needs to be uppercase.

Example:

const firstName = "Andy";
const lastName = "Powers";
const emailAddress = "andyp@mail.com";
Enter fullscreen mode Exit fullscreen mode

PascalCase

Unlike camelCase, every word starts with uppercase letter, even the first one.

Example:

const FirstName = "Andy";
const LastName = "Powers";
const EmailAddress = "andyp@mail.com";
Enter fullscreen mode Exit fullscreen mode

snake_case

In this case, every word needs to be in lowercase letter however we separate then using underscore ("_").

Example:

const first_name = "Andy";
const last_name = "Powers";
const email_address = "andyp@mail.com";
Enter fullscreen mode Exit fullscreen mode

UPPER_CASE_SNAKE_CASE

UPPER_CASE_SNAKE_CASE is almost same like regular snake_case however instead of lowercase letters, all letter need to be uppercase this time.

Example:

const FIRST_NAME = "Andy";
const LAST_NAME = "Powers";
const EMAIL_ADDRESS = "andyp@mail.com";
Enter fullscreen mode Exit fullscreen mode

kebab-case

kebab-case visually is really almost like dΓΆner kebab. Every word is in lowercase letter separated by the hyphen, dash, subtract, negative or minus sign.

Example:

const first-name = "Andy";
const last-name = "Powers";
const email-address = "andyp@mail.com";
Enter fullscreen mode Exit fullscreen mode

Which one to use?

First, it depends on the language you use and how sensitive it is to case type.
Secondly, depends on your preference.
Lastly, depends on how the variables has been declared from the very beginning.

Personally, I use JavaScript and I love using camelCase. In React I also use PascalCase. For me, it mostly happened for accident. I just saw how everyone was doing it and I did the same without really learning the reason I use this or that.
If you are a beginner like me and most likely you know one or two languages, I just suggest sticking to the case which is common in the language you use.

Here are several common examples that has become a general rule, convention:

JavaScript

  1. camelCase for naming variables
  2. PascalCase for classes

React

  1. PascalCase for naming files and components

Python

  1. snake_case for method names
  2. UPPER_CASE_SNAKE_CASE for constants

Ruby

  1. PascalCase for classes and modules
  2. UPPER_CASE_SNAKE_CASE for constants
  3. snake_case for variables and methods

So, which case type do you love to use? πŸ‘€

Top comments (0)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.