Author: Zhu Jincan
Source:Http://www.cnblogs.com/clever101
A company colleague asked me: "When should I use it?Assert? For example, if the input parameter of a function is a pointer and you want to calculate it effectively, the pointer must be non-null. In the pop-up warning dialog box, will it be okay to prompt the other party? Why?Assert? I want to ask when to use a dialog box to prompt users and when to useAssert?"
This is a question worth thinking about. First, define assert ( here I am talking about C ++ environment ) it takes effect only after debugging. The release is invalid. The fact that debugging takes effect tells us that assert one of the important functions is to help developers debug Programs to locate errors. As a common fact for developers, it is not difficult to solve the bug , locating bugs is often the most difficult. This is why I advocate the use of assert . Let's look at another layer. Let's assume that assert can be used on the released version, so when to use assert and when to use the prompt dialog box, what is the principle? I think there is a user-level problem. Generally, there are two types of users: developers before release and users after release. As a developer, we assume that he understands assertions, but for users, we cannot assume that he understands assertions. If this interface is intended for developers, you should use assertions to restrict input parameters. If this interface is intended for users, apply the prompt dialog box, for example, if you select to select an input file in the pop-up dialog box, but you have not selected the file, click "OK". This should be prompted in the dialog box, it should not be assertion (if the assertion dialog box appears, he does not know what is going on ).