Thoughts on adding safety checks to a library
I've been working on an array library and now I'm thinking of adding built-in protections for things like out-of-bounds array accesses and such. Currently there are some sanity checks in place but it really could be more robust.
One of the ideas I've been considering is to report the error in detail and then exit. That seems better in the long run because then you don't necessarily have to resort to debugging. Just read the read the error that's been logged and the fix will likely be obvious. On the other hand, most of the library is implemented as macros so that does impose some limitations on forming expressions that can both return a result *and* fail on error.
But then also what if the application is already properly bounds checked? It doesn't really make sense to waste so many precious CPU cycles in tight loops in such cases. So maybe it should just be an opt-in feature? I was also wondering if there are any good generic approaches to that end. Because I'm really not looking forward to putting together that potential mess of code!