My own experience of code coding specifications

Source: Internet
Author: User

Many beginners and I, just beginning to write code, do not pay attention to the code specification, think as long as the code without syntax errors, can run is correct.

Such a concept in my heart for a long time, this is actually buried in the code of a ticking bomb, to their own maintenance and cooperation with others has brought great trouble.

1. First line indent: Almost in all the code language we are all in 4 spaces to indent the code one is looking very beautiful, the second is the code structure at a glance, enhance the robustness of the code.

2. Language coding: Use Utf-8 This ensures that the code you write is no longer garbled on other browsers.

3. Note: Note is very important, because in the project, we are a team in cooperation, you write the code may be only you understand, you write good comments This code is what to do, so that others can know at a glance

The role of code, saving time, but also enhance communication between each other. CSS comments are/**/HTML comments are <!----> JS comments are//

4. Name: All tags of the element and attribute names are used in lowercase, CSS class name to use a meaningful name, is what this thing is not like what the principle. For example, the last background color of the navigation menu is red if we use NAV-RED-BG, this can be written, but if there is a new need to turn it into

Blue, so the naming is not unreasonable. We should see what he is: Nav-last, he is the last element of the navigation menu I don't care if you're red or green. It doesn't matter how you change it later. and naming as much as possible to have a hierarchical relationship, so that we can see the structure of the DOM tree at a glance.

JS local variable with---start, global variables do not use the-Number link, which will be in the JS operator minus sign conflict, causing unnecessary trouble.

5. Document type: Use <! at the beginning of HTML DOCTYPE html> to make a statement to tell the browser what type of document I have below. This also enhances the compatibility of the pages.

6. Tags: each HTML tag should have a corresponding end flag, a single line of such as

7. Operator: JS two mesh operator and three mesh operator before and after a space is added.

My own experience of code coding specifications

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.