Another question again :P I'm not too sure whether I should post it here or on the OCaml mailing list, but I try SO first.
I like assert statements. However, I find the error messages close to useless without an additional message (assertion violation at line XXX --- well great, but what actually went wrong?).
I think the good example of an assertion is a pythonic assert x > 0, "X must be greater than zero for the algorithm X to work"
and a bad example is C-like assert(x>0)
.
I was quite disappointed to learn that there is no way to attach an error message to an assertion in OCaml =( My options are:
- Write a custom function, say
vassert
=> but I won't get the magic line numbers which are only possible with theassert
keyword - Use
failwith
, but it is considerably more verbose, and I think suffers from the same problem as a custom function. - Use functions from
OUnit
, but I don't want to introduce unneeded dependency.
Does anyone else have the same problem? What do people use?