View myselfArticleIndex Via http://www.cnblogs.com/seesea125/archive/2012/04/17/2453256.html
Motivation: Rename is the most basic and simple refactoring of refactoring, But This refactoring is also very important.CodeThe key first step for readability is "to become a real programmer, the level of name is crucial". If you see a function name, it cannot express its purpose very well, it should be modified immediately. Remember, your code is first written for humans, and then for computers. And people need functions with good names ."
Method: first consider how to annotate the function, and then try to annotate the function name.
Note:
Do not be afraid of long names. length is not a problem. The key lies in the semantic distance between the function name and the function ontology.
2. You must name the method name, including the class name, parameter name, control name, And webform, however, each team should have a unified specification.
Example:
/// <Summary> /// Determine if it is a technology department /// </Summary> /// <Returns> </returns> Public Bool Isscience ( Int Departmentid, String ID) {Datatable dt = Attendance. getdepmentid (ID ); Bool DTT = ( From Column In DT. asenumerable () Select Column [ " ID " ]). Contains (dimension mentid ); If (DTT ){ Return True ;} Else { Return False ;}}
First, isscience made others unable to understand what it meant, and another string ID parameter did not know what it meant, and DTT did not know what it meant.
The code after reconstruction is as follows:
/// <Summary> /// Determine if it is a technology department /// </Summary> /// <Returns> </returns> Public Bool Ifmintech ( Int Departmentid, String Departmentidlist) {Datatable dt = Getmintechallinclumentid (inclumentidlist ); Bool I Sdepartmentid = ( From Column In DT. asenumerable () Select Column [ " ID " ]). Contains (dimension mentid ); If (ISdepartmentid){ Return True ;} Else { Return False ;}}
Although the Refactoring is simple, the effect is obvious. Remember that we write code for people, instead of writing code for computers. If the name does not reflect the intention of the code, you can immediately get rid of it, otherwise, it will waste you countless times to read and understand the code. What's more annoying is that you have read and understood the code today, and you have to read and understand it again in a few days.