A better assert() [was: Re: std.unittests [updated] for review]

Jonathan M Davis jmdavisProg at gmx.com
Fri Feb 4 07:13:41 PST 2011


On Friday 04 February 2011 04:40:35 bearophile wrote:
> > So moving them into explicit little features makes the language more
> 
> The two little features I am talking about are:
> - a halt() somewhere like in core.bitop or std.intrinsic or the default
> object module to replace assert(0); - And to use
> class_instance.invariant() to replace assert(class_instance).

assert(0) has the advantage of being a normal assertion in non-release mode. It 
also makes it clear that that code path should _never_ be reached. I don't think 
that halt would be as clear in that regard and it _certainly_ wouldn't imply 
that it would be a normal assert in non-release mode. We'd then have problems 
with halt not actually being halt in non-release mode...

I'm _definitely_ against changing assert(0). The real question though is whether 
you can convince Walter (which I doubt, but I don't know). Still, making such a 
change _would_ contradict TDPL, which is supposed to be a major no-no at this 
point.

- Jonathan M Davis


More information about the Digitalmars-d mailing list