Abstract: think of writing this article, because recently saw a well-known open source projects of various problems in internal use, have to say that a lot of open source mind is good, but the distance from real engineering have, so it’s not a commercial company adopts open source products you should be careful if you want to introduce, often have…
Reprinted from: http://hellojava.info/?p=508
By Ali Bixuan
Think of writing this article, because recently saw a well-known open source projects of various problems in internal use, have to say that a lot of open source mind is good, but the distance from real engineering have, so it’s not a commercial company adopts open source products you should be careful if you want to introduce, tend to have more than N waiting for you to fill in the pit, Most successful open source projects have commercial companies behind them.
00 when I began to learn to write in the asp code, write code also easily ah, only to learn rules of grammar, libraries, you can write, remember once when I was an internship interview about let me in an afternoon of time to write a complete message board, that is brush brush to write, but with the later work, especially after joining ali, More and more understand why high-quality engineering code is difficult to write.
At the beginning of code writing, what I pay most attention to is how to realize requirements with codes. If it is only to realize business requirements, even a programmer who is just getting started can write codes as long as his ability to solve problems is OK. Therefore, I always believe that math score is a very important requirement for programmers. People who are good at math are usually good at problem solving and logical thinking.
In the above basic code writing process, students who write better will be reflected in the profound understanding of business and abstraction, and the code will have a certain reusable ability, which will not be discussed here.
But the code is to realize the needs of the business will be over, actually far from, it is just the beginning of writing code, in addition to forward the implementation of the logic, any one point of how to deal with abnormal branch of logic is more difficult to deal with part of the engineering code, the problem in a single type of system will be relatively well, in a distributed environment will become very complicated, For example, call other machine function timeout, error, exactly how to deal with, this is why there are so many distributed theory things out, after the increase of abnormal branch processing logic, it is usually found that at this time, the proportion of the forward logic code in the whole code will be significantly reduced.
After the exception branch logic is handled, it is often necessary to add the necessary log information, so that it is easy to troubleshoot the problem, rather than when it is time to troubleshoot the problem, the current state of the system is not clear, so eating important exception information and not throwing this behavior in writing code is very shameful.
After handling the actions related to the above exception, the code robustness should also be handled, which mainly refers to: 1. Self-protection ability provides interfaces have enough ego to protect ability, is the man who even using didn’t see the API documentation to use will not lead to system problem, this case is very much, such as foreign provides a batch query interface, the results of the user about a transfer array with thousands of user id inside, Query the direct memory consumption, such as this case can not blame the use of the people, but should blame the implementation of the API end of the protection is not good enough, according to such a standard to see, will find a lot of open source things are not qualified API; Another is capability protection, what happens when you exceed the amount of concurrency you can handle; 2. Restrictions on the use of resources, which is also poor for novice code or some open source products, it is easy to appear that once the scale is up, the resource usage has been rising, there is no limit, and then the system will fail. A very common case is the use of thread pool. Such as Executors of Java. NewCachedThreadPool, this interface are used a lot of people, but many people do not have carefully thought about will in some cases here to create a huge number of threads; For example, if you use a Map cache, the size limit is not considered. As a result, as the amount of data increases, it suddenly dies one day.
Robustness is one of the more complex parts of the code, and it’s often the part that shows the power of the code. It might look like a few lines of code, but the difference behind it is huge.
Open source products in addition to the gap on the robustness, usually there will be a huge gap is the expansion ability, the design of the whole system expansion ability enough usually cause structural remodeling, another is common on the concurrent processing is not effective, such as the proper use of the lock, the introduction of lock-free algorithm, etc., These require very strong system design and code skills.
In addition to the above, high quality engineering code also needs to consider maintainable (such as monitoring information exposure), security, etc. To me, I always think of engineering as taking some toy code and turning it into something that can be really robust in a commercial system.
The above written content is brief, but should also can see that for the high quality project code, actually implement the business logic is just one of a small part of, even the time spent is relatively at least part of the so I really agree with the interview to let students write code, this time it’s easy to see the students write code capability; Sometimes I would ask for IDE shortcuts or write a piece of code that wasn’t too complicated in order to test my students’ coding proficiency.