“I want to know what kind of variable names are good for programming”
“I wonder what kind of variable names are available”
Don’t you think?
Even if you try to give a variable name in programming, you will get lost as to how to give it.
What are some ways to name variables?
So this time
- What are good variable names in programming
- How to assign variables in programming
- Naming conventions to help with naming variables etc.
I will explain in detail about.
Read this article to learn how to name variables in programming .
Table of contents
- What are good variable names in programming
- 1. What is a good variable name
- 2. Why you should use good variable names
- 3. Concrete examples of good variables
- 8 good ways to name variables in programming
- 1. Use nouns
- 2. Be as specific as possible
- 3. Incorporate the information you need
- 4. Avoid Japanese (Romaji)
- 5. Do not include meaningless words
- 6. Aggregates Use Plural Forms
- 7. Write the boolean type in the form of a question
- 8. Keep the names of related data intact
- 5 naming conventions to refer to
- 1. Snake Case: Use Underbar
- 2. CamelCase: mix capital letters
- 3. Constant case: use uppercase letters and underscores
- 4. PascalCase: Capitalize at the beginning and in the middle
- 5. Chain case (kebab case): use hyphens
- Introducing examples of words that can be used in programming variable names in 5 different situations
- 1. User authentication/privileges
- 2. Network
- 3. Data input/output
- 4. Database
- 5. Make changes to your data
- Two Questions for Programming Beginners
- 1. What is a programming variable?
- 2. What is codic
- Summary: If you use variable names in programming, create a unified rule
What are good variable names in programming
Let’s take a look at what makes good variable names in programming.
Inappropriate variable names can lead to trouble later .
- How to assign good variables
- Why you should use good variable names
- Examples of good variables
Let’s take it step by step.
1. What is a good variable name
Good variable names make it clear what data is stored .
Because you don’t know when and who will use the variable, review or rewrite the code.
It should be as concise and specific as possible.
2. Why you should use good variable names
Thinking of variable names can be difficult, but good variable names are important.
- A variable appears multiple times in a program
- Code can be rewritten many times
- The larger the program, the more people involved in its development
Because there is a reason.
By giving a good variable name, it becomes clear what the data inside the variable represents, and you don’t need to go back to the initial settings one by one .
So be sure to give it a proper name so you don’t get in trouble later.
3. Concrete examples of good variables
A good variable name makes it easy to understand what the data inside is.
Specific examples are as follows.
At a glance you can see what values are stored .
Make the name as specific as possible.
8 good ways to name variables in programming
Let’s take a look at how to name good variables in programming.
Anyone can come up with good variable names if the correct rules are followed .
- use nouns
- be as specific as possible
- Incorporate the necessary information
- Avoid Japanese (Romaji)
- don’t use meaningless words
- Aggregates use plural forms
- boolean type is written in question form
- Use the name of the related data as is
Please see each.
Use nouns for variable names.
This is because the variable itself is a noun in the first place .
Use adjectives and passive verbs to make it more specific, based on nouns.
When writing variable names, remember that the base is a noun.
Variable names should be as specific as possible.
The reason is that variables are assumed to appear in various places, so it is better to make it easy to understand what they represent at a glance .
A specific name also helps when sharing with your team.
As much as possible, try to use a name that other people can recognize.
Try to include the necessary information in your variable names, even if they are a bit long.
This is because it is easy to understand what kind of data is contained without looking back at the code from the beginning .
For example, if you decide in advance what kind of information you want to put in, you won’t get lost when deciding on variable names.
So be sure to include the necessary information when naming your variables.
It is better to avoid using Japanese in variable names.
- programming is in english
- Continuing words are difficult to understand
- Pronunciation is written differently by different people
This is because the programming language is based on English .
After all, it can be said that it is natural and easy to understand to use the English notation that is the base.
Variable names should not contain meaningless words.
The reason is that typing is hard when it is unnecessarily long .
It can’t be helped to put in the necessary information and become long.
But don’t let it go unnecessarily long.
A good tip for increasing specificity is to use the plural form for collectives.
It is easy to understand what kind of data should be entered .
Aggregation is the following data.
- array or list
Plural words are recommended for variables that store multiple pieces of data like this.
A question form can be used for a variable that stores a boolean type.
This is because it becomes clear which is true or false .
For a simple naming example,
Answer this question with a true if yes and a false if no.
If there is data associated with the variable name, just use that name.
Using a different name can get confusing later.
Good examples are database tables and columns.
If you want to store the values of a table or column, you should use the table name and column name as they are .
5 naming conventions to refer to
Here are some naming conventions for your reference.
In fact , there are many publicly recognized naming conventions .
- Snake Case: Use Underbar
- camel case: mix uppercase
- Constant case: use capital letters and underscores
- PascalCase: Capitalize first and middle
- Chain case (kebab case): use hyphens
Knowing each makes it easier to communicate when sharing with others.
1. Snake Case: Use Underbar
Snake case is a naming convention that uses an underscore.
Connect words with underscores .
For example, the following are variable names using snake case:
This is a rule often used in languages such as Python.
2. CamelCase: mix capital letters
CamelCase is a naming convention that mixes uppercase letters.
Lowercase the first word and capitalize the first word of the second .
3. Constant case: use uppercase letters and underscores
Constant case is a naming convention that combines capital letters and underscores.
All caps and underscores between words .
Within the project, it is used for common global variables, etc.
4. PascalCase: Capitalize at the beginning and in the middle
PascalCase is a naming convention with initial and intermediate capital letters.
Capitalize only the beginning of each word .
- My View
- Connected Line
The method used in class names, which must be capitalized.
5. Chain case (kebab case): use hyphens
Chaincase (kebab case) is a naming convention that uses hyphens.
Connect words with hyphens .
- navigation bar
Often used in HTML classes, tag attributes, etc.
Introducing examples of words that can be used in programming variable names in 5 different situations
Here are some examples of words that can be used as variable names in programming.
Different words are used depending on the situation .
- User authentication/privileges
- Data input/output
- make changes to the data
Verbs are used in the passive voice, and are used in combination with nouns.
Let’s take a look at each.
1. User authentication/privileges
Words used in user authentication and authorization are often used.
This is because it is common to restrict user access in things such as web app development .
The words that can be used for user authentication and authorization are as follows.
- certification: three-way authentication
- authentication: two-way authentication
- identification: user/user identification
- permission: permissions and access restrictions
- allow/deny: allow/deny
It is a word that can be used for access restrictions and password authentication.
Let’s memorize the words of the network.
This is because many applications are linked with other systems such as servers and databases .
- connect/disconnect: State in which communication is possible/state in which communication is not possible
- request/response: request/response
These can be used to store communication values, etc.
3. Data input/output
It is also important to use words related to data input/output in appropriate situations.
This is because various programs need to transfer data in and out .
- load: load
- save: to save
- input/output: input/output
- set/get: to set/get
Verb words should be in the passive voice and combined with other nouns.
Also remember some database related words.
It will be used extensively not only for internal systems but also for web applications .
- create/drop: create/drop (a database)
- select: select (columns or tables)
- insert: insert (a column)
- table: table
- column: column
Mainly in the SQL language for databases, use the words as they are used.
Using the database columns as they are has the advantage of being easy to code.
5. Make changes to your data
Also remember the words for making changes to the data.
The more words you have, the easier it will be to create variable names that are easier to understand .
- to: to ◯◯
- merge: combine
- change: change
- join: connect
- exclude/include: exclude/include
Using these words makes it easier to understand what the variable contains.
So when you make changes to your data, it’s important to use them wisely.
Two Questions for Programming Beginners
I will answer the frequently asked questions of programming beginners.
Because one day you may have the same question or meet someone on your team who has the same question .
- What is a variable in programming
- What is codic
Let’s take a look at each.
1. What is a programming variable?
Variables in programming are like boxes that store data .
This is because normally the output data will be neglected as it is.
Data that you want to use many times can be reused by storing it in a box called a variable.
The following words are similar to variables, so let’s distinguish them.
- Constant: A group of data that cannot be changed unlike a variable
- Object: Anything that can be processed by a computer
- Class: A model or template for an object
- Properties: information attached to an object
- Method: A collection of one process
Variables are also used in objects and classes to store data.
2. What is codic
codic is a naming tool that can be used when naming variables and functions .
- No download required: works in your browser
- free to use
- Automatic translation from Japanese to English
- Join words with underscores
There are features such as
Thinking of variable names takes time to get used to, so it is recommended to use codic until you get the hang of it.
Summary: If you use variable names in programming, create a unified rule
In this article, I have explained how to assign variable names in programming.
- Good variable names in programming are always easy to understand
- There are many ways to name variables in programming.
- Referencing naming conventions makes it easier to name variables
Some people are confused about what to name programming variables, but there is no answer to how to name variables.
However, if you just put it on freely, someone will be in trouble later.
So it’s important to follow naming conventions that match your programming language.
Any rule is fine, but I recommend that you make it consistent within yourself and your team so that it is specific and easy to understand .