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…


This content originally appeared on DEV Community and was authored by catherineisonline

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";

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";

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";

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";

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";

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? 👀


This content originally appeared on DEV Community and was authored by catherineisonline


Print Share Comment Cite Upload Translate Updates
APA

catherineisonline | Sciencx (2022-07-25T14:16:59+00:00) Most Common Programming Case Types. Retrieved from https://www.scien.cx/2022/07/25/most-common-programming-case-types/

MLA
" » Most Common Programming Case Types." catherineisonline | Sciencx - Monday July 25, 2022, https://www.scien.cx/2022/07/25/most-common-programming-case-types/
HARVARD
catherineisonline | Sciencx Monday July 25, 2022 » Most Common Programming Case Types., viewed ,<https://www.scien.cx/2022/07/25/most-common-programming-case-types/>
VANCOUVER
catherineisonline | Sciencx - » Most Common Programming Case Types. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/07/25/most-common-programming-case-types/
CHICAGO
" » Most Common Programming Case Types." catherineisonline | Sciencx - Accessed . https://www.scien.cx/2022/07/25/most-common-programming-case-types/
IEEE
" » Most Common Programming Case Types." catherineisonline | Sciencx [Online]. Available: https://www.scien.cx/2022/07/25/most-common-programming-case-types/. [Accessed: ]
rf:citation
» Most Common Programming Case Types | catherineisonline | Sciencx | https://www.scien.cx/2022/07/25/most-common-programming-case-types/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.