Home >Backend Development >Golang >Is `assert()` Truly Evil in C and C ?
Is assert() the Devil's Spawn? A Rational Examination
In their wisdom, the Go language creators have decreed that assertions are evil, a crutch that stifles proper error handling and reporting. But how do these arguments hold up in the realm of C and C ?
Arguments Against Assertions
According to the Go team, assertions are problematic because:
Arguments for Assertions
Despite the concerns raised by the Go creators, assertions do have their uses, particularly in the following scenarios:
Pros and Cons
Pros:
Cons:
Conclusion
The use of assert() is not inherently evil, but it should be employed wisely. Assertions should be reserved for debugging purposes or as a secondary line of defense against unexpected conditions. By adhering to these principles, C and C programmers can harness the benefits of assertions without compromising their code quality or performance.
The above is the detailed content of Is `assert()` Truly Evil in C and C ?. For more information, please follow other related articles on the PHP Chinese website!