Coding Standards and feel the beauty of mathematics

Naming conventions

Code name can not start with an underscore or a dollar sign, can not end with an underscore, or dollar sign

Code named Do not use mixed Pinyin and English, but does not allow direct use Chinese way

Use UpperCamelCase style class name, must comply with the hump form (in some cases such as relevant domain model named except); method name, parameter name, member variables, local variables are consistent use lowerCamelCase style, form must follow the hump

Constant naming all uppercase, separated by an underscore between words

Unified package name in lower case, and only a semantic nature of the English word delimiters between points

Abstract class name or the beginning of the use Abstract Base; exception class named using ends Exception; test class named after the name of its class to be tested beginning to end Test

For Service and DAO classes, based on the concept of SOA, must be exposed service interfaces, and the difference between the suffix internal interface implementation class with Impl

If the interface name to describe the ability to take corresponding adjective as interface name

Enum class name is recommended to bring Enum suffix, enumeration member name needs to be in all uppercase, separated by an underscore between words

If you use the design mode, we recommend that reflects specific patterns in the class name

Unified package name singular form; if the plural class names, class names, you can use the plural form

Any magic value (that is, without the constants defined) allowed directly in your code

Do not use a constant maintenance of all class constants should be classified according to the constant function, separate maintenance

Constant multiplexing hierarchy has five: the constant cross-application sharing, application sharing within a constant, constant share within the sub-project, the bag constant sharing, shared constants within the class

If the variable value is only Enum type used in a range of variation. If extended with further attributes other than the name, the class must Enum

Try not to define variables in the interface, if you have to define a variable, is certainly related to the interface method, and is the basis for constant throughout the application

When long or Long initial assignment, you must use a capital L, not lowercase l, lowercase easily confused with the digit 1, misleading

The interface class attributes and methods do not add any modification symbols (public and do not add), maintaining simplicity code, combined with effective and Javadoc comments

All the override method, you must add @Override comment

The variable parameters must be placed at the end of the argument list.

The external interface exposed signature, in principle, allows you to modify the method signature to avoid an impact on the caller interface. Obsolete interfaces must be added @Deprecated comment, and clearly explain what the new interface or using the new service

You can not use outdated class or method

When adding serialization class property, please do not modify the serialVersionUID field, to avoid de-serialization failure

Loop body, the coupling of the character string using the StringBuilder append

final efficiency can be improved in response to the program

Object method to clone caution copy target

Comparison between the wrapper class for all objects of the same type of values, all using the equals method comparison

All POJO class attributes must be packed data type

RPC parameter and return value data types must be packaged

All local variables [Recommended] using basic data types

Service / DAO layer method naming conventions
- Get a single object method prefixed with GET
- Get more object's methods prefixed with the List
- Get statistic methods prefixed with COUNT
- insertion method save (recommended) or insert do prefix
- to delete method remove (recommended) or delete prefixed
- modified method prefixed with update

Defining DO / DTO / VO POJO class, etc., do not set any attribute default values

Constructor which prohibits adding any business logic, if there is initialization logic, please put the init method

When a class has multiple constructors, the same name or a plurality of methods, which should be placed together in the order, to facilitate reading

The method of the class is defined in the order: public or protected method Method> Private method> getter / setter Method

setter methods, consistent parameter names and class member variable name, this. Member Name = parameter name. In getter / setter methods, so as not to increase the business logic

Class members with strict access control method

Indented using four spaces, prohibit the use of tab characters

The number of characters single line limit is not more than 120

IDE's text file encoding to UTF-8; line breaks in the IDE using the Unix file format, do not use windows format

Group group definition statements executed statements, the variables in vivo method, is inserted between the different semantics of different business logic or a blank line

Gets the singleton object needs to ensure thread safety, which should guarantee thread-safe method

Please specify a meaningful name when creating a thread pool thread or threads, easy backtracking on error

Thread resources must be provided by the thread pool is not allowed in the application itself explicitly create threads

Executors thread pool are not allowed to create, but to create by ThreadPoolExecutor

When the multi-threaded parallel processing timing task, when Timer running multiple TimeTask, as long as one does not catch exceptions thrown, other tasks will automatically terminate, use ScheduledExecutorService is not the problem

CountDownLatch using asynchronous transfer synchronization, each thread must call countDown method before exiting, note the code execution thread catch exception ensure countDown method can be performed,
to avoid the main thread to countDown method can not be performed until the time-out before returning the result back

volatile memory to solve the multi-threaded invisible problem. For a write once read many, synchronization problems can be solved variables, but if you write, the same can not solve thread safety issues

HashMap dead links may occur due to high concurrency when capacity is insufficient carried resize

ThreadLocal update problem can not be solved shared objects, ThreadLocal objects recommends using static modification. This variable is for all operations within a common thread, it is set to a static variable,
all such instances share the static variables

All comments must be enumerated type field, indicating the purpose of each data item

Its "half-baked" in English to comment, as with the Chinese annotation clear the problem. Proper names and keywords can keep the original English text

Comment out the code as much as possible to tie explain, rather than simply comment out

Good name, code structure is self-explanatory, comments to be simple and accurate expression in place

Is the concept of whether or not the field name must is_xxx manner, the data type is unsigned tinyint (1 is represented, 0 for No)

Table names, field names must be lowercase letters or numbers; banned from the beginning of the digital prohibiting the middle two numbers appear only underscore

Table name does not use a plural noun

Disable reserved words

The only index called uk_ field names; ordinary index name was idx_ field name

Named the best table is to add business name _ the role of table

Library name and application name as consistent as possible

Table must have three fields: id, gmt_create, gmt_modified

If stored longer than this value, defined as the field type text, an independent list, with the corresponding primary key, to avoid affecting other fields efficiency index

If you modify the field meaning or status field indicates the additional need to update the comment field

Field allows appropriate redundancy to improve performance, but must consider the case where data synchronization

Single table rows over 5 million lines or single-table capacity of more than 2GB, it is recommended sub-library sub-table

Suitable character storage length, not only save space database tables, saving index storage, more importantly, to enhance the retrieval speed

Field has a unique characteristic of the business, even if a combination of fields, unique indexes must be built

More than three tables join prohibited

When creating an index on a varchar field, you must specify the length of the index

Search page is strictly prohibited left vague or fuzzy whole

If there is order by the scene, note the use of the index ordering

Or delay associated with the use of sub-query optimization super multi-page scene

Build composite index of time, the highest distinction in the leftmost

Do not use the count (column name) or count (constant) instead of count (*)

When writing the query paging logic, if the count should be returned directly to zero in the code, to avoid the back page statement execution

Not use foreign key with a cascade, all foreign key concepts that must be addressed in the application layer

Prohibit the use of stored procedures, stored procedures, difficult to debug and extend, and no portability

in operation can be avoided, avoid, if it can not avoid the need to carefully assess the number of elements in the set back control in the 1000's

In the table query, do not always use * as a list of fields of inquiry, which fields need to be clearly stated

Recommended minimize the use else, if-else manner can be rewritten as:
IF (for condition Condition) {
...
return obj;
}
// else then write the business logic code;

If you must use if () ... else if () ... else ... mode logic expression, [do] forced more than three layers, more than use state design pattern

The method requires the scene check parameters:
1) the low frequency method call.
2) execution time overhead lot of methods, parameters check time is almost negligible, but if because of parameter error led to the middle of a rollback or error, and that more harm than good.
3) high stability and availability of the required methods.
4) open interface provided externally, whether RPC / API / HTTP interface.
5) sensitive capabilities inlet.

1.7.8 The method does not require scene check parameters:
1) the method is likely to be called the loop without checking the parameters recommended. Acknowledged and external parameters in the process described in the inspection
method 2) calls the underlying relatively high frequency, generally do not check. After all, is like pure water filtration final, parameter error will be less likely to be exposed to the underlying problem. Usually DAO layer Service layer in the same application,
deployed on the same server, the checksum parameter DAO may be omitted
method will be called private codes themselves 3) is declared as, if the method call can be determined the code has been done to check the incoming parameters, or certainly not a problem, then you can not check parameters

 

In quanta already learning SQL, database, trying to back only php java technology stack to expand, so chose Ali cloud java coding standard, in short, good use of these coding standards is certainly there will be benefits of simplicity and code reading Art is encoded.

Mathematical beauty book review thought:

Read a few beginning, I was amazing, this is not just something you do a laboratory, before slightly learned, felt the science of human wisdom, can make DNN language model to predict the probability of occurrence of a sentence, as well as by word to embed

Dimensionality reduction, as well as convolution layer and cycling network, forgotten door design, action mechanism had to admire the exquisite mathematics, stitching them together into a model, it can produce an output after the input, just as a black box, understand people naturally understand,

People do not understand that the very big, I am now in greater efforts to study the depth of learning, thinking and learning algorithm which, in fact, found inside the principle is based on the basis of the algorithm,

In terms of reading books watermelon book, I recommend Andrew Ng course of machine learning and deep learning things directly on the tall talk of the civilian population, everyone has to engage in AI,), I love Andrew Ng greatly.

Guess you like

Origin www.cnblogs.com/likeghee/p/11441848.html