In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to code C++, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
For users and scholars who have come into contact with C++ coding for many times, it is very important to understand the concept of C++ language, so let's first talk about what C++ language is. The so-called C++ language: it is a very widely used computer programming language.
In our actual development, we often reuse the code by copying the C++ code. This includes a copy of a piece of code, or copies of several files. Instead, I would like to propose what I think is the most basic coding principle: principle 6, never copy code unless you have to.
If we copy the code inside a project, it means that some of the code inside the project must be duplicated. As an efficient developer, why write repetitive code instead of reusing them directly? This shows that there is something wrong with the design of the code, or that the developer has made perfunctory operations for the sake of temporary convenience.
If we copy C++ code from one project to another. It means that we have actually written code that can be used between projects. This kind of code has been tested by at least one project, so why don't we just use it instead of copying it? The copy of the code has at least the following disadvantages:
1. If this code does not have bug. Then bug may appear during the copy process.
two。 If the code has bug, then bug is copied during the copy process. Bug can infect other engineering components, and even other engineering projects.
The so-called code reuse, I intend to give a definition as follows:
Bool check (const vector
< condition * >& conditions) {unsigned int i; bool result = true; for (iConditions [I]-> check_type = = "Hardware") resulte & & = HardwareCheck (condition- > param1,condition- > param2); else if (conditions [I]-> check_type = = "Registry") resulte & & = RegistryCheck (condition- > param1,condition- > param2); else if (conditions [I]-> check_type = = "OS") resulte & & = OSCheck (condition- > param1,condition- > param2) Else if (conditions [I]-> check_type = = "Process") resulte & & = ProcessCheck (condition- > param1,condition- > param2); ... }}
The above if... Else if is not only ugly but also long. More importantly, it is very unscalable. This check component must rely on a series of modules with very complex implementations, such as HardwareCheck, RegisterCheck, OsCheck, and ProcessCheck, which cannot be operated without any one of them. In implementation, this check is not reusable at all.
In addition, if there is a # include def.h in Log.c, it is destined not to be easily "copied". This is a convenient consideration in the engineering development phase: suppose I include all the header files, macro definitions, or function declarations in a header file called def.h. Well, it's very convenient for me to write C++ code, usually as long as # include "def.h", without worrying about the lack of header files.
The above content is how to code C++. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.