During the 51 period, the former colleague asked a question on QQ:
What kind of code do you think is a high-quality code?
At that time because of play in the field, did not respond promptly. Today, I took the time to reply to him:
This question is not difficult to say, simple is not easy. Everyone's level, experience, and preferences can affect the understanding of code quality. Here are the high-quality codes I think:
1. Readability. Can make a lot of people understand. In addition to the basic factors such as variable naming, function size and combination, the expression ability of the selected language also affects readability. Ruby's ability to express is more advanced than Java, C #.
In addition to the overall comment on the module, the code should minimize comments unless there is a section that produces two semantics. Because the code is the final product, is the carrier of all logic, too many comments will not only interrupt the idea of reading, but also make the code messy.
2. maintainability. A function is the smallest functional unit, to ensure that its functionality is single, and that the scale is as small as possible. This makes the code easy to modify in terms of detail.
How to control change is the core issue of maintenance. In general, a deferred implementation is used to shift the change to where it can be addressed. Common methods have delegates and inheritance.
Delegates move changes outside of the current module, while also injecting external logic into the current module, increasing the flexibility of the code, where the delegate is not limited to the type defined in C # by the delegate keyword, which is a way to delegate changes to other modules.
Inheritance enables changes to be passed along the inherited chain to subclasses until there are subclasses that can cope with this change. This makes the parent class A template for the algorithm, and the implementation of the subclass gives it flexibility.
3. Robustness. For general errors, remedial measures are provided to enable the program to continue running. Serious error, need to protect the data, at the same time terminate the operation of the program, so as not to accumulate errors, more serious errors.
Say this first, there is no ultimate answer to this question, and there is no complete answer. Presumably you also read a lot of views on the Internet, that most people agree with, it can be a standard, they are likely to read or maintain your code of people.
The above is my humble opinion.
High-quality Code