Hello, I’m Yanyun Changfeng. Meaning: combined with Li Bai’s famous border fortress poem “Guan Shanyue” take [Yan Yun Changfeng] – changfeng tens of thousands of miles, blowing degrees Yumen Pass.

1. The name

1.1 Class name, object name is usually a noun or noun phrase, such as Customer, UserInfo, avoid Manager, Data, etc., do not use verbs; 1.2 Method names usually use verbs or phrasal verbs, such as postPayment and save. Theoretically, based on the method name, you can know what the method is probably doing; 1.3 All names should make sense and should not be named in pinyin, or a, B,name1,name2, etc. 1.4 All statements should be useful in theory, and those not used should be deleted; 1.5 Constants are named in uppercase, and switch statements are named in uppercase. 1.6 Method and variable names should be humped, such as userInfo, and class names should be capitalized, such as Customer; 1.7 The suffix of a common file should indicate the type of the file, such as ActiveService, DataManager, UserInfoBean, etc. 1.8 Normally variables and methods are private, which is useful in Angular2;Copy the code

2. Statement

2.1 Every variable, method, and class declaration should be meaningful, that is, consumed, or deleted; 2.2 In theory, all variables that are declared should be initialized. (In fact, every variable is declared with a default value, which is null.) It is not usual to give a default or dead value to a variable as soon as it is declared. There should be an initialization method in each class, where variables are given default values. 2.3 Variables should be scoped as small as possible, rather than all variables declared on the outsideCopy the code

3. Code

3.1 Code singleness principle, a class should only do one thing, a method should only do one function; 3.2 The least known principle, a variable, a method, a class in the system should be known by the least number of people; 3.3 Accept the minimum principle of parameters, a method should accept as few parameters as possible, usually no more than 5; 3.4 Vertical format: Two related methods are placed together in vertical order; 3.5 Minimum code principle, the code of a class and a method should be as little as possible, in principle, the code of a class should control about 200 lines, more than 500 lines, and the code of a method should be controlled within 20 lines; 3.6 Avoid redundant code, when the project appears more than one similar function of the code, we should consider refining the code, out of the common method, class 3.7 if statement conditions should be as few as possible, when the if statement conditions are many should consider the if inverse, that is, if(! false); 3.8 I recommend not to use a lot of if()elseif(); The way I recommend it is if(! false)return; 3.9 Format the code 3.10 Do not appear a large number of code comments, which will mislead the second person to understand the code, delete the unnecessary 3.11 appropriate code comments, easy for others to understand, but also prevent yourself from forgetting; 3.12 There should be Spaces between method parameters, such as login(name, pass, type).Copy the code

4. Angular code specification

4.1 Add a semicolon at the end of the code to avoid unknown errors; 4.2 HTML tags should be closed, such as <br/>; 4.3 Quotation marks should be uniform, either "" or ""; 4.4 End the file with the module name, for example, Controller, service, module, route, directive, filter, template, etc. 4.5 The file name should reflect the function, all in lowercase, separated by "-". For example, disk-creation.html, app-hardwork.module. js 4.6 Controller names end with Ctrl, uppercase, camel name, For example, DiskCreationCtrl 4.7 template, try not to use inline HTML. It is better to create an HTML with inline HTML. 4.8 Angular specifications should follow the above three specifications, such as the Single principle, A controller.js should contain a controller, which only does one function;Copy the code

My personal blog

  • YanYun changfeng

A series of projects I worked on

  1. NiceFish: Mermaid is a micro-blog system with a front-end based on Angular7.0 + PrimeNG7.1.0. (GVIP code cloud the most valuable open source project 3774 ☆)
  2. Nicefish-react: This is an implementation of the React version, consistent with the NiceFish Angular version. React Hooks version 16.8.3, developed using TypeScript, Ant Design component libraries, and Bootstrap V4.2.1. (4) being
  3. OpenWMS-Frontend: The OpenWMS project Frontend is based on Angular 7.0 + PrimeNG 7.1.0. (recommended 205 ☆)

My social page

  • Yan Yun Long wind github

That’s all for today’s sharing. I wish you all the best, happy work and happy every day.

Long wind tens of thousands of miles, blowing yumen Pass.