MattPD / cpplinks

A categorized list of C++ resources.
4.52k stars 478 forks source link

Add defensive programming resources #36

Open jeremy-rifkin opened 6 months ago

jeremy-rifkin commented 6 months ago

This PR adds links to libassert (shameless plug, I'm the author), and Bloomberg bsls_assert as resources for defensive programming

MattPD commented 5 months ago

Thank you for the patience! I definitely want assertions in cpplinks (I'm a big fan of assert-early-assert-often, as in https://llvm.org/docs/CodingStandards.html#assert-liberally) and I think the library is great, too, so a perfect fit.

What I've been thinking of is where to put these exactly (category-wise). I'm still not quite sure, so perhaps you can help me out, if you feel like (or it's going to be me (over-)thinking out loud otherwise).

Context: I think there's value in having good categorization, so as to avoid growing into one big "awesome list" (subjectively I consider this an anti-pattern: For practical, selfish purposes I also want to be able to use cpplinks myself to quickly find what I need).

This is the background that resulted in debugging.tracing being separate from debugging, testing.fuzzing being separate from testing, or compilers.correctness being separate from compilers.

In the same vein, I'm wondering whether asserts fit into debugging directly (in a defensive_programming section, which is also what I'm not sure about), elsewhere, or whether these deserve a distinct category.

Some thoughts and open questions:

(On a side note, perhaps error_handling would fit under correctness.error_handling?; One thing I'm sure of is that I agree with https://blog.regehr.org/archives/1091 that asserts themselves do not belong in the error_handling category. This does however make me hesitate to just create top-level assertions.md if there's a broader category that would be a better fit. FWIW, in retrospect I think using top-level atomics.lockfree.memory_model.md directly was a mistake--and concurrency would have been a better choice.)

Let me know if you have any thoughts on these; thanks!

jeremy-rifkin commented 5 months ago

Hi Matt! Thank you for the context on the organization of the project. I'm happy to opine, however, you have definitely given this much more thought than I have. (And TIL about offensive programming)

The main concepts to me seem to be defensive programming / "assert early assert often" philosophy, design by contract, and error handling. To me these fit very comfortably under a correctness (or design.correctness) category.

static_assert is tricky to place. To me many uses of static_assert seem comparable to contracts, such as static asserting that a struct is a certain size or satisfies certain concepts, and I wonder if it would fit under a design by contract sub-category.