The first person to write the program, followed by the computer

Source: Internet
Author: User
Tags comments documentation

"The first is to write a program, followed by the computer", which is the basic point of software development, software life cycle throughout the product development, testing, production, release, user use, version upgrades and maintenance of the long-term process, only easy to read, easy to maintain software code to have vitality.

In the actual software development process, may be due to the busy work, many developers only focus on the implementation of the basic functions of the program, and forget the programming specifications, so write the code can only let the computer understand, people to understand very difficult. What's more, some project teams in order to catch up with the team members to achieve the main product function, the code can be run up. Low requirements to produce low-quality code, since the "top" is so required, it is necessary to write "let people read" code. if not programmed for humans, the consequences are.

Progress is to catch up, the product has been delivered, everything seems OK, but the problem is coming. In front of the product failure frequency, the rear developers continue to pounce on fire. At this time, they found that the code written by others was difficult to read, and even read the code they wrote is very difficult, really hadn't. If you can write code at the beginning of the specification, the document is equipped with a little bit, what about this.

The "Good" Code and "bad" code give people a feeling that is very diverse. When we see beautiful code, there is a desire to continue to study, and even a feeling of enjoyment. On the contrary, when we see ugly code, we grind our teeth, because it is not only bad for reading, but it also wastes a lot of time and reduces the efficiency of our work. In general , the "Good" Code and "bad" code give us the impression that there are several:

layout Neat VS typesetting not neat

When we open a code file, the first thing we see is how it's formatted, which is also the most intuitive feeling. When the code is well-organized, it is easy to find out its organization and logic, we will quickly understand what it is going to achieve, and when the typesetting is not neat, our eyes will feel very tired, and then affect our thinking.

naming conventions VS naming nonstandard

After reading the layout, we will see the naming of each function and variable. Because of the number of lines of code in a generic project, it is not possible to spend a lot of time understanding what each function and variable is all about and what it does. This requires that when we encode, the names of functions and variables are self-explanatory, so that they can tell the reader what they are doing, rather than having to spend a lot of time reading them to know. This reflects the attitude and professionalism of the developer to some extent.

For example, a function that processes messages, named Processmsg and Functiona, which is better. Obviously the former. As soon as we see its name, we know what it does.

Again, there are three variables, named ReturnValue, Maxnum, and sumoftwonum, so we can see for themselves what they are used for. The first variable is used as the return value, the second variable holds the maximum number, and the third variable is used to hold the sum of two numbers. This is too obvious, you can not ask Yuan Fang, you can figure it out. and if the same three variables are named I, J, K, you can't see exactly what they're used for, and spend a lot of time reading the code, even for a few hours, and you don't know what they're for. At this time, your boss to ask you how things are done, you tell the truth, he said you incompetent. In fact, you are "dumb to eat Coptis", blame others did not write the code well.

properly annotated VS comments must not be

Read the code, and we'll also notice whether it has comments or comments or less. This is also very intuitive.

If the code implements a more complex function, then adding comments is essential. In the right place, the use of appropriate comments, can make the reader feel enlightened, they will silently in the heart grateful to you. note too little or no comment is no good, just like we eat. If there is nothing in a bowl of vegetables, you will feel very dull and have no appetite. If you put a little chili sauce, you will feel the appetite doubled. Whether you believe it or not, I believe it anyway.

However, the comments can not be too much, can not hide the useful code, can not be distracting, so that the real implementation of the code of the function as a foil. Programming for humans: How to write good code that "people" can read

So how do we write "good" code that "people" can read? This process can not be done overnight, to gradually, from my start, from the side to start, and constantly improve the state of personal programming.

Personally think that you can consider the following aspects to start:

First, the new recruits to the staff of the software programming norms training. in the beginning of the work, let them strictly refer to the programming specifications to write code. The earlier the training of programming norms, the sooner you get into the habit of writing code, the more clearly the code is written. By the way, many IT companies do not have this awareness, just to train the corporate culture, so that it will be able to increase employee loyalty. In fact, it's just a whimsical approach.

second, regularly in the project team to carry out the topic of programming norms, to strengthen the awareness of everyone. Old employees write code to the new employees have a demonstration role, if the old staff write procedures are poor readability, then the new staff will think of it. What are they going to do? A lot of developers are obsessed with the hard stuff every day, ignoring some of the most basic things, so the ability is difficult to get promoted again. After you've written your code, don't assume that it's done, but also write some project documentation, such as detailed design documentation, unit/Integration test documentation, and so on. In these documents, to write their own ideas clearly, convenient for themselves or others to look up to quickly understand the process of thinking.

Third, developers write code in strict accordance with the programming specifications established by the company. how the variable is named. How the function is named. Note how to write. How the code is formatted. These are strict requirements, as a qualified software development engineer, writing code is the basic requirements. When we read the beautiful code of writing, is not the heart will feel very good. To some extent, the level of code writing can reflect a programmer's attitude and professionalism.

the project team should strictly implement the peer review process. most IT companies in order to improve the quality of products, there is a process called "peer review", that is, the project team members to examine each other's results, we learn from each other, mutual improvement. However, it may be the impact of Chinese culture, we are more sensitive to face, so do not want to be true to other people's ideas expressed, but also make "peer review" a mere formality. Of course, maybe you have no problem with other people's procedures, that's another matter. It's not offensive to be honest with others, it's a good way for everyone to learn from each other.

Five, the most important thing is that individuals should have the sense of writing code, to constantly learn a variety of techniques to improve the ability of programming. no matter what others say to you, if you do not want to write the program, then even if all the external forces, and how. Programmers are busy, but they also take the time to learn new technologies so that they don't get knocked out by new technology.

"Waves will sometimes, straight hanging clouds sail the sea", for many people, to write a computer can read the program is enough, but if you want to become a good software development engineer, then you should strive to write "people" can easily understand and comprehend the code. This is a long-term process, we should have "Long March" preparation, to have "Yugong Yishan" spirit.

Related Article

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.