Why high-quality engineering code is difficult to write

Source: Internet
Author: User

http://kb.cnblogs.com/page/558087/

The reason why I think of writing this article, because recently saw a famous open-source project in the internal use of various problems, have to say, a lot of open-source ideas is good, but from the real engineering is not a small distance, so there is no commercial companies to adopt the open source products if you want to introduce the words must be cautious, There will usually be more than n pits waiting for you to fill out, and most of the more successful open source projects will have the business company behind the constant improvement.

Thinking back I began to learn to write ASP code in 2000, I think it is not difficult to write code, nothing is to learn grammar rules, library can be written out, I remember one time I intern interview is to let me in an afternoon about the time to write a complete message board, that is, brush brushes are written well, but with later work, Especially after joining Ali, more and more understand the high-quality engineering code why difficult to write.

At the beginning of writing code, the most concern is how to implement the requirements of the code, if it is only to achieve business needs, even the novice programmer, as long as the ability to solve the problem is OK, basically can write code. So I myself always think that math is a very important requirement of programmers, math good people usually solve problems and logical thinking ability is also good.

The above basic code writing process, write better students of the embodiment of the business in a deep understanding and abstraction, written code will have a certain ability to reuse, this is not discussed here.

But the code is not the realization of the business needs of the end of it, in fact, far from the beginning, this is actually just writing code, in addition to the logical implementation of the forward, any point of the exception of the branch of the logic is more difficult to deal with the code in the engineering of the part, the problem in a stand-alone system will be relatively good In the distributed environment will become very complex, such as calling other machines function timeout, error, what to do, which is why there are so many distributed theory of things out, in addition to the exception branch of the processing logic, It is often found that the code in the forward logic is significantly reduced in proportion to the entire code.

After the exception branch logic is processed, it is often necessary to add the required log information to facilitate troubleshooting in the case of problems, rather than to troubleshoot the problem, it is not clear what is happening in the system at the moment, so it is very shameful to consume important exception information without throwing this behavior in the code.

After dealing with the above abnormal action, the robustness of the code should also be handled well, this mainly refers to:

  1. Self-protection ability

External interface to provide adequate self-protection, that is, even if the use of people do not carefully look at the API document random use will not lead to system problems, this case is very much, such as providing a bulk query interface, the results of the user passed a number of thousands of user ID in the array, Query directly to the memory consumption, such as the case can not be used to blame people, and should blame the implementation of the API at the end of the protection do not good enough, according to this standard to see, will find that many things open source API is not too qualified.

There is also the ability to protect, if beyond the capacity to handle the concurrency, what happens at this time.

  2. Restrictions on the use of resources

This is also the code novice or some open-source products in the poor place, it is easy to scale up, resource usage has been up, no restrictions, and then led to the system hangs, very common case is the use of the thread pool, For example, Executors.newcachedthreadpool in Java, this interface is used by many people, but many people do not think carefully will not be in some cases to create a huge number of threads, as well as a map to do the cache, and do not consider the size limit problem, the result is as the volume of data growth , one day suddenly hung up.

Robustness is a complex part of code, often a part of comparing code capabilities, and may seem like a few lines of code, but the gap behind it is huge.

Open-Source Products in addition to the robustness of the gap, usually there is a huge gap is the overall system of the design of the telescopic ability, not enough flexibility will often lead to structural reconstruction, and the common is not efficient in concurrent processing, such as the rational use of locks, the introduction of lock-free algorithm, etc. These require very strong system design and code skills.

In addition to the above mentioned, high-quality engineering code also need to consider maintainable (such as monitoring information exposure), security, etc., for me, I have always thought that the so-called engineering is to turn some of the toy-like code into a business system can be really robust running code.

The above content is relatively simple to write, but should also be able to see, for high-quality engineering code, in fact, the realization of business logic is only a small part of the proportion, even spend time is relatively minimal part, so I really very much agree with the interview when the students write code, this time it is easy to see the ability of students to write code Sometimes in order to examine the proficiency of the students writing code, I would ask the IDE shortcut keys, or let the handwritten paragraph is not too complex code.

Why high-quality engineering code is difficult to write (turn)

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.