Why are claims collected from manufacturing assemblies (other than performance)?

A typical argument for removing claims from production code is performance. It makes no sense to me. Yes, disabling multiple statements from critical critical 5% or so of your code can be a useful optimization. However, for the remaining 95%, they probably have no measurable effect, and statements can only increase the likelihood that if your code has an error, it will be quickly and easily diagnosed.

I do most of my programming in D, which has an enforce() function that does basically what assert() does, except that it remains in the build versions. I usually use enforce() most of the time, and assert() only in a few places where enforce() will be too expensive.

Is there any other reason besides performance for removing claims from releases? If not, then why languages ​​do not allow standard statement behavior to always be executed even in release builds and provide a second function that is more complicated and difficult to remember, something like expensiveAssert() , which is removed from releases and recommends it to be used only in performance-critical ones parts of your code?

+4
source share
4 answers

I think assert() was primarily intended as a tool for developers.

Part of the software for end users should provide some error handling (by registering and / or displaying a message to the user). assert() does not provide error handling.

However, I usually use the native release and debug assert functions. Both releases and debug assert are used only for unusual errors - which should never occur. But they give a useful error message (useful for the developer, usually not very useful for the end user).

Errors that may occur (input / output, incorrect configuration, ..) are explicitly processed and reported to the user.

+3
source

It is not simple. I think that the statements contained in the assemblies would add paranoia to people about what text (and / or source fragments) gets into the shipped binaries (think about what code comments will be similar if they fall into the sent binaries!), Which, in turn, impedes the use of statements.

Your mileage may vary.

+2
source

My answer would be that the statements prematurely terminate the program, often when it is not needed. Although a person may be paranoid because a missing statement leads to undefined behavior, the program may limp anyway. Statements can be very annoying and stupid when you come across them as a user. As in, why can't this game deal with ONE invalid texture ?! !!

Although statements are a great way to quickly catch development bugs, users hate them (in my opinion).

+2
source

I think the statements in the production code are fine. disabling it causes you to lose the idea of ​​problems in your production system. and I’m always wondering how my program / system behaves + production failure. in my opinion, the best "test data" to improve your system often appears through real users.

what i prefer:

  • save statements in production code
  • a log with good information in case assert failed
  • handle approval error (-> never show user stack trace)
  • after log files have been displayed for a long time to confirm failures and correct your code (for me, these are statements - these are programming triggers or contract violations)
+1
source

Source: https://habr.com/ru/post/1299915/


All Articles