4 ms·
Well tell that to Blizzard and all the thousands of other developers where asserts are used in production code, I guess.
by moonshinefe 10y ago
Well tell that to Blizzard and all the thousands of other developers where asserts are used in production code, I guess.
- TeMPOraL 10y agoI said "release versions", not "production code". Please check the very definition of assert() macro.
- moonshinefe 10y agoOkay but I'm pretty sure the manual pages for assert functions don't make a distinction between release versions and production code, whatever that is...
- TeMPOraL 10y agoLet me pull out the (relevant fragments of the) source of /usr/bin/assert.h on my machine: #ifdef NDEBUG # define assert(expr) (__ASSERT_VOID_CAST (0)) #else /* Not NDEBUG. */ # define assert(expr) \ ((expr) \ ? __ASSERT_VOID_CAST (0) \ : __assert_fail (__STRING(expr), __FILE__, __LINE__, __ASSERT_FUNCTION)) #endif /* NDEBUG. */ Do I really need to explain this more?
- acdha 10y agoThat's the code, not what moonshinefe was talking about, and we know that most programmers rarely look at the source for standard library code unless they're debugging something. Here's what the assert man page says on OS X: The assert() macro tests the given expression and if it is false, the calling process is terminated. A diagnostic message is written to stderr and the abort(3) function is called, effectively terminating the program. If expression is true, the assert() macro does nothing. The assert() macro may be removed at compile time with the cc(1) option -DNDEBUG. Note that the “may be removed” warning is at the end, where it's easy to miss and it mentions a specific compiler flag rather than the concept of a release build. On Linux, the man page leads with that discussion: If the macro NDEBUG was defined at the moment <assert.h> was last included, the macro assert() generates no code, and hence does nothing at all. Otherwise, the macro assert() prints an error message to standard error and terminates the program by calling abort(3) if expression is false (i.e., compares equal to zero). The purpose of this macro is to help the programmer find bugs in his program. The message "assertion failed in file foo.c, function do_bar(), line 1287" is of no help at all to a user. You're not wrong but you're being very optimistic to assume that a) every C programmer, including those grinding away on massive projects, has learned about this and knows every compiler flag in use and preprocessor macro defined in every file and b) large applications haven't accreted so much code in assert calls in that the current maintainers are afraid to turn it off. Stories like this one pop up every so often in the programming community for a reason.
- maxlybbert 10y agohttp://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4075.pdf http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n407... , starting on page 11. "Assert" isn't necessarily limited to the macro in assert.h. Some places, including I assume Blizzard, have more control over which builds remove which asserts.
- TeMPOraL 10y agoWell, if I redefine the word "alcohol" to mean "water", I can be sure that I won't get into trouble by drinking "alcohol" (a.k.a. TeMPOraL!alcohol) and driving. But it doesn't mean the laws saying "don't drink alcohol (::alcohol) and drive" are suddenly wrong. If Blizzard, et al. are using their own definition of asserts then they're responsible for their semantics. That doesn't change what is commonly understand as "assertion" in C/C++ code, and the author of this article is (apparently) using the bog-standard assert macro.
- maxlybbert 10y agoA broad definition is widespread: * http://www.boost.org/doc/libs/release/libs/assert/assert.html http://www.boost.org/doc/libs/release/libs/assert/assert.htm... * https://wiki.libsdl.org/CategoryAssertions https://wiki.libsdl.org/CategoryAssertions * https://msdn.microsoft.com/en-us/library/ew16s3zc.aspx https://msdn.microsoft.com/en-us/library/ew16s3zc.aspx * https://github.com/questor/eastl/blob/master/assert.cpp https://github.com/questor/eastl/blob/master/assert.cpp * http://kernelnewbies.org/FAQ/BUG http://kernelnewbies.org/FAQ/BUG Plus my copy of "The C++ Programming Language" (3rd edition) includes an example of creating an assertion facility that uses exceptions. I don't know who you talk to, but when assert comes up in conversations -- even conversations limited to C or C++ -- I know what the assert is meant to do but I don't assume I know where it's defined or if it's a one-size-fits-all approach.