std.unittests for (final?) review

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Jan 6 07:09:03 PST 2011


On 1/5/11 8:54 PM, Ary Borenszweig wrote:
> I prefer assert, assertFalse, assertEqual and assertNotEqual.
>
> Compare this:
> assertPredicate!"a<  b"(1 + 1, 3);
>
> To this:
> assert(1 + 1<  3)
>
> Or to this:
>
> assertLess(1 + 1, 3)
>
> Ok, the first one is more generic. But so the error message for the assertion failure will be more generic, when you want exactly the opposite to happen.
> Plus your brain has to think more to read it (starting from the point that it's longer).
>
> assertPredicate!"<"(1 + 1, 3) reminds me of polish notation, which is very good for machines but not very good for humans.

One problem with using distinct names is the explosion thereof. Google 
unittests have EXPECT_EQ, EXPECT_NE, EXPECT_LT, EXPECT_GT, EXPECT_LE, 
EXPECT_GE, EXPECT_TRUE, EXPECT_FALSE and probably others. I was able to 
write these from memory because I used to know Fortran, which uses the 
same two-letter conventions for comparisons. At that point I think we 
can say, wait a minute, why not use the respective symbols which are 
impossible to forget?


Andrei


More information about the Digitalmars-d mailing list