Comments on: Check Yourself I see nothing wrong with the assert/if combo you advise against. Rule 0 of a game is always "It must not crash", hence the if(). However, you also want to know if there's an unexpected NULL ptr occasionally ( especially on some logical edge-case that's hard to repro ) so leaving an assert in to help track it down whenever it does happen is preferable to omitting it and having the crash just happen somewhere else. It also serves as a comment in a way, since an if() without an assert says that the code may or may not be passed NULLs, doesn't matter, but the assert declares it should never be passed one, and it states so quite succinctly. People have short memories nowdays, but one of the main differences I remember seeing in the Quake codebase when it came out versus the ones other people generally wrote back then was that every single ptr was check at usage, rather than just assuming it worked. Other games crashed occasionally, Quake didn't. I think it's a paradigm worth continuing. I see nothing wrong with the assert/if combo you advise against. Rule 0 of a game is always “It must not crash”, hence the if(). However, you also want to know if there’s an unexpected NULL ptr occasionally ( especially on some logical edge-case that’s hard to repro ) so leaving an assert in to help track it down whenever it does happen is preferable to omitting it and having the crash just happen somewhere else. It also serves as a comment in a way, since an if() without an assert says that the code may or may not be passed NULLs, doesn’t matter, but the assert declares it should never be passed one, and it states so quite succinctly. People have short memories nowdays, but one of the main differences I remember seeing in the Quake codebase when it came out versus the ones other people generally wrote back then was that every single ptr was check at usage, rather than just assuming it worked. Other games crashed occasionally, Quake didn’t. I think it’s a paradigm worth continuing.

]]>
By: Ben Carter/2011/03/05/check-yourself/#comment-1258 Ben Carter Sat, 05 Mar 2011 14:15:04 +0000