logoalt Hacker News

quotemstr • today at 6:48 AM • 1 reply • view on HN

There's nothing "legacy" about checking invariants at runtime, and you can't simultaneously dismiss the concerns of people doing so on the grounds that they're "still us[ing] legacy C asserts" when you deny them an alternative to "legacy C asserts". That's question-begging.

> People figured out how to do with C++20 better than what contracts promised.

What contracts used to promise is irrelevant. The contracts on the table modernized runtime assertions and are irrelevant to concepts, constexpr, and related facilities.

Is the contracts feature more useful than C's assert()?

If you want to argue that we're better off with the old macro, do so directly. Concepts, in this context, amount to irrelevant distraction.


Replies

jandrewrogers • today at 7:04 AM

I have no issues with people check invariants at runtime. It is unavoidable. C++ contracts is a mediocre way of doing it. Many C++ code bases don’t use any macros at all for assertions and haven’t for a long time. Their models are much more nuanced than C++ contracts allows.

Why would anyone that already ditched C asserts use C++ contracts when it can’t express what the alternatives already can? This isn’t a new problem. People were creating more expressive assertion replacements than contracts offers a decade ago.

C++ contracts are nerfed. It is less expressive and capable than what anyone that cares about these things already uses. So who is expected to use it?

➕ show 1 reply