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
- camelCase for naming variables
- PascalCase for classes
React
- PascalCase for naming files and components
Python
- snake_case for method names
- UPPER_CASE_SNAKE_CASE for constants
Ruby
- PascalCase for classes and modules
- UPPER_CASE_SNAKE_CASE for constants
- 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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.