In actual programming, what good habits are worth learning and persisting from the beginning?
“Standardize your own code, have less personal style, and add necessary comments”
This is the principle that I have always adhered to during the coding process.
What good habits do you have during the coding process? Welcome to share and leave messages!
Tens of millions of lines of code, the first line of comments, the naming is not standardized, my colleagues cried after two lines
1. Camel hump
Camel hump is divided into small hump and large hump;
a): small hump: the first letter of the first word is lowercase, and the first letter of the second word is lowercase. The letters are capitalized, such as userName
b): Camel case: the first letter of each word is capitalized, such as UserName
2, naming
Shorter words can The vowels are removed to form an abbreviation, and longer words can be represented by the first few characters of the word. Private methods and properties should start with an underscore "_", and the words used when naming should try to use the English words they play a role in.
3. Indentation
Appropriate indentation can make the code structure clearer. Generally, a tab, 4 spaces or 2 spaces are used for indentation.
4. Space
Under normal circumstances, a space will be added before the "{", "}", "+", and "=" symbols. No space will be added when calling the method. Define When using anonymous functions, add a space.
5. Comments
When modifying other people's code, indicate the time, name and reason before and after the commented-out content. When adding new functions, indicate the time, name and general function. Increase readability and maintainability.
If you encounter something you don’t understand, check the official manual first. Most of the official manuals may be in English. Just use a translation tool to translate it carefully and try to understand it yourself
In the process of writing code, you must pay attention to the development of good habits. For example, when naming, you should make clear the difference between big hump and small hump
And try to use meaningful and simple word naming
When writing code, you should also pay attention to indentation, spaces and comments to enhance the readability of the code. and maintainability
Recommend a course document: "PHP Development Coding Specifications" //m.sbmmt.com/course/982.html
The document contains detailed PHP code specifications, PHP annotation specifications, etc. The PHP coding specification is mainly to better improve the work efficiency of PHP developers, ensure the effectiveness and rationality of development, and improve the readability and reusability of program code. The value of this specification is that we all follow this Coding style.
Standardize the code, take notes frequently, learn more and practice more!