introduction
This article is for personal reading 《 Alibaba java Development Manual 1.5》 and 《 Programming craftsmanship 》 My experience , Organize to form a good personal code writing style

<> one , Naming style

* No naming in the code can start or end with an underscore or dollar sign
Error example : _nameError$

* It is strictly prohibited to use the naming method of mixing Pinyin and English , In addition to international names , All in English
alibaba / taobao / youku / hangzhou And other international names , Visual English

* The class name uses the hump naming method of initial capitalization
UpperCamelCase
The following exceptions apply: :DO / BO / DTO / VO / AO / PO / UID etc.

* Method name , Parameter name , Member variable , Local variables use the hump nomenclature of initial lowercase
localValue / getHttpMessage() / inputUserId

* Constant naming all uppercase , Underline words , Strive for complete and clear semantic expression
MAX_STOCK_COUNT / CACHE_EXPIRED_TIME

* Package names are in lowercase , An English word with only one natural meaning between dot separators . Package name unification singular noun , But if the class name has plural meaning , Class names can be plural
The application class package name is com.alibaba.ai.util, The class name is MessageUtils( This rule reference spring Frame structure of )

* Avoid using identical names between member variables of child parent classes or local variables of different code blocks , Reduce readability
The application class package name is com.alibaba.ai.util, The class name is MessageUtils( This rule reference spring Frame structure of )

* Custom programming elements when named , Use word combinations as complete as possible to express their meaning
* stay long perhaps Long When assigning , Use uppercase after numeric value L, Cannot be lowercase l, Lowercase is easy to follow word 1 confusion , Cause misunderstanding .
Long a = 2l; It's written in numbers 21, still Long Type 2

<> two , Code format

* use 4 Space indent , No use tab character
If used tab indent , Must be set 1 individual tab by 4 Spaces .
IDEA set up tab by 4 Space , Please do not check Use tab character, And in eclipse in , Must be checked insert spaces
for tabs

* There is only one space between the double slash of the comment and the content of the comment
int i = 0;// This is an example note , Notice a space after the double slash

* When performing type cast , No spaces are required between the closing parenthesis and the cast value .
long first = 1000000000000L;
int second = (int)first + 2;

* The number of single line characters is limited to no more than 120 individual , Line wrap required , The following principles shall be followed during line feed:
- The second line is indented relative to the first line 4 Spaces
- Operator with the following line breaks
- The dot symbol of the method call is wrapped with the following text
- Wrap lines after commas and parentheses
* Method parameters are defined and passed in , Multiple parameter commas must be followed by spaces
method(args1, args2, args3);

* It is not necessary to add several spaces to align the assigned equal sign of the variable with the equal sign at the corresponding position of the previous line .
int one = 1;
long two = 2L;
float three = 3F;
StringBuilder sb = new StringBuilder();

* Different logic , Different semantics , Insert a blank line between the codes of different businesses to separate them to improve readability
Any situation , There is no need to insert multiple blank lines to separate .

* In high concurrency scenarios , Avoid using ” be equal to ” Judgment as a condition for interruption or exit .
If concurrency control is not handled properly , It is easy to produce equivalent judgment “ breakdown ” Situation , Use the interval judgment condition greater than or less than to replace .

* Do not execute other complex statements in conditional judgment , Assign the result of complex logic judgment to a meaningful boolean variable name , To improve readability
final boolean existed = (file.open(fileName, “w”) != null) && (…) || (…);
if (existed) {

}

* The statements in the loop body should consider performance , The following operations shall be moved to extracorporeal circulation for treatment as far as possible , Such as defining objects , change amount , Get database connection , Make unnecessary try-catch operation
* Avoid using negative logical operators
<> three , Annotation protocol

* All classes must be added with creator and creation date .
* Explain the problem clearly with Chinese notes . Proper nouns and keywords can be kept in the original English .
TCP connection timed out

* While modifying the code , The notes should also be modified accordingly
Code and comment updates are out of sync , Just like the road network is not synchronized with the navigation software update , If the navigation software lags seriously , Lost it Significance of navigation

<> four , Database protocol

* Use ciphertext to store user sensitive data , Clear text access is strictly prohibited
* Direct display of user sensitive data is prohibited
Chinese mainland mobile phone number is displayed as :137****0969, Hide middle 4 position , Prevent privacy disclosure

* Any parameter passed in by the user's request must be validated
* A field that represents a yes or no concept , Must use is_xxx Named in the same way
The data type is unsigned tinyint(1 Say yes ,0 Indicates No ).

* Table name , Field names must use lowercase letters or numbers , The beginning of a number is prohibited , Prohibit two underscores with only numbers in the middle .
The modification of database field name is very expensive , Because pre publishing is not possible , Therefore, the field name needs careful consideration
MySQL stay Windows Lower case insensitive , But in Linux The default is case sensitive . therefore , Database name , surface name , Field name , No uppercase letters are allowed
eg: aliyun_admin,rdc_config,level3_name

* The primary key index name is pk_ Field name ; The unique index name is uk_ Field name ; The normal index name is idx_ Field name
pk_ Namely primary key;uk_ Namely unique key;idx_ Namely index Abbreviation of .

* Disable reserved words
* Stored strings are almost equal in length , use char Fixed length string type .
* varchar Is a variable length string , No pre allocated storage , Do not exceed 5000, If the storage is long Degree greater than this value , Define field type as
text, Separate a table , Corresponding with primary key , Avoid affecting other fields Lead efficiency
* Table 3 required fields :id, create_time, update_time
: among id Must be primary key , Type is bigint unsigned, Self increment in single table , Step size 1.create_time, update_time All types are
datetime type .

* The naming of the table is best to follow “ Business name _ Function of table ”
alipay_task / force_project / trade_config

Technology