Message-ID: <26468.1261.138143.666018@rob.eddelbuettel.com>
Date: 2024-12-19T11:35:09Z
From: Dirk Eddelbuettel
Subject: [R-pkg-devel] use of assert in C++
In-Reply-To: <463fb69e-8200-4770-9817-d71c199f7ed6@gmail.com>
On 19 December 2024 at 06:06, Duncan Murdoch wrote:
| I think it would be really misleading to have code that routinely
| ignored the assert() calls. In a year would you remember that those
| asserts were effectively just comments, not being acted on without some
| trickery to enable them?
Or have a user with different compiler flags without the NDEBUG ... and now
you have different behavior on different installation which is not great.
| You'd be much safer if you used a different function specific to R that
| triggered an R error if the assertion was false.
Seconded.
We trade run-time and compile-time off in other ways so this should be a
run-time check, with e.g. Rf_error() or Rcpp::stop() returning to the R
prompt with an error message. If you feel you must program your C++
components with assert() you could still do so in an external library
effectively hiding it from CRAN check. But that's cheating.
Dirk
--
dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org