Development

개발할 때 변수이름을 작성하는 좋은 방법

sonpro 2023. 3. 27. 22:11
반응형

write

A Good Way to Write Variable Names When Developing

As a developer, writing code is a significant part of your job. You spend most of your time writing, reading, and debugging code. One of the essential aspects of writing code is naming variables. Variable names should be descriptive, concise, and easy to understand. In this blog post, we will discuss a good way to write variable names when developing.

Why is it important to write good variable names?

Writing good variable names is essential for several reasons. First, it makes your code more readable and understandable. When you or someone else reads your code, they should be able to understand what the variable represents without having to look it up. Second, it makes your code more maintainable. If you come back to your code months or years later, you should be able to understand what the variable represents and why you named it that way. Finally, it makes your code more professional. Good variable names show that you care about your code and take pride in your work.

Guidelines for writing good variable names

Here are some guidelines for writing good variable names:

1. Use descriptive names

Variable names should be descriptive and convey the purpose of the variable. For example, instead of using x or y as variable names, use more descriptive names like numberOfStudents or totalSales.

2. Use camelCase

When writing variable names, use camelCase. CamelCase is a convention where the first word is lowercase, and the first letter of each subsequent word is capitalized. For example, numberOfStudents is written in camelCase.

3. Avoid using abbreviations

Avoid using abbreviations in variable names. Abbreviations can be confusing and make your code harder to read. For example, instead of using numStud as a variable name, use numberOfStudents.

4. Use nouns for variable names

Variable names should be nouns that describe the data they hold. For example, firstName or lastName are good variable names because they describe the data they hold.

5. Use plural nouns for collections

If a variable holds a collection of data, use a plural noun for the variable name. For example, students is a good variable name for a collection of student data.

6. Use boolean names that start with "is" or "has"

If a variable holds a boolean value, use a name that starts with "is" or "has." For example, isStudent or hasPassed are good variable names for boolean values.

Example code

Here is an example of good variable names in Python:

numberOfStudents = 20 firstName = "John" lastName = "Doe" students = ["John", "Jane", "Bob"] isStudent = True 

Conclusion

Writing good variable names is essential for writing clean, readable, and maintainable code. By following the guidelines we discussed in this blog post, you can write variable names that are descriptive, concise, and easy to understand. Remember, good variable names show that you care about your code and take pride in your work.

반응형