Home > Web Front-end > JS Tutorial > body text

What are the rules for writing code in web development?

零下一度
Release: 2017-06-26 10:00:10
Original
1316 people have browsed it

I am the least able to fly among the rookies, so I have not developed these basic habits. I just took the time to make a note to facilitate myself to standardize the code. Anyone who is interested can give me some advice.

There are many benefits to developing good coding habits. Let’s summarize the details that should be paid attention to when coding. "Learning from Code Constraints in Gaoyingli". By the way, I silently complain that those institutions that say that the front-end does not require English basics are really losing money. Zhi;

a. Naming constraints: Hungarian naming/camel case naming/Pascal nomenclature

Hungarian naming: This naming method can be subdivided into system Hungarian nomenclature and Hungarian application nomenclature.

 -> Syntax: variable name = type + description

 ->Convention type:

 a --- array

 o --- object

s --- string

l --- float

fn --- function

i --- int

r --- regular

b --- boolean

Camel case naming (little camel case naming method): The first word starts with a lowercase letter, and the first letters of all subsequent words use the same Capital letters;

Pascal naming (camel case naming): the first letter of each word is capitalized;

1. Variable naming: noun

2. Method naming: Verb

->Common verb convention:

can --- Determine whether an action can be performed

has --- Determine whether there is a certain value

is --- Determine whether it is a certain value

get --- Get a certain value

set --- Set a certain value

load -- - Load some data

3. Special function/variable naming convention:

1): Constants: All capital words are separated by "_";

2 ): Constructor: Big camel case naming;

 3): Private members (properties/methods): Prefixed with "_";

b. Coding is not a rigid principle:

1. The Event object is not passed. If necessary, only the required data can be passed;

2. The application layer logic can be carried out without relying on any behavior;

3. The event layer only Handle events;

4. Single code responsibility;

5. Respect object ownership, that is, only modify objects created by yourself;

6. Avoid global variables;

c. Code performance

1. Avoid global search and minimize the search scope chain length;

2.With,eval,setTimeout first parameter character form, Function avoid using;

3. Loop optimization

 ->Decrement iteration

 ->Simplify the termination condition

 ->Simplify the loop body

 -> Try to use post-test loops, that is, do-while

4. Minimize the number of statements;

5. Bit operations on numerical values ​​are faster;

6 .Optimize DOM operation (there are a lot of things that need to be studied in this area and I won’t share them for a while);

d: Common identifiers for code comments:

1.@author Instructions for the author of the program

2.@version The version description of the source file

3.@param The parameter description of the method

4.@deprecated Not recommended usage

5.@return The description of the return value of the method

6.@see, used to specify the reference content

7.@exception The exception type thrown

8 .@throws Exception thrown

9.@example Sample code

So many notes. I slowly developed it;

The above is the detailed content of What are the rules for writing code in web development?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!