CSC/ECE 517 Fall 2010/ch5 5b RR: Difference between revisions
No edit summary |
No edit summary |
||
Line 10: | Line 10: | ||
In this chapter, we are mainly going to look at some rules and guidelines to choose good variable names. | In this chapter, we are mainly going to look at some rules and guidelines to choose good variable names. | ||
</p> | </p> | ||
==Advantages of using naming conventions== | |||
<ol> | |||
<li>Having good names provides additional information (metadata) to programmers about what the variables are used for. As in the example above, a good name goes a long way in giving out specific use of variable which makes code more readable.</li> | |||
<li>Having a convention or standard helps in having a consistent look to the code. When the development team is large and various people are working on various parts of a project, looking at some other section of the code should not look very different from what someone has written themselves.</li> | |||
<li>Conventions usually will have rules or guidelines to sort out naming of variables or other structures in code to avoid potential ambiguity.</li> | |||
<li>When we use naming conventions, we are forced to use meaningful and professional names rather than cute or funny names. Having good names gives good appearance to the program.</li> | |||
<li>In the case of code reuse after a long interval of time, having a well defined naming convention can help provide better understanding of code.</li> | |||
<li>Well-chosen names make it significantly easier for subsequent generations of analysts and developers to understand what the system is doing and how to fix or extend the source code for new business needs.</li> | |||
</ol> |
Revision as of 01:00, 4 November 2010
Variable Naming Conventions
Almost all programming languages allow the programmer a great deal of freedom when naming variables in a program's source code. But choosing good names is hard. This is a tutorial on how to choose good variable names!
Introduction
Naming conventions is one topic in programming that has probably not been emphasized enough. There has always been a debate about its importance and effort taken to learn and follow them. Naming conventions make programs more understandable by making them easier to read. They can also give information about the function of the identifier-for example, whether it's a constant, package, or class-which can be helpful in understanding the code thereby reducing development time specially when the code is large.
As an example, say a variable holds the average age of students in a class. Int averageAge or int AverageAge gives a lot of information to the programmer about what the variable does than say just int a; Also capitalizing the very first letter of every word makes it more readable than just int averageage.
In this chapter, we are mainly going to look at some rules and guidelines to choose good variable names.
Advantages of using naming conventions
- Having good names provides additional information (metadata) to programmers about what the variables are used for. As in the example above, a good name goes a long way in giving out specific use of variable which makes code more readable.
- Having a convention or standard helps in having a consistent look to the code. When the development team is large and various people are working on various parts of a project, looking at some other section of the code should not look very different from what someone has written themselves.
- Conventions usually will have rules or guidelines to sort out naming of variables or other structures in code to avoid potential ambiguity.
- When we use naming conventions, we are forced to use meaningful and professional names rather than cute or funny names. Having good names gives good appearance to the program.
- In the case of code reuse after a long interval of time, having a well defined naming convention can help provide better understanding of code.
- Well-chosen names make it significantly easier for subsequent generations of analysts and developers to understand what the system is doing and how to fix or extend the source code for new business needs.