Programming in the Visual C ++ Environment

Source: Internet
Author: User

The Visual C ++ environment is a new programming language developed based on the C ++ language. C ++ language was born in 1970s and is a widely used programming language, especially in the field of system programming ),C ++It has become one of the most popular programming languages.

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.

  • How to better learn the C ++ Language
  • Detailed usage and maintenance of the C ++ Library
  • Detailed description of Visual C ++ programming Database
  • Study how to adjust Visual C ++ language by ADO
  • Advanced programmers describe operations on C ++ programs

Any communication must have certain specifications before it can be carried out. In 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 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.

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.

Write secure and reliable 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.

Contract Programming
The idea of Contract programming Design by Contract has been slightly mentioned in the C ++ Bible-level book Bjarne Stroustrup C ++ programming language, the father of the Visual C ++ environment, the Bible-level book object-oriented software architecture in the OO field illustrates contract programming in a large space. More and more software developers recognize the importance of contract programming, and gradually adopt contract programming in actual work.

A simple explanation of contract programming is: Define the contract between the implementer and caller of the function and the caller of the function to implement code block functions and classes by specifying the call condition constraints) and output results. As for our work, developers should define the contract for each function and class completed. Contract programming seems to be unremarkable and does not have any specific help for program development. In fact, contract programming can ensure the reliability and security of software to the maximum extent in the development stage.

In actual work, whenever you need to use modules provided by other programmers, you do not know how to call them or whether the parameters you pass in are legal, sometimes the processing results of functional modules cannot be believed. This should have been obvious because the module provider does not provide explicit information.

As a result, the caller can only feel the stones and cross the river in an uneasy manner, wasting a lot of time. In order to make his code more secure and reliable, he made a lot of judgments and assumptions in the code, this may cause damage to the code structure and loss of execution efficiency.

Finally, the caller still cannot ensure that his or her call is correct. By strictly specifying functions or classes), contractual programming defines mutual rights and obligations between function providers and callers to avoid the above situations, this ensures code quality and software quality.

Active debugging
Active debugging refers to adding a proper amount of debugging code when writing code to help us pop up a message box when a software error occurs, tell the developers where the error occurred, and stop the program. The debugging code is only valid in the Debug version. After full testing and Release of the Release version program, the debugging code will automatically become invalid.

Active debugging and contract programming complement each other to jointly ensure the quality of software development. 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. Various development languages and tools provide these debugging statements. The Visual C ++ environment provides the assert function, and the MFC provides the ASSERT debugging macro to help us perform active debugging. In actual work, we recommend that you use the mfc assert debugging macro in a unified manner.

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.