How can we balance the design of C ++ projects?

Source: Internet
Author: User

A few days ago, I looked at the source code of a project I wrote. Previously, due to the increase in processing cores, the problems found in practice were constantly involved in the Code. The Code of some modules was relatively mixed, and I had been trying to find time to refactor but had no time. As a result, another colleague restructured and handed it to me. From the perspective of the overall situation, the code is indeed highly decoupled, and some concepts of the design pattern are introduced, and the code structure is clear. However, after careful tracking and analysis, I found that, unlike the reconstruction method, there must be at least two more layers than I thought, and a large number of applications with complex data structures are involved, as a result, it is really laborious to look at the code again. debugging tracing usually requires several layers to enter the main logic processing layer. There is a conflict in my mind, that is, whether I think it is simple or my colleagues are over-designing it. With this question, I threw the question to "zhihu ". Let's take a look at several discussions:
Sun Liwei started to play computer at the age of 17 and made a living on it. Ten years of software development... :At the language level, Java is better encapsulated than C ++. Compared with pure object-oriented syntax and a standard development library, Java greatly simplifies development. The C ++ language is relatively low-level and must be compatible with C. As a result, when C ++ is used for development, it is difficult for people who have just transferred to C ++ to turn their thinking from process-oriented to object-oriented. This is a phenomenon I often see in my actual work, for example, the singleton mode is frequently used, printf and sprintf are used, FILE and macro are used, and pointer is used for all parameters. However, it is not intended to cause an old debate that C ++ is better than Java, or object-oriented or process-oriented. My personal opinion is that any computer language has the ability to solve problems. It can be used for different projects, different problem domains, or even individual habits. To put it bluntly, you need to use scripts such as JavaScript, Python, and Ruby for development. As long as you write well, you can do the same. The difference may be that the specific value of a project is not worthwhile, or it is not feasible. Second, we have a big misunderstanding in program development. We believe that a specific technology, such as the design mode, C ++ template, and multithreading technology, can solve all the problems. There is a saying like this: "There is a hammer in your hand and there are nails everywhere ". In particular, the knowledge you just learned is always impulsive and you want to use it whenever you have the opportunity. To be honest, so do I. However, from the software project point of view, this approach is very harmful. Here we will not talk about it too late, Zzzzzz ....). To decouple the business logic, code must be further abstracted, but it does not mean that the higher the abstraction level, the Code logic will become complicated, and it does not mean that the code is getting increasingly difficult to read. The complexity of the Code should be directly proportional to the complexity of the business logic. The Code becomes more and more complex only when the complexity of requirements increases. Decoupling is meaningless for abstraction and decoupling. In a word, the code is complex and abstract, which does not mean that your code is hard to understand and become difficult to read. The key lies in the design and coding capabilities.
Chen Shuo, a Linux C ++ programmer, author of The muduo network library, weibo.com/giantchen... :"Simple C ++ design" http://www.iteye.com/topic/736269 "on Java development do not understand some issues" "decoupling is just a means to confuse people, is the pursuit of excessive design people explicit tools. Only the real cohesion, there is no absolute decoupling, But if you cut off the contact somewhere, then you will inevitably re-produce the contact in another place "http://www.iteye.com/topic/947017
Bai shunlong, codenong, uses C ++ java to work:Multi-layer encapsulation, using a complex data structure, the code is more intuitive and easy to understand ----- You are easy to understand, not equal to others' easy to understand, or you can look at it later, the people who talk about this are basically confused. I am used to being limited to my own code habits, and may not be used to reading elegant code. Although a high degree of decoupling is achieved after the introduction of the design pattern, ------ the design pattern is not for decoupling, but only for the effect. The key is clear functional separation, which is easy to expand. But there is no need to introduce some patterns for things that are basically unchanged, or something that is originally coupled. But the code logic is complicated. How can we balance it well? ----- I ask you, is addition complicated or multiplication complicated, and calculus? Why do people need to invent such a complex thing as multiplication when they have addition? If you want to add the result from 1 to N one by one, do you still use (1 + n) * n/2 to get the result directly? Do not leave yourself at the primary school level and think that the things in the middle and high school are complicated, so that you will always be able to do things for primary school students. In junior high school, multiplication is a child game, so you don't need to pay special attention to multiplication when it comes to college students, know when to use calculus, and simple equations are obviously not enough. What mathematical tools should be used.
Yu Tiansheng, a liberal arts students who appear to be engineering students and graduate students in computer technologyIf it cannot be balanced, I think it can sacrifice ease of use. It doesn't matter if the logic is more complex. The code quality is the first. It may be that you have chosen the wrong design pattern. Please try to see if there are any good solutions.
Edwin, C ++ programmer"But the code logic is complicated" is not a drawback. The key is to write code with high reusability and quality. When it comes to balance, there will be a pressure on the project progress, which will affect the code quality. However, in the long run, code with high quality still reduces costs.
Zheng Shuqing, System ArchitectWhether the design model can exert its value depends on whether the entire team can recognize and master it. The code is written to the reader. If a person is unhappy, the structure will be damaged and maintenance will eventually fail. The model also aims to unify the style. The key is to check whether the team can reach an agreed standard and improve the code quality.
A wonderful discussion has its own points of view. How can we balance them?

This article from "forever friends" blog, please be sure to keep this source http://yaocoder.blog.51cto.com/2668309/793035

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.