On the self-cultivation and self-cultivation of a programmer

Source: Internet
Author: User

On the self-cultivation and self-cultivation of a programmer

 

In the king of comedy, Yin tianqiu, played by Stephen Chow, has always dreamed of becoming an actor. Whether he is playing a long running role, opening an actor training class in a neighborhood, or playing a leading role, his attitude towards actors has always been earnest, loving, and invested. The book "actor's self-cultivation" he carried with him, although I don't know what he wrote in it, I guess his attitude towards actor and his behavior, is displayed in the book.

So I asked myself, as a programmer, what is "programmer's self-cultivation?

Although we do not have to take our own business as seriously as Yin tianqiu does, some basic accomplishments should always be available as a code farmer in the new era. However, there are still a lot of accomplishments, so you don't have to say anything about technical self-tips. However, I don't want to start with the technical aspects that everyone takes for granted. Instead, I want to talk about the readability of the Code, which is easily overlooked by everyone.

1. Follow the code specifications of the team.

An efficient and mature team must have its own code specification. This specification is a valuable asset of the team. It is the accumulated experience and lessons of the entire team. What is standardization? It is a rule and standard that people have summed up from countless experiences. The code specification guides team members to write the most efficient and readable code in the shortest time. Imagine how much impact it will have on the readable program if the Members do not follow the rules and you name them in the camper. I think no one is willing to read a piece of code. All the Naming forms of variables can be seen. The private and public methods are sorted at will, and even the constant classes are scattered in every corner of the Code.

Code, one function is to let the machine read, another important role is to let people read !!!

 

2. comply with industry-specific specifications

If the code specification of the team is not involved, write the code according to the industry specification. One advantage of standardization is that it can significantly reduce learning and communication costs. In java, when we see variable names in all upper case, we know that this is a constant, instead of looking at comments, or code logic. Why is it so fast, because everyone in the industry is used to naming constants in uppercase. However, if you use other naming methods to name constants, such as team_nums, not only do you not quickly know that this is a constant, but it may be misunderstood that it is a variable, it increases the learning and communication costs for team members and may even mislead them. I met a renxiong who clearly used the factory model but named it according to the template model. He asked him that he knew this was the factory model, but he thought, it should also be called the template mode... My God, are you so capricious that you can be friends in the future?

For example, we need to produce multiple payment products based on the payment type, so we wrote a factory class named FactoryPay. When other people see a class named FactoryPay, they will guess that it should be a factory class that is responsible for producing various payment products and then read the code according to this guess, you can quickly understand the role of the entire class. However, if I name it PowerPay, and other people do not know what it is, after reading it for a long time, they will understand that this is the role of a factory. This significantly increases others' learning costs and code maintenance costs.

Whether you are a newbie or an old bird, be sure to understand the industrial norms and do not violate the rules to be unconventional. There is no need to adopt such a low-end installation force. We need to install a high-end framework to improve the performance.

 

3. Variables and method names must be able to express the functions of variables.

After a long time in the programmer's circle, I found that programmers like this set. "What is this interface used? Is there a document?" and "read the code by yourself ". In many cases, it is a black face.

Although programmers are top-notch in reading other people's code technology, no matter whether you have comments or not, no matter how nested or named, they can be patient, analyze the code. However, for a programmer who regards time as precious as life and creates millions of values every minute, you can do well. Save us some time and use the variables, to be clear, you may save a few minutes and earn tens of thousands more.

Every time I see a great God in a department, I have the impulse to vomit blood with a magical variable named "flag". He also keeps hiding the flag, no need, I used it only when I passed it to the nth method. I suddenly handed it over. My God, why is this flag used? Later I realized that isPay meant it, used to identify whether the payment is successful. At that time, the screen was filled with blood, and my heart went crazy. Dude, will you die if you name isPay? Is my brain cell so worthless. Later, we can see that the magic number is represented by int NUM_7 = 7 instead of MAX_MEMBERS, and the variable name is named by x y z, or the unique naming method that I forgot later is strange. What's more, a variable named passed means "fail". At that time, it was petrochemical, and the author had to be careful.

A good variable name can help readers understand the role of variables and help readers understand the entire code segment.

 

4. Do not show English. Children in the country cannot afford to hurt.

The team in which LZ is located has always been a tough injury to the team, but it is always possible to see that a senior man, with a lot of comments in English, some variable names also contain complex English words. Dare to ask, how can we play with you in the future. (The man-in-law is actually LZ. When I was young, alas, sin and sin)

The code is used for communication, and the author's intention is passed on, so it cannot be understood. How can we communicate. It is recommended that children's shoes with good English skills be displayed in English books. In the Code, if the team's English skills are weak, do not use English. Variable names should also be named according to the team's English proficiency.

 

5. add necessary comments

As LZ said above, it often encounters a god reply like "you should take a closer look at the code to know what to use. Although reading the code is a strong point for every programmer, the necessary comments, such as the complicated logic, add the necessary comments, it is of great help to improve the efficiency of team members to read the code they are familiar. Imagine how horrible it would be for readers to read a class with hundreds of lines without comments.

 

6. Keep comments concise to avoid unnecessary comments.

That is to say, I have read the code that does not have a line of comments, and I have read the program that has more comments than the code. One is to make life worse than death, and the other is to make people feel bad. (Alas, it is really difficult not only to sigh and mix in the programmer world ).

LZ has often seen it. A large comment is long-winded for a long time, or it just shows that it is a loop !!! For code like I ++, is it necessary to add a comment such as "Add 1 for each count"? This completely positions readers as non-programmers, or, the reader's programming level is severely despised.

Annotation helps readers better understand the logic of the program. It is only an aid. If you do not pay attention to the function of passing code through naming, but rely on annotations, this is the result of putting the system upside down. In addition, the lengthy comment indicates whether it helps people understand, or hinders understanding, whether it is reading a program or reading a novel.

 

7. Have your own coding specifications

Standards are designed to allow the team to understand and familiarize themselves with code more quickly. Similarly, with their own set of standards, they can help others understand the functions we write more quickly and reduce learning and communication costs.

 

8. The Code clearly and concisely expresses the author's meaning

Every time we write a piece of code, we must ask ourselves whether the Code clearly expresses what I mean, whether some comments need to be added, and whether the name is obtained properly, is it hard for others to read .. Every time I see a mess of confusing code from others, I always remind myself that I must write the code well. I did the same and checked it over and over again, check whether the variable name and method name indicate its purpose, whether it is unnecessary to improve the code, and whether others can understand it in a short time. All of this is to write a piece of code that is better.

 

9. Stick to and defend the above principles

We often hear that some companies define performance based on the number of lines of code. However, as a programmer with integrity and basic self-cultivation, we must never resort to temptation or coercion, it is even your own inertia and personality, instead of writing concise, clear, and readable code.

  

The above points are not strictly comments or suggestions. They just remind programmers that they should never forget to read the Code not only on machines, but also on high-end technologies, you also need to read. Even if you write complex code, but it is completely unreadable, what is the purpose. This is like, you are awesome, but it is not useless for others to understand what you say. If you really write readable code, but you should not be smug. I think writing a beautiful, robust, and readable code is the most basic self-cultivation for a programmer. If there is no such pursuit, what is the difference with salted fish. Although it is often seen by outsiders as a poor communication, our code is beautiful, and each piece of code clearly and concisely expresses our thoughts. This is not very good. As a medium for programmers to communicate with each other, code must maintain its efficient communication attribute, rather than sacrifice its readability for its own personality. We recommend that you read books such as "clean code" and "how to be a better programmer" in your spare time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.