Repeat Liang Ziqian's article-coding operation manual for separation of duties

Source: Internet
Author: User

Coding operation manual for separation of duties

 

 

Most of the problems found in this codereview have been mentioned in previous comments, so I read the code review and found a problem that people do not care about at ordinary times: the length of the code file reflects the habit of controlling the complexity of the encoding process.

 

 

 

This review code has seen more than 300 rows of class definitions. This type of code may be understandable at ordinary times, because many functions are combined and mutually dependent, for example, most games have too many player classes and have even thousands of class definitions. h include more than 50% of the module header files in the entire project, and most CPP files include them, forming a hot spot in the call structure. This type of source code can be imagined by everyone. It is very difficult to maintain it. how painful it is to build an analysis view of this module in your mind.

 

So I thought of taking the opportunity of this code comment, turning out a small article I wrote last year, sharing some personal programming ideas and habits with you, and going through more in-depth design work, achieve a reasonable responsibility segmentation granularity, and use the conceptual annotation + translation encoding process to enhance the accuracy and controllability of development.

 


Here we will list some of the opinions that have been circulating in the soft industry for a long time as a foreshadowing for future discussions:
1. We often hear engineers say that the bottleneck for improving work efficiency lies in the inability to focus on coding. during work, we are often interrupted by conversations, meetings, RTX, and other irregular insertion events.
2 As mentioned in the article "pieces of human ware", it takes 15 minutes to work in a focused state. Once interrupted, the stack is cleared, it may take another 15 minutes to build a new thinking cache and Context Environment, ideally.
3 In booch OOA-OOD book mentioned: the human brain in the management of events can not be too many, preferably less than 7 things, this can ensure the quality of thinking, too crowded thinking goals, this will overload the brain's thinking ability and lead to the risk of losing one's mind.
4. We often hear some excellent geek saying, "My most efficient time is from to in the middle of the night. One hour can be equivalent to eight hours in the day, and the time is from ......" In addition to the reasons for getting used to the biological clock, there is also a small relationship between disturbing and interrupting at night.
5. We often hear some old programmers say that pen mistakes cannot be avoided, but they can only be reduced by the automatic functions of the editor. Is that true?

 

 

 

-- As a programmer, how can we do this?
On the one hand, we hope that our team members can communicate effectively, respect each other's work time, reduce meaningless interruptions, improve the comprehensive quality and office etiquette of our partners, and avoid shouting, hands-free phone calls and RTX group chats, but as you may think, this is just a theoretical hope.
On the other hand, from the perspective of changing the engineering nature of our coding work, we can improve our combat capabilities to avoid cracking, improve toughness, and reduce attacks. Let's take a look at how we can achieve this goal.

 

 

 

We divide coding into several stages, each of which focuses as much as possible on an independent task and responsibility.

 

Now let's assume that we want to complete a module (big to service, small to data structure, in short it is a work unit, called a module). Under normal circumstances, we assume that engineers can correctly complete this module (the physical design part is not discussed today), but the process efficiency is different from the quality of the final deliverables.

 


There are three basic layers: functional design, implementation planning, and translation-type coding.

 


1. Module responsibility design-the value of this module in the overall system. Why do I have to write such a thing? Can I leave it alone? This step also involves the upstream and downstream interface and Interface Behavior of the module, such as how the caller cooperates with the called interface? What is the time series relationship between these logics? Do some statuses of the state machine conflict? And so on.

 


2. Hierarchical Design Within the module, such as the interface layer, logic layer, core data layer, and external dependency layer. The problem solved in this step also includes the scalability of each sub-module in the module, the logical dependency between the sub-modules and the call relationship dependency. Do I need to shield the expansion in the middle layer or put the dependency upside down? And so on.

 


3. Details about how to implement the core data structure, Core algorithms, and technical difficulties of the module-anyway, we know that this part of the challenge in most systems won't make engineers sleep. If this is not the case, if there is still a lot of uncertainty in the core design, please put this step before phase 1 to confirm the Physical feasibility of this module.

 


4. Responsibility segmentation with a reasonable granularity, that is, header files. In the header file, use annotations to clarify the upstream and downstream collaborators (Other submodules) of this submodule, how do you interact and complete the work together, and so on.

 


5. Comments of the function name and concept type in the C (. cpp) file. This step is important and critical. First write the conceptual annotation and then write the code. Write branches, loops, braces, paragraphs, and sequences in the natural language that programmers are most familiar with in comments. When writing comments, we actually consider robustness, fault tolerance, boundary, and branch, cycle conditions, data types, resource allocation and release, and so on, how can computers fulfill the core value of their work as we wish. This step determines what the computer will do, how it will do it, and the conceptual annotation can ensure that the coders use the most natural and most appropriate way of thinking and express the ideas.

 

6. Translation encoding. Translate comments from human language in function implementation into C/C ++/Java/C #/Python/Lua/lisp /. SH and other programming languages, translation work undoubtedly requires some of our syntax skills, variable name function name and external library function information, now they are converted into the encoding language, and works. Conservatively estimated that this part will occupy more than half of the seven rare tasks, so while doing translation work, if we are still working on the process or resource management interface design robustness trap avoidance, our mind is really too poor, it is likely to be overwhelmed (especially when it comes to extremely complex logic like a large game ). To avoid this risk, let the complicated things be completed in the conception, and let the expression itself be completed in translation encoding.

 

 

 

In summary, 1-4 is the design, 5 is the implementation of the planning concept, and 6 is the translation code. If nothing else is done, but we can insist on separating 5 and 6, code Quality (I guess :--) will also be significantly improved to make your work simple and accurate!

In terms of hacker's working methods, hacker is more advocating inspiration and impromptu play, and completes excellent design while coding, but unlike those of engineers in large projects, hacker considers the functions and fun of works, instead of always alerting "One hundred reasons not strong enough" in your mind, "it will bring upstream and downstream modules into the two hundred traps in the ditch" and "three hundred lines of code with clear and understandable behavior ", at the same time, hacker's coding time and location are slightly different from those of normal engineers.
In addition, the recommended books include the peopleware, OOA-OOD mentioned above, and an interesting booklet: Illustration of the tomato working method.

 

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.