articles directory
- 1. Ensure no error after code compression
- 2. Ensure that the code can be automatically formatted using the specific ide
- 3. Use standard document annotations
- 4. Use valid variable names
- 5. Ignore partial syntax
- 6. A Chinese character is not generated unless the statement is assigned a value.
- 7. Define a fixed number of parameters for a function.
- 8. Do not be keen on dynamic event binding
- 9. Reduced code and XHTML coupling
- 10. A function should return a unified data type.
- 11. Define JSON objects in a standard format and enclose double quotation marks.
- 12. Do not leave a code snippet in the file that is determined to be no longer in use in the future.
- 13. Do not repeatedly define the methods implemented by other team members.
- 14. Call appropriate methods
- 15. Use appropriate controls to store suitable data
- 16. Never ignore code optimization
- 17. Analysis of planning documents, interface definition and code organization using object-oriented methods
- 1. Ensure no error after code compression
- 2. Ensure that the code can be automatically formatted using the specific ide
- 3. Use standard document annotations
- 4. Use valid variable names
- 5. Ignore partial syntax
- 6. A Chinese character is not generated unless the statement is assigned a value.
- 7. Define a fixed number of parameters for a function.
- 8. Do not be keen on dynamic event binding
- 9. Reduced code and XHTML coupling
- 10. A function should return a unified data type.
- 11. Define JSON objects in a standard format and enclose double quotation marks.
- 12. Do not leave a code snippet in the file that is determined to be no longer in use in the future.
- 13. Do not repeatedly define the methods implemented by other team members.
- 14. Call appropriate methods
- 15. Use appropriate controls to store suitable data
- 16. Never ignore code optimization
- 17. Analysis of planning documents, interface definition and code organization using object-oriented methods
Original http://www.cnblogs.com/webflash/archive/2010/06/11/1756255.html
As a developer (Web Front-end Javascript development), nonstandard development not only enables future developmentCodeIt is difficult to maintain and change, and it is not conducive to Team Cooperation. It usually brings about code security and execution efficiency issues. I have been cooperating with colleagues who do not develop according to standards in my development work, so it cannot be described as "Pleasant" to work with him. Now I am writing this article to share with you a little bit of experience, but more hope to play a certain role for future partners. Of course, if I say that I have no subject, I also hope that many seniors will give me more advice. The following sections list various normative requirements. These requirements are raised for the coding problem of colleagues. Other normative requirements agreed by some industries may not be mentioned.
1. Ensure no error after code Compression
For large JavaScript projects, all the JavaScript files contained in the project are compressed during product release. For example, you can use Google closure Compiler service to compress the code, the new version of jquery has used this tool to compress the Code. This usually removes the comments written during development and removes all spaces and line breaks, you can even replace a long variable name with a short and meaningless variable name to accelerate file download, at the same time, it also reduces the additional data traffic caused by Website access, and also plays a role in code protection. At least the compressed code is not as easy to understand even if it is restored. To compress the code correctly, it is generally required that the statements should end normally with a semicolon and braces should also be strictly ended. The specific requirements of the compression tool should also be taken into account. Therefore, it would be a waste of time if the compression is not performed according to the standard at the beginning and the error is returned after the compression fails.
2. Ensure that the code can be automatically formatted using the specific ide
Generally, more sophisticated development tools (such as Aptana Studio) all have the "Automatic formatting" function of code, which helps to implement unified line breaks, indentation, spaces, and other code orchestrations, you can set your favorite format standard, for example, whether the left braces {start with another line. The purpose of achieving this is to help your development team members take a copy of your code and use ide to automatically format it into a style they like or are familiar with for reading. Your colleague needs to read your code, probably because you write a general method, which should also be used in the development process of other modules, read your code to get the most in-depth understanding of method calls and implementation details, which is not achieved by Simple API documentation.
3. Use standard document annotations
This requirement is the most basic, which helps to see the specific parameter passing prompt of the method in the method call, you can also use the supporting documentation tools to generate development documents in HTML or other formats for other team members to read. You can try to use jsdoc-toolkit. If the APIS you automatically generate come from an open platform, just like Facebook.com, your documents are provided to all developers in the world. In addition, you can write complete comments to make it easier for team members to read your code. With your parameter descriptions, team members can easily know how to pass the methods you have written to participate in implementation details. Of course, it is also convenient for code maintenance in the future, so that even if a large project, after a long time, you will not forget the code you wrote when you go back to change something.
4. Use standardized and meaningful variable names
Using standardized and meaningful variable names can improve code readability. As a member of the development of large projects, self-written code should not only be easy for others to understand. For large projects, the amount of code written by each person may be relatively large, with standardized names. In the future, your code can be clearly understood, such as system upgrades or new functions, it is much easier to modify the code. It would be a big joke if I found that I could not understand the code I wrote at the beginning.
Of course, use standard names for meaningful variable names. For example, VAR me = this may not be as good as VAR self = this, because self is a keyword in Python, in python, self is the common language of this. Let's look at the following example. The addition of S is obviously more scientific than the absence of addition, so that we can know that the variable name is stored in the plural, maybe an array, and so on:
VaR li = Document. getelementsbytagname ('lil ')
VaR Lis = Document. getelementsbytagname ('lil ')
5. Do not use biased syntax
As a dynamic scripting language, JavaScript has both advantages and disadvantages. As we all know, developers at different levels of dynamic languages may significantly differ in the specification or syntax of code written to implement the same function. In any case, the standard encoding is less funny, and the simple problem is not complicated, and the principle of easy coding is not violated.
For example, the statement typeof (B) = 'string' & alert (B) should be changed to: If (typeof (B) = 'string') Alert (B ), in the previous usage, the & operator parsing mechanism is used: If the & Pre-statement returns false, the following sentence will not be detected, in terms of code optimization, It is also mentioned that the most likely case should be judged first. For example, if there are few good conditions for writing, if there are many conditions and long statements, the code is quite readable.
Another example: + function (a) {var P = A;} ('A') should be changed to: (function (a) {var P = ;}) ('A'). In fact, the plus sign in front of the function has the same effect as the () bracket containing the function, and is used for computing priority, the latter is a common and easy-to-understand approach to prevent variable pollution. For example, some popular JavaScript frameworks adopt the following method.
Another example of reducing code readability is: function getpostiontxt (type) {return type = 2? "Field": (type = 3? "Mall": (type = 4? "Copy": NULL);} should be changed to: function getpostiontxt (type) {var typedata = {"2": "wild", "3": "mall ", "4": "copy"}; If (typedata [type]) return typedata [type]; else return NULL ;}. If type is an uninterrupted integer starting from 0, it is easier to directly use the array. This result looks much clearer. Do you see the nested headers of the preceding multi-layer ternary expressions not dizzy.
6. A Chinese character is not born in a place where the statement is not assigned a value.
The statement should not contain Chinese characters. I think most people know it, although this does not affectProgramRunning, but it is clear that there are industry standards, of course we are not using "easy language" for development. I didn't want to give it out, but I did not know whether it was because his English was really bad, at least pinyin can be used. In addition, it is a good choice to seek help from translation tools. I will give an example as follows, which can be understood as follows:
This. User ['name'] = 'zhang san' or this. User. Name = 'zhang san'
7. Define a fixed number of parameters for a function
A function with a fixed number of parameters does not use arguments to obtain parameters, because in this way, if the method you define contains more scripts, you cannot see at a glance what parameters and the number of parameters are accepted by this method. For example:
VaR $ = function () {return document. getelementbyid (arguments [0]);} should be changed to: var $ = function (elemid) {return document. getelementbyid (elemid );}
8. Do not be keen on dynamic event binding
Although we know that events can be dynamically bound, such as using addeventlistener or using jquery's bind method, we also know that dynamic event binding can make XHTML clean, however, in general, we recommend that you write the event on the DOM node directly. I think this will make the code easier to maintain.Source codeIn this case, you can easily know what methods are bound to an element. Simply put, it is easier to know what method scripts are called when a button or link is clicked.
9. Reduced code and XHTML Coupling
Instead of relying too much on some content features of the Dom to call different script codes, you should define methods for different functions and then call them on the Dom, regardless of whether the Dom is a button or a link, methods are called in the same way. For example, the following implementation may obviously have problems:
Function mybtnclick (OBJ)
{
If (/OK/. Test (obj. innerhtml ))
Alert ('OK ');
Else if (/cancel/. Test (obj. innerhtml ))
Alert ('cancel ');
Else
Alert ('other ');
}
<A herf = "javascript:;" onclick = "mybtnclick (this)"> OK </a> <a herf = "javascript:;" onclick = "mybtnclick (this) "> cancel </a>
The above example actually processes two things in a function and should be divided into two functions, such as the above statement. If you change the link to a button, for example, change it to the following: <input type = "button" onclick = "mybtnclick (this)" value = "OK"/>, the OBJ IN THE mybtnclick function. innerhtml has a problem because obj. value is correct. If you change the button name from Chinese to English, there will be too many problems.
10. A function should return a unified data type.
Because javascrip is of a weak type, some users may be casual in processing the returned type when writing functions. I think it should be returned like a strong type language. Let's look at the two examples below:
Function GetUserName (userid)
{
If (data [userid])
Return data [userid];
Else
Return false;
}
It should be changed:
Function GetUserName (userid)
{
If (data [userid])
Return data [userid];
Else
Return "";
}
If this method is defined in C #, we know that the data type to be returned should be a string, so if this data is not found, we should return an empty string, instead of returning a Boolean value or its unsuitable type. This does not affect future function calls, because the returned null string can be regarded as "non" in logic judgment, that is, it is the same as false, unless we use "=" or "typeof.
11. Define JSON objects with double quotation marks
It is certainly advantageous to use standards. Why do we still choose not to use standards? I think this may be a problem of laziness or habit. Someone may tell me that writing less quotation marks can reduce the file size. I think this makes sense, but it is not the point. For JSON data returned by the server, you can use the jsonview plug in the Firefox browser to conveniently view the JSON data (like viewing XML in a tree). In addition, if you use jquery for development, the latest version of jquery1.4 + has higher requirements on the JSON format. For details, refer to the jquery update document. For example, {name: "Tom"} or {'name': 'Tom '} should be changed to {"name": "Tom "}.
12. Do not leave a code snippet in the file that will not be used in the future
After the code is adjusted or restructured, the previously written code that is no longer used should be deleted in a timely manner. If you think the Code has some useful value, you can cut it into a temporary file. Staying in the project not only increases the file size, but also interferes with other members of the team and even themselves. I am afraid that I will not understand what this method will do if I look back at the code in the future, used. Of course, you can use the document comment tag @ deprecated to mark this method as not recommended.
13. Do not repeatedly define methods already implemented by other team members
For large projects, some developers usually implement some general methods, while others should be familiar with these general methods, then, you can directly call the module when you need to call it. Instead of reading these general method documents, some developers prefer "Single-stick, I wrote the implementation again in my own code, which not only produces redundant code, but also affects the development efficiency of the team. This is a result of no team spirit, it is the tragedy of repeating the wheel.
For example, in the common class file common. JS has a defined function $ (elemid) {return document. getelementbyid (elemid)} Should Not Be in mail. the repeated definition of this function is repeated in JS, which should be more appropriate for some complicated methods.
14. Call appropriate methods
When several methods can implement similar functions, we should choose the most appropriate method based on the scenario. The following describes two Ajax methods of the jquery framework. If you confirm that the data returned by the server is JSON, you should directly use $. getjson instead of using $. Get to get the data and convert it to a JSON object using the eval function. If $. post cannot be used because this request needs to transmit a large amount of data, you should also specify the data type returned (set the ype parameter. If $. getjson is used, we can see at a glance in the code that the request server returns JSON.
Tip: After jquery1.4, if the server has a contenttype set for data output, such as ASP. net C # Set response. contenttype = "application/JSON", then $. get will match $. there is no difference in the use of getjson.
15. Use appropriate controls to store suitable data
It was found that someone used Div to save JSON data for future use after the page is downloaded, like this: <Div id = "JSON"> {"name ": "Tom"} </div>, it is clear that this div is not used for interface display. If you have to do so, it can cache data using HTML files, it is more reasonable to use hidden fields to store this data, for example, <input type = "hidden" value = "{" name ":" Tom "}"/>.
In fact, you can also use the window object to save some data. In the example above, we can directly include such a script block on the Ajax request page: <SCRIPT> window. userdata = {"name": "Tom" };</SCRIPT>. After $ ("# mydiv" ).html (data) is executed in the Ajax request callback function, this variable is available immediately on the window. If the first method is used, Eval (document. getelementbyid ("userdata"). innerhtml) is inevitable ). If the window object stores a large amount of data, you need to manually clean the data in time when it is not used. They will disappear after the browser refreshes or restarts, which will increase the memory overhead.
16. Never ignore code optimization
Code optimization is the goal that every programmer should strive to achieve. It should also become the permanent pursuit of programmers. When writing code, you should not rush to implement the function. If you want to write code, the code execution efficiency is better.
For example, suppose there is a shortcut for defining getelementbyid functoin $ (elemid) {return document. getelementbyid (elemid)}, someone may write this code $ ("mydiv "). parentnode. removechild ($ ("mydiv"), in fact, the getelementbyid Dom query is executed twice here. It will be better if it is changed to this: var mydiv = $ ("mydiv"); mydiv. parentnode. removechild (mydiv ). Fortunately, the DOM search for getelementbyid is relatively fast. If you replace it with getelementsbytagname, you should pay more attention to optimization. The jquery development team also reminded everyone to pay attention to this issue.
Of course, code optimization skills also need to be accumulated by individuals. A friend once told me that he never thought about optimization when writing website back-end code, because their website uses Xeon quad-core servers, which I think is ridiculous.
17. Analysis of planning documents, interface definition and code organization using object-oriented methods
This capability is very important for every programmer. It is also an important factor that determines the level of a programmer. The ability to refine requirements and abstract different classes, and then write code in a systematic manner, so that the code structure is clear and readable, and the code is easy to maintain. It is not too procedural and messy, this is a good programmer.
Author: webflash
Source: http://webflash.cnblogs.com
The copyright of this article is shared by the author and the blog Park. You are welcome to repost this article. However, you must retain this statement without the author's consent and provide a clear link to the original article on the article page. Otherwise, you will be held legally liable.
As a developer (Web Front-end Javascript development), nonstandard development not only makes code maintenance difficult in the future, but also is not conducive to team cooperation, it usually brings about code security and execution efficiency issues. I have been cooperating with colleagues who do not develop according to standards in my development work, so it cannot be described as "Pleasant" to work with him. Now I am writing this article to share with you a little bit of experience, but more hope to play a certain role for future partners. Of course, if I say that I have no subject, I also hope that many seniors will give me more advice. The following sections list various normative requirements. These requirements are raised for the coding problem of colleagues. Other normative requirements agreed by some industries may not be mentioned.
1. Ensure no error after code Compression
For large JavaScript projects, all the JavaScript files contained in the project are compressed during product release. For example, you can use Google closure Compiler service to compress the code, the new version of jquery has used this tool to compress the Code. This usually removes the comments written during development and removes all spaces and line breaks, you can even replace a long variable name with a short and meaningless variable name to accelerate file download, at the same time, it also reduces the additional data traffic caused by Website access, and also plays a role in code protection. At least the compressed code is not as easy to understand even if it is restored. To compress the code correctly, it is generally required that the statements should end normally with a semicolon and braces should also be strictly ended. The specific requirements of the compression tool should also be taken into account. Therefore, it would be a waste of time if the compression is not performed according to the standard at the beginning and the error is returned after the compression fails.
2. Ensure that the code can be automatically formatted using the specific ide
Generally, more sophisticated development tools (such as Aptana Studio) all have the "Automatic formatting" function of code, which helps to implement unified line breaks, indentation, spaces, and other code orchestrations, you can set your favorite format standard, for example, whether the left braces {start with another line. The purpose of achieving this is to help your development team members take a copy of your code and use ide to automatically format it into a style they like or are familiar with for reading. Your colleague needs to read your code, probably because you write a general method, which should also be used in the development process of other modules, read your code to get the most in-depth understanding of method calls and implementation details, which is not achieved by Simple API documentation.
3. Use standard document annotations
This requirement is the most basic, which helps to see the specific parameter passing prompt of the method in the method call, you can also use the supporting documentation tools to generate development documents in HTML or other formats for other team members to read. You can try to use jsdoc-toolkit. If the APIS you automatically generate come from an open platform, just like Facebook.com, your documents are provided to all developers in the world. In addition, you can write complete comments to make it easier for team members to read your code. With your parameter descriptions, team members can easily know how to pass the methods you have written to participate in implementation details. Of course, it is also convenient for code maintenance in the future, so that even if a large project, after a long time, you will not forget the code you wrote when you go back to change something.
4. Use standardized and meaningful variable names
Using standardized and meaningful variable names can improve code readability. As a member of the development of large projects, self-written code should not only be easy for others to understand. For large projects, the amount of code written by each person may be relatively large, with standardized names. In the future, your code can be clearly understood, such as system upgrades or new functions, it is much easier to modify the code. It would be a big joke if I found that I could not understand the code I wrote at the beginning.
Of course, use standard names for meaningful variable names. For example, VAR me = this may not be as good as VAR self = this, because self is a keyword in Python, in python, self is the common language of this. Let's look at the following example. The addition of S is obviously more scientific than the absence of addition, so that we can know that the variable name is stored in the plural, maybe an array, and so on:
VaR li = Document. getelementsbytagname ('lil ')
VaR Lis = Document. getelementsbytagname ('lil ')
5. Do not use biased syntax
As a dynamic scripting language, JavaScript has both advantages and disadvantages. As we all know, developers at different levels of dynamic languages may significantly differ in the specification or syntax of code written to implement the same function. In any case, the standard encoding is less funny, and the simple problem is not complicated, and the principle of easy coding is not violated.
For example, the statement typeof (B) = 'string' & alert (B) should be changed to: If (typeof (B) = 'string') Alert (B ), in the previous usage, the & operator parsing mechanism is used: If the & Pre-statement returns false, the following sentence will not be detected, in terms of code optimization, It is also mentioned that the most likely case should be judged first. For example, if there are few good conditions for writing, if there are many conditions and long statements, the code is quite readable.
Another example: + function (a) {var P = A;} ('A') should be changed to: (function (a) {var P = ;}) ('A'). In fact, the plus sign in front of the function has the same effect as the () bracket containing the function, and is used for computing priority, the latter is a common and easy-to-understand approach to prevent variable pollution. For example, some popular JavaScript frameworks adopt the following method.
Another example of reducing code readability is: function getpostiontxt (type) {return type = 2? "Field": (type = 3? "Mall": (type = 4? "Copy": NULL);} should be changed to: function getpostiontxt (type) {var typedata = {"2": "wild", "3": "mall ", "4": "copy"}; If (typedata [type]) return typedata [type]; else return NULL ;}. If type is an uninterrupted integer starting from 0, it is easier to directly use the array. This result looks much clearer. Do you see the nested headers of the preceding multi-layer ternary expressions not dizzy.
6. A Chinese character is not born in a place where the statement is not assigned a value.
The statement should not contain Chinese characters. I think most people know that although this does not affect the program running, it is clear that there are industry-standard requirements. Of course, we are not using "easy language" for development. I didn't want to give it out, but I did not know whether it was because his English was really bad, at least pinyin can be used. In addition, it is a good choice to seek help from translation tools. I will give an example as follows, which can be understood as follows:
This. User ['name'] = 'zhang san' or this. User. Name = 'zhang san'
7. Define a fixed number of parameters for a function
A function with a fixed number of parameters does not use arguments to obtain parameters, because in this way, if the method you define contains more scripts, you cannot see at a glance what parameters and the number of parameters are accepted by this method. For example:
VaR $ = function () {return document. getelementbyid (arguments [0]);} should be changed to: var $ = function (elemid) {return document. getelementbyid (elemid );}
8. Do not be keen on dynamic event binding
Although we know that events can be dynamically bound, such as using addeventlistener or using jquery's bind method, we also know that dynamic event binding can make XHTML clean, however, in general, it is recommended that you write the event on the DOM node directly. In my opinion, this can make the code easier to maintain, when viewing the source code, we can easily know what element is bound to and what method script is called when a button or link is clicked.
9. Reduced code and XHTML Coupling
Instead of relying too much on some content features of the Dom to call different script codes, you should define methods for different functions and then call them on the Dom, regardless of whether the Dom is a button or a link, methods are called in the same way. For example, the following implementation may obviously have problems:
Function mybtnclick (OBJ)
{
If (/OK/. Test (obj. innerhtml ))
Alert ('OK ');
Else if (/cancel/. Test (obj. innerhtml ))
Alert ('cancel ');
Else
Alert ('other ');
}
<A herf = "javascript:;" onclick = "mybtnclick (this)"> OK </a> <a herf = "javascript:;" onclick = "mybtnclick (this) "> cancel </a>
The above example actually processes two things in a function and should be divided into two functions, such as the above statement. If you change the link to a button, for example, change it to the following: <input type = "button" onclick = "mybtnclick (this)" value = "OK"/>, the OBJ IN THE mybtnclick function. innerhtml has a problem because obj. value is correct. If you change the button name from Chinese to English, there will be too many problems.
10. A function should return a unified data type.
Because javascrip is of a weak type, some users may be casual in processing the returned type when writing functions. I think it should be returned like a strong type language. Let's look at the two examples below:
Function GetUserName (userid)
{
If (data [userid])
Return data [userid];
Else
Return false;
}
It should be changed:
Function GetUserName (userid)
{
If (data [userid])
Return data [userid];
Else
Return "";
}
If this method is defined in C #, we know that the data type to be returned should be a string, so if this data is not found, we should return an empty string, instead of returning a Boolean value or its unsuitable type. This does not affect future function calls, because the returned null string can be regarded as "non" in logic judgment, that is, it is the same as false, unless we use "=" or "typeof.
11. Define JSON objects with double quotation marks
It is certainly advantageous to use standards. Why do we still choose not to use standards? I think this may be a problem of laziness or habit. Someone may tell me that writing less quotation marks can reduce the file size. I think this makes sense, but it is not the point. For JSON data returned by the server, you can use the jsonview plug in the Firefox browser to conveniently view the JSON data (like viewing XML in a tree). In addition, if you use jquery for development, the latest version of jquery1.4 + has higher requirements on the JSON format. For details, refer to the jquery update document. For example, {name: "Tom"} or {'name': 'Tom '} should be changed to {"name": "Tom "}.
12. Do not leave a code snippet in the file that will not be used in the future
After the code is adjusted or restructured, the previously written code that is no longer used should be deleted in a timely manner. If you think the Code has some useful value, you can cut it into a temporary file. Staying in the project not only increases the file size, but also interferes with other members of the team and even themselves. I am afraid that I will not understand what this method will do if I look back at the code in the future, used. Of course, you can use the document comment tag @ deprecated to mark this method as not recommended.
13. Do not repeatedly define methods already implemented by other team members
For large projects, some developers usually implement some general methods, while others should be familiar with these general methods, then, you can directly call the module when you need to call it. Instead of reading these general method documents, some developers prefer "Single-stick, I wrote the implementation again in my own code, which not only produces redundant code, but also affects the development efficiency of the team. This is a result of no team spirit, it is the tragedy of repeating the wheel.
For example, in the common class file common. JS has a defined function $ (elemid) {return document. getelementbyid (elemid)} Should Not Be in mail. the repeated definition of this function is repeated in JS, which should be more appropriate for some complicated methods.
14. Call appropriate methods
When several methods can implement similar functions, we should choose the most appropriate method based on the scenario. The following describes two Ajax methods of the jquery framework. If you confirm that the data returned by the server is JSON, you should directly use $. getjson instead of using $. Get to get the data and convert it to a JSON object using the eval function. If $. post cannot be used because this request needs to transmit a large amount of data, you should also specify the data type returned (set the ype parameter. If $. getjson is used, we can see at a glance in the code that the request server returns JSON.
Tip: After jquery1.4, if the server has a contenttype set for data output, such as ASP. net C # Set response. contenttype = "application/JSON", then $. get will match $. there is no difference in the use of getjson.
15. Use appropriate controls to store suitable data
It was found that someone used Div to save JSON data for future use after the page is downloaded, like this: <Div id = "JSON"> {"name ": "Tom"} </div>, it is clear that this div is not used for interface display. If you have to do so, it can cache data using HTML files, it is more reasonable to use hidden fields to store this data, for example, <input type = "hidden" value = "{" name ":" Tom "}"/>.
In fact, you can also use the window object to save some data. In the example above, we can directly include such a script block on the Ajax request page: <SCRIPT> window. userdata = {"name": "Tom" };</SCRIPT>. After $ ("# mydiv" ).html (data) is executed in the Ajax request callback function, this variable is available immediately on the window. If the first method is used, Eval (document. getelementbyid ("userdata"). innerhtml) is inevitable ). If the window object stores a large amount of data, you need to manually clean the data in time when it is not used. They will disappear after the browser refreshes or restarts, which will increase the memory overhead.
16. Never ignore code optimization
Code optimization is the goal that every programmer should strive to achieve. It should also become the permanent pursuit of programmers. When writing code, you should not rush to implement the function. If you want to write code, the code execution efficiency is better.
For example, suppose there is a shortcut for defining getelementbyid functoin $ (elemid) {return document. getelementbyid (elemid)}, someone may write this code $ ("mydiv "). parentnode. removechild ($ ("mydiv"), in fact, the getelementbyid Dom query is executed twice here. It will be better if it is changed to this: var mydiv = $ ("mydiv"); mydiv. parentnode. removechild (mydiv ). Fortunately, the DOM search for getelementbyid is relatively fast. If you replace it with getelementsbytagname, you should pay more attention to optimization. The jquery development team also reminded everyone to pay attention to this issue.
Of course, code optimization skills also need to be accumulated by individuals. A friend once told me that he never thought about optimization when writing website back-end code, because their website uses Xeon quad-core servers, which I think is ridiculous.
17. Analysis of planning documents, interface definition and code organization using object-oriented methods
This capability is very important for every programmer. It is also an important factor that determines the level of a programmer. The ability to refine requirements and abstract different classes, and then write code in a systematic manner, so that the code structure is clear and readable, and the code is easy to maintain. It is not too procedural and messy, this is a good programmer.