3 ms·
A comment with first class citizen status is an assert?
by forgotmypw17 3y ago
A comment with first class citizen status is an assert?
- sideshowb 3y agoI've never seen an assert explain why
- tleb_ 3y agoThe signature for static_assert(3) in C has a second argument that is `char *msg`. With C23 onwards, it becomes optional.
- marginalia_nu 3y agoJava has this too. assert isSorted(array, start, end) : "The input array for binary search is expected to be sorted"; That said, I think in many cases asserts tend to be fairly self-evident, they typically just list the invariants, e.g. assert start <= end; assert (end - start) % stepSize == 0; // some logic assert pos - start >= 0; assert pos - end < 0; assert (pos-start) % stepSize == 0; return pos;
- timeon 3y agokind of: https://doc.rust-lang.org/rustdoc/write-documentation/documentation-tests.html https://doc.rust-lang.org/rustdoc/write-documentation/docume...
- tpoacher 3y agoSome languages (e.g. D), have contract blocks built into the language, which are even better. (or, well, different).