On 7/31/2014 1:11 PM, Daniel Gibson wrote:
I guess in many cases I'd avoid using assert() in fear of breaking my
defensively written program (like that example from earlier: assert(x !is null);
if(x) { x.foo = 42; }).

I just hang my head in my hands at that code :-)

Really, you're much better off writing something like:

   if (x) {
      x.foo = 42;
   }
   else {
      writeln("Sack the QA dept. for not testing this code");
      abort();
   }

which expresses what you intend directly and would be perfectly fine.


Somehow all this assumes that you found all problems (at least the ones you
check in assert()) by testing during development..
*I* personally wouldn't be so arrogant to assume that my code is bugfree just
because it passed testing...

No worries, I'd probably spare you and sack the fellow on your left!

Reply via email to