Detailed descriptions of C ++ code examples

Source: Internet
Author: User

These debugging codes are only valid in the Debug version. After full testing and Release of the Release version program, these debugging C ++ codes automatically fail, contract programming is equivalent to various contracts signed in economic life, and active debugging is equivalent to the legal penalty measures taken when a party fails to comply with the contract.

1. Standardized and easy-to-understand code

At this stage, software development relies on the cooperation of teams. Programmers are no longer synonymous with personal heroism. On the one hand, programmers must rely on a large number of other programmers to complete the code, and on the other hand, provide a large amount of code for others to use. The Code actually has two elements: the first is to provide a reliable function, and the second is to clearly express the author's thoughts. Any communication must have certain specifications. In C ++ code, the specifications are easy to understand. In addition, standardized and easy-to-understand code can be reused. Standardized Code has a longer life cycle, better maintainability, and more convenient extension later.

Several features of good code

What kind of code can be regarded as a standard and easy to understand? It is reflected in countless arguments in details. In fact, no matter the style and habits, good code has several common features:
1. Good naming: A good variable name and function name let people who read the code immediately know the role of the variable or function, and it is easy to understand the approximate structure and function of the program. It is necessary for programmers to understand the Hungarian naming law.
2. consistency: consistency leads to better programs. consistent code indent style can display the code structure. It doesn't matter what indent style is used. In fact, specific C ++ code styles are far from consistent.
3. NOTE: Annotations are a way to help program readers, and program authors are also one of the Future Program readers. The best comments are the highlights of the program, or provide an overview to help others understand the program. However, if comments only indicate what the code has already said, or conflict with the code, or confusing and interfering with readers in a well-organized manner helps.

Good habits

As mentioned above, it is far from important to use specific code styles. Therefore, it is A waste of time to put too much energy into the choice of A or B. What you need to do is to stick to it. Below are some tips on how to write standard and easy-to-understand code and develop good habits.

  • Father of C ++: Object-oriented evolution and implementation
  • How to better set Dev C ++
  • Analysis on the use and learning of C ++ Compiler
  • Brief description of struct ideology in C ++
  • C ++ programming language Overview

1. Name the variables and functions according to the Hungarian naming method.
2. Follow the international popular code style.
3. When writing code, you must follow your naming rules and writing style. You must never remedy the issue afterwards.
4. Use the tool Parasoft C ++ Test) to check your code and evaluate whether you have formed good habits.
5. persevere until you develop habits.

2. Write secure and reliable C ++ code

In large application software systems, code snippets constitute a complete system. Code interactions are frequent, and program crashes do not occur when errors occur, it is a delay of a period of time. It takes a lot of time and effort to locate and search for errors. How can we timely reflect errors in the program, how can we avoid some naive Semantic Errors in code? A function is often used by other programmers, but how can he correctly use functions compiled by others? This part can be partly) help solve these problems.

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.