Alibaba Development Manual

One , Code specification :

* Methods and properties in interfaces , Without embellishments such as :publc, Correctly :void f()
* long or Long, Unified use Long Type handling
* Constants are classified by function
* if/for/while/switch/do Spaces must be added between reserved words and brackets
* There is only one space between the double slash of the comment and the comment content
* When the number of characters exceeds 120 Hours , Newline rule : The second line indents the first line 4 Spaces , The third line is not indented at the beginning
* Method parameters are defined and passed in , Multiple parameters must be thick with spaces
* Comparison of values between all wrapper class objects of the same type , Use all equals compare , as :Integer For comparison equals
* All entity classes must be wrapped with data types
* RPC method ( Remote call method ) The return value and parameters of must use the wrapper data type
* Use basic data types for all local variables
* definition DO/DTO/VO etc. POJO Isochronous , Do not set any property defaults
* POJO Class must write toString method
* Method definition order within a class : Public method or protection method > Private method > getter/setter method
* In circulatory body , String splicing , use StringBuilder Of append Method extension
* Set to array , use toArray(T[] array) Method with parameters , It is better to have the same input parameter group size and the number of collection elements
* foreach The remove/add operation , use Iterator mode ,
* HashMap use HashMap(int initialCapacity) initialization
* use set Unique feature de duplication , Avoid using contains Method ergodic de duplication
* SimpleDateFormat Thread unsafe , use DateUtils Better tools
* Less use if-else, have access to if() {return ;}
* High concurrency , Avoid using equals as a condition of interruption or exit , Possible breakdown , Use interval judgment greater than or less than
* Statements in the body of a loop should consider performance , Defining objects , variable , Get database connection ,try-catch operation , Transfer to CPB as much as possible
* class , Class properties , Class method annotation using /* content /, Not used // xxx mode
* All abstract methods , Include methods in interfaces , Must use javadoc notes , Notes include : Return value , parameter , abnormal , Also point out what the method does , What functions are implemented
* All enumeration type fields must have comments
* At the same time of code modification , Comments also need to be modified , include : parameter , Return value , abnormal , Core logic
* Note the code carefully , The code logic to be replied later can be commented , Delete the ones that will never be used , The warehouse has preservation history code
* Note requirements :1) Reaction design thought code logic ;2) Be able to describe the meaning of business ;
* Good name is self explanatory
* To be used TODO, Error cannot work (FIXME)
Two , Exception log :

* try…catch… Exceptions should not be used for process control , Conditional control , Process conditions if Etc ,try…catch… Exception handling only
* Small code try-catch, Not conducive to positioning
* Catch exception to handle , Leave the exception to the caller if you don't handle it
* Method return value can be null, Do not force return of empty collection empty object , Colleagues add comments
*
Prevent null pointer exception , Packaging class and basic data type , Database query results may be null, Remote call to be judged , from session Null pointer judgment is needed to obtain data in , A series of calls are also prone to null pointer exceptions
* Application internal recommendation exception thrown , And across applications rpc Consider using Result mode , encapsulation isSuccess() method , Error code , error message
* Avoid duplicate code , Reuse to extract
* At least save the log file 15 day , There are some anomalies “ week ” Frequency
* Using the logging framework slf4j Of api, Log framework using facade mode , It is conducive to the unification of maintenance and log processing of various classes
* Log output , Use conditional output or placeholder , as :if() {logger.debug(“ok”)}
*
Exception information includes two types of information : Crime scene information and exception stack information . If not handled , By keyword throws Throw it up . as :logger.error( Various parameters or objects toString
+ “_” + e.getMessage(), e)
* Think when you log :1) Does anyone read the diary ?2) What can I do when I see this log ?3) Can it bring benefits to troubleshooting
Three , unit testing

* Unit test code in src/test/java lower , Ensure the test granularity is small enough , Helps pinpoint problems , Unit test is required for each application layer
* unit testing :BCDE, Boundary value test ( Circular boundary , Special value , Special time point , Data order ), Correct input , Combination with design documents , Force error message input
Four , Security protocol

* No direct display of sensitive data , To desensitize
* Note deserialization injection ( Stream bytes to objects ), Convert to unexpected object execute code influence program
Five ,MySQL database
1) Table building

* Fields expressing yes or no , Must use is_xxx How to name , For data type tinyint,(1 Indicates yes ,0 No )
* Table and field names must use lowercase letters or numbers ,windows Case insensitive below , but linux Case sensitive down
* Table name does not apply to plural nouns
*
Decimal type is decimal, No use float and double, These two problems have precision loss , If the range of data stored exceeds decimal, It is recommended to separate data into integers and decimals for storage
* Table required three fields :id( Primary key , type bigint), gmt_create(datetime type ) Proactive creation ,
gmt_modified(datetime type ) Passive update
* It is better to add the name of the table : Business name _ Function of table (trade_config)
* Library name and application name should be consistent as much as possible
* If the field is used frequently , Short field length , The name is basically the same , Category names can be stored redundantly in the associated table ( Data of the same field is stored in another table ), Avoid associated queries
* The number of single table rows exceeds 500 More than 10000 rows or single table capacity 2GB It is recommended to divide the warehouse into different tables
2) Indexes

Technology
©2019-2020 Toolsou All rights reserved,
org.postgresql.util.PSQLException Processing records 【JAVA】【 Huawei campus recruitment written examination - Software 】2020-09-09vue use THREE.js Create a cube that you can control ( Essence )2020 year 7 month 15 day Wechat applet template Use of Thoughts on multi tenant system Python Multithreading programming ( One ):threading modular Thread The usage of class java Several common runtime exceptions and simple examples Golang Array bisection , Array split , Array grouping use VS2019 “Windows Desktop applications ” Module creation Win32 window Python realization switch method