Joke Collection Website - Joke collection - Java training of Beida Jade Bird: How to standardize your own code editing methods?
Java training of Beida Jade Bird: How to standardize your own code editing methods?
Today, let's look at the requirements of standardized code writing.
I hope that by reading this article, I can improve my understanding of code specifications.
1. Guarantees that there will be no errors after code compression. For a large JSP project, when the product is released, all JSP files contained in the project are usually compressed. For example, you can use GoogleClosureCompilerService to compress code. The new version of jQuery uses this tool to compress the code. It usually deletes comments written during development and removes all spaces and line breaks. You can even replace the long variable name with a short and meaningless variable name. The purpose of this is to speed up the download of files and reduce the extra data traffic caused by website visits. In addition, it also plays a little role in code protection, at least the compressed code is not so good to read even after restoration.
In order to make the code pass the compression correctly, it is usually required that the statement should end with a semicolon normally, the braces should end strictly, and so on. , depending on the requirements of the compression tool.
So it's a waste of time if you don't follow the standard at first, compress the error and then go back to find it.
2. Ensure that the code can pass the automatic formatting function of a specific IDE. Generally, relatively perfect development tools (such as AptanaStudio) have the function of "automatic formatting" of codes, which is helpful to realize uniform code arrangement such as line breaks, indents and spaces. You can set your favorite format standards, such as opening braces {Do you want to start a new line?
The purpose of implementing this requirement is to make it convenient for development team members to get a copy of the code and use IDE to automatically format it into a style they like or are familiar with.
Your colleagues need to look at your code, probably because you have written a general method, which also needs to be used in the development of other modules. Reading your code can give you a deeper understanding of the details of method calling and implementation, which is beyond the reach of simple API documents.
3. The requirement of using standard document comments is basic, which is beneficial to see the specific parameters of the method at the method call. You can also use the document support tool to generate development documents in html or other formats for other team members to read. You can try jsdoc-toolkit.
If your automatically generated API comes from an open platform, just like the facebook.com application, then your documentation is for all developers in the world.
In addition, writing complete comments makes it easier for team members to read your code. Through your parameter description, team members can easily know the details of the method you wrote and participate in its implementation.
Of course, it is also convenient for future code maintenance, so that even if it is a big project, after a long time, you will not forget what you wrote when you go back to change things.
4. Use standardized and meaningful variable names. Using standardized and meaningful variable names can improve the readability of the code. As a member of large-scale project development, the code written by yourself should not only be easy for others to understand.
Computer training/thinking that the development of large-scale projects, in fact, everyone may have written a lot of code, standardized naming, and later look back at their own code is also clear and easy to understand, such as future system upgrades or new functions, it is much easier to modify the code.
If you find that you can't even understand the code you wrote at the beginning, it's all wet.
- Related articles
- The name of a TVB TV series.
- Seeking vulgar and funny allegorical sayings
- Tu Tu with Big Ears Season 4 Episode 1 Why is it terrible?
- What if NBA bosses pay players privately to avoid luxury taxes? What is the basis?
- My wife dresses casually at home, but she dresses beautifully at her parents' house. Why?
- What kind of person does the warehouse manager need to find?
- Eunuch joke in late Qing dynasty
- The Diversified Plots of Liaozhai II in Haicheng, Luo Cha
- Some incisive sentences [essence] praising women's cooking skills and high emotional intelligence
- An essay on fighting "pox"