Code specification for novice Web developers

Source: Internet
Author: User

The author rookie of the most will not fly, so these basic habits are not formed, just take time to deliberately make a note to facilitate their code, interested in the big guy more guidance.

Good coding habits to develop a lot of money, summed up the code should pay attention to the details of "reference elevation codes", The silent Spit groove, said that the front-end does not need the foundation of English those institutions are really to lose their wisdom;

A. Naming constraints: Hungarian naming/Hump naming/Pascal nomenclature

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

Syntax: variable name = type + Description

Convention type:

A---array

O---Object

s---string

L---Float

FN---function

I---int

R---Regular

B---Boolean

Hump naming (Small hump nomenclature): The first word starts with a lowercase letter, and the first letter of all subsequent words is capitalized;

Pascal's name (Big hump nomenclature): The first letter of each word is capitalized;

1. Variable name: noun

2. Method naming: Verbs

Common Verb Conventions:

Can---Determine if an action is performed

Has---Determine if there is a value

Is---Determine if it is a value

Get---get a value

Set---setting a value

Load---loading some data

3. Special function/variable non-rigid contract naming:

1): constant: All uppercase words are divided by "_";

2): constructor: Big hump naming;

3): Private member (Attribute/method): With "_" as the prefix;

B. Coding non-rigid principle:

1. Event object is not passed, if necessary, only the necessary data can be transmitted;

2. Application layer logic can be carried out without reliance on any behavior;

3. Event layer only handles events;

4. The code has a single responsibility;

5. Respect for object ownership is to modify only the objects you create;

6. Avoid global variables;

C. Code performance

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

2.with,eval,settimeout the first parameter character form, Function avoids the use;

3. Cycle optimization

Minus value Iteration

Simplified termination conditions

Simplified loop body

As far as possible after the test cycle is do-while

4. Minimize the number of statements;

5. The numerical operation bit operation is faster;

6. Optimize DOM operation (this piece has a lot of things to study 1:30 will not share);

D: Code comment common identifiers:

[email protected] The author of the program explains

[Email protected] Version description of source file

[Email protected] Method parameter description

[email protected] Not recommended methods of use

Description information for the return value of the [email protected] Method

[email protected] See, specifying reference content

Exception type thrown by [email protected]

[Email protected] throws an exception

[Email protected] Sample code

The notes are so much. slowly cultivated;

Code specification for novice Web developers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.