The author believes that to achieve more elegant coding, it is necessary to comply with the following constraints, ranking order:

Good naming clear structure not very bad algorithm

Here are a few:

A good name is not straight, then speak not, speak not, then things are not — Confucius

Mencius said, ‘Confucius is right.’

Naming is very important, just a logic teaching materials (if readers are interested in, here recommend introduction to logic), there will be named after the long to discuss problems in ancient China had appeared during the mahoganypanelled splendour of schools of thought contend a school called “masters”, named after the discuss problems, such as the famous “white horse is not horse”, “from the solid white”, etc., It’s fun to read, more fun than King of Glory. The author thinks that up to now there have been three periods of great ideological liberation in Our country: first, the spring and Autumn period and the Warring States period of a hundred schools of thought contended, but unfortunately, it was ended by the unification of the qin Emperor’s county system; Second, during the Period of the Republic of China, when western thought began to surge, Chinese people seemed to wake up like thunder. Third, at present, the technological revolution has sharply reduced the power of central thought control, making people at the bottom have the freedom to choose who controls their thoughts (please refer to the current Internet-based fan culture and circle culture). So we must write code well, so as to live up to the young head.

Returning to the theme, naming should be based on the principle of not being too long but not too clear, and try to explain the meaning of a class, method and variable clearly. In fact, the author prefers OC method (message) naming rules, such as:

(void) buy:(NSString*)something from:(NSString*)store at:(NSDate*)time;
Copy the code

Long, but clear. The following details the naming:

Interface naming

Interfaces are usually named with the prefix I plus a noun or an adjective, in fact. The Net Framewrok class library does this, for example:

System. The Collections. The Generic. The ICollection (noun)

System. Collections, Generic IEnumerable (adjective)

An interface is often used to assemble a behavior or group of behaviors, and a class that implements an interface means it has the ability to perform a behavior or group of behaviors, all common adjectives. When you really can’t find an adjective, a noun will do.

An abstract class

Abstract classes usually do not need prefixes or suffixes, but some prefer to add Base suffixes as appropriate. I think the following naming is good:

Shape (abstract) Ellipse (concrete) Rectangle (concrete)

The use of nouns for concrete classes does not rule out the use of verbs in cases where an action is encapsulated as a class.

methods

Use verbs or verbal phrases.

The above. I think other fields ah, attribute ah, event ah appear naming problem is less, no discussion. For example, some people like to start fields with underscores and some people like to start fields with m_. It doesn’t matter. On the contrary, it is a problem to prescribe a specification that is extremely large and detailed. On the one hand, it consumes the writer’s time, on the other hand, the reader may not remember it, and on the other hand, the reader may resist it because it is different from his own habits.

In addition, it is necessary to emphasize that less use of pinyin with English, less use of abbreviation with full name, as far as possible without pinyin abbreviation, even dialect pinyin abbreviation, and English plus pinyin, and even English plus pinyin abbreviation…… . However, it cannot be ruled out that some words such as “family planning”, which are not easy to translate, can be used in pinyin and should be annotated clearly or the vocabulary should be maintained. In addition, abbreviations are not banned. Some abbreviations, such as “Id”, are used without misunderstanding and can also help clarity of code.

Sometimes due to the problem of English level, after all, our mother tongue is not English, it is inevitable that we do not know what words to use. At this point, try Codelf, thanks to a tool reportedly developed by Netease engineer Unbug. This is pronounced koʊdɪf, but the penultimate letter is not an I, it’s an L.

Clear structure

The basic requirements

If, while and other keywords wrapped expressions, even if only one sentence, try to use curly braces

Avoid the Erectus-era goto statement

Try to avoid too long method, the large method divided into a number of small methods, the function of the method as far as possible single

Try to avoid duplicate code and move it to a common tool

Try to avoid too large a class, split into a number of classes, each doing its job

Appropriate comments. Too many comments indicate that the expressiveness of the code itself may need to be improved. Some really difficult logic, you can write detailed notes, if you do not write notes, when leaving please pay attention not to disclose to wipe the ass person’s own address

High requirements

Be familiar with the following common object-oriented design principles:

Open-closed

Single responsibility

Replacement on the Richter scale

Dependency inversion

Interface segregation

Be familiar with common design patterns:

The factory method

The abstract factory

Builder model

The singleton pattern

Adapter mode

The appearance model

Observer model

Command mode

The proxy pattern

The strategy pattern

The three characteristics of object-oriented language everyone knows, but really good use is not easy, the three characteristics are only the basis of object-oriented design, on this basis to establish object-oriented high-rise buildings. The author has worked for many years, often lamenting the wasted time, so far has not mastered the object – oriented design ten five or six.

There are two benefits to using mature design patterns:

These solutions have been tried and tested, and the name of the fail-safe design pattern is a concept that circulates among programmers and reduces communication costs based on a common understanding of the concept

Of course, there are disadvantages, although the code scalability is good, but the code complexity is also high, which requires us to be familiar with the common design pattern, so as to get its benefits, avoid its disadvantages.

It is important to be careful not to use design patterns to encapsulate changes that have occurred or are likely to occur only when requirements have changed or are anticipated to change. This is sometimes used when refactoring code, such as the appearance mode and the allocator mode.

A large project cannot be completed by one person, and chaos is easy to occur when there are too many people. At this time, the leader of the team is required to shoulder the obligatory responsibilities bravely, including but not limited to:

Maintain the code framework and hierarchy regularly. Write long hard to avoid chaos, leaders want regular elimination, timely elimination of odor

Lead the boys in code review. The point of censorship is not to supervise, but to learn and maintain a good attitude. Learning means learning from others through code review and helping them improve. Keep a good attitude is to point to if know someone will see your own code, you can consciously try to write neatly, even lazy not seriously read review code, is the so-called, if everybody believe above three feet have gods, so also no one to do bad things, this is positive, in religion, digress.

Review the database design

Update or delegate documentation to a team member

One more thing to say about documentation: Only document when it’s absolutely necessary. If you write a lot of unnecessary documentation, it’s hard to keep the documentation up to date when the code changes. A novice faced with a stack of documents disconnected from the code can only be misleading. The expressive power of the code itself and verbal communication are the main, and the document communication is the secondary. One hand is hard, the other is soft.

Not a very bad algorithm

Most of the projects you do are performance-insensitive and can be done with a little attention. For example, paging is used where it should be used, querying the database based on criteria is found all at once, and optimizing the database is optimized.

In addition, stress testing is also necessary, and some performance problems only appear when there is a large amount of data. Many performance problems don’t surface until they are in production.

code

Compared with team building, the above can only be considered trivial skills, only played a role of icing on the cake. How to maintain the vitality and enthusiasm of the team is the most important, which is usually the most easily ignored by leaders and the most difficult to do well. These are beyond the scope of my ability and the focus of this paper, and I will write them again when I have the opportunity. Happy work!

※ Some articles from the network, if any infringement, please contact to delete; More articles and materials | click behind the text to the left left left 100 gpython self-study data package Ali cloud K8s practical manual guide] [ali cloud CDN row pit CDN ECS Hadoop large data of actual combat operations guide the conversation practice manual manual Knative cloud native application development guide OSS Operation and maintenance actual combat manual cloud native architecture white paper Zabbix enterprise distributed monitoring system source document 10G large factory interview questions