Node. js code specification, node. js Code

Source: Internet
Author: User

Node. js code specification, node. js Code

When calling a function, there is no space between the function name and the left parenthesis.

There is no space between the function name and the parameter sequence. There is a space between all other syntax elements and the left parenthesis.

Use the small hump naming method as the naming rules for all variables and attributes.
Two spaces are used for indentation and single quotation marks are used.
Join an array. No quotation marks are required unless the key name contains spaces or invalid characters.
Do not merge statements for different purposes into one row.
Do not omit the semicolon at the end of a sentence, even if one row has only one statement.
Do not use the auto-increment (++) and auto-increment (--) operators, instead of the + = and-= operators.
Do not use the "Equal" (=) operator. Only the "strictly equal" (=) operator is used.
All variable declarations are placed in the function header.
All functions are defined before use.
Name constructors and callback functions as much as possible, so that you can see a clearer call stack during debugging.
Try to define all member functions in the constructor through the prototype, define the attributes in the constructor, and then use the new keyword to create an object for the constructor.
Avoid complex inheritance. If you want to inherit, use the inherits function in the util module whenever possible. For example, if A inherits B, it can be util. inherits (A, B ).


References:
Appendix B (BYVoid) of Node. js Development Guide)

Javascript programming style (Ruan Yifeng)



Document Information

  • Copyright statement: Free Reprint-non commercial-Non derivative-keep the signature | Creative Commons BY-NC-ND 3.0
  • Http://blog.csdn.net/cdztop/article/details/37749051
  • Last modification time: July 14, 2014


JAVA coding Specification

(1) The first letter of the class name should be capitalized. The first letter of the field, method, and object (handle) should be in lowercase. For all identifiers, all the words in them should be placed together, and the first letter of the intermediate word should be capitalized. For example:
ThisIsAClassName
ThisIsMethodOrFieldName
If a constant initialization character appears in the definition, all the letters in the static final basic type identifier are capitalized. In this way, they are constants of the compilation period.
A Java Package is a special case where all these are lowercase letters, even the middle words. All domain name extension names, such as com, org, net, or edu, should be in lower case (this is also one of the differences between Java 1.1 and Java 1.2 ).
(2) When creating a class for the general purpose, take the "classic form" and include the definition of the following elements:
Equals ()
HashCode ()
ToString ()
Clone () (implement Cloneable)
Implement Serializable
(3) For each class you create, consider placing a main (), which contains the code used to test that class. To use a class in a project, we do not need to delete the test code. If any form of modification is made, you can easily return to the test. These codes can also be used as an example of how to use classes.
(4) the method should be designed into a brief functional unit to describe and implement a discontinuous class interface section. Ideally, the method should be concise. If the length is large, you can divide it into several shorter methods in some way. This also facilitates the reuse of code in the class (sometimes, the methods must be very large, but they should still only do the same thing ).
(5) When designing a class, consider it for the client Programmer (the usage of the class should be very clear ). Then, let's look at the form of changes that may be made to the person who manages the code (think about how to make them easier ).
(6) Make the class as short and concise as possible, and only solve a specific problem. The following are some suggestions for class design:
A complex switch statement: consider adopting the "multi-form" Mechanism
A large number of methods involve very different types of operations: Consider using several classes to implement them separately.
Many member variables have major differences in features: Consider using several classes
(7) Make everything "private" -- private as much as possible. A certain part of the database can be "public" (a method, class, or a field, etc.), and it will never be taken out. If you forcibly extract the code, it may damage the existing Code of others, so that they have to rewrite and design it. If you only publish what you must publish, You can boldly change anything else. In a multi-threaded environment, privacy is a particularly important factor-only private fields can be protected in non-synchronous use.
(8) Please refer to "huge object syndrome ". For new users who are used to sequential programming and are initially involved in the OOP field, they often prefer to write an ordered execution program first and then embed it into one or two huge objects. According to programming principles, objects should be expressed as the concept of applications rather than the application itself.
(9) If you have to do some unsightly programming, at least put the code inside a class.
(10) at any time, as long as you find that classes are closely integrated with each other, you need to consider whether internal classes are used, to improve coding and maintenance (see "improve code with internal classes" in section 14.1.2 of Chapter 14th ").
(11) add comments as detailed as possible and generate your own program documents using javadoc annotation Document Syntax.
(12) Avoid using "magic numbers", which are difficult to work with code. If you need to modify it later, it will undoubtedly be... the remaining full text>

What are the requirements for HTML encoding?

1. HTML coding Specification
HTML is not a programming language, but a markup language. It does not have loops or flow control statements in any real programming language. However, the format and style of HTML code are very important. Because HTML code must be maintained and modified frequently, the HTML code must have a clear logical structure and layout, and make it easy to understand and easy to maintain.

1.1 mark writing
HTML is case-insensitive, but in general, tags are written in uppercase, such as <P>, <HTML>, and <TABLE>. attributes in tags are generally in lower case, such as <A href00000000a.html "> and <font size =" 5 ">.

1.2 line feed Specification

Generally, an HTML code is very long and complex, so do not write the code very closely. This is very poor readability. HTML is not sensitive to carriage return and space. Therefore, you can use carriage return and space, make the code format and structure clearer so that it is easy to maintain. Many tags generally occupy one row. Except for the close tag of the same tag, it is best not to Mark Two tags on the same row. For example:

<TABLE> <TR> <TD> text </TD> </TR> </TABLE>

Should be written:

<TABLE>

<TR>

<TD> text </TD>

</TR>

</TABLE>

1. Generally, the line feed should be marked as follows:

<HTML> and </HTML>

Ø <BODY> </BODY>

Ø <HEAD> </HEAD>

<FORM> </FORM>

Ø when the content of a paragraph is relatively long, <P> </P>

Various list tags

Ø table Markup

<BLOCKQUOTE> and </BLOCKQUOTE>

<PRE> and </PRE>

<CODE> and </CODE>

2. In general, you need to put the start and close tags on a row with the following tags:

<B> and </B>

<U> and </U>

<I> and </I>

Various title tags, such as <H1>... </H1>

<A> and </A>

1.3 mark closing rules:
1. The text of the HTML document should be in the middle of the <BODY> </BODY> mark, and the <BODY> mark should be included between the <HTML> and </HTML> mark, as shown in

<HTML>

<BODY>

............

& L ...... remaining full text>
 

Related Article

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.