debugme icon indicating copy to clipboard operation
debugme copied to clipboard

WISH: Near-zero overhead assertions

Open HenrikBengtsson opened this issue 7 years ago • 2 comments

(continuation of my Tweet https://twitter.com/henrikbengtsson/status/984323561656483841)

Analogously to how you can produce debug messages using:

    "!DEBUG Hello world: x = `x`"

I'd like to run assertion statements that have near-zero overhead, e.g.

    "!ASSERT 'x' is integer `stopifnot(is.integer(x))`"

This will allow package developers to add lots of internal assertions validating not only the contract of returned values, but also intermediate values.

The above could be achieved by

    "!DEBUG `stopifnot(is.integer(x))`"

but the downside is that this will also trigger lots of DEBUG-produced output if such exists. Not only may such output clutter troubleshooting but it may also have side effects conflicting with any troubleshooting efforts, e.g. in a DEBUG statement may touch a promise (think "delayed assignment") causing different results than when disabled.

Any assert framework should be supported, so it should not be hard coded to stopifnot() [which comes with even more overhead in R (>= 3.5.0)], assertthat, checkmate, ...

HenrikBengtsson avatar Apr 12 '18 18:04 HenrikBengtsson

stopifnot() [which comes with even more overhead in R (>= 3.5.0)]

Can you point me to a benchmark or commit?

mllg avatar Apr 12 '18 20:04 mllg

See https://github.com/HenrikBengtsson/Wishlist-for-R/issues/70

HenrikBengtsson avatar Apr 12 '18 21:04 HenrikBengtsson