If I understand contracts right, as in, that they're a basic form of dependent typing, I think that offers a form of safety in its own right.
As a fan of functional programming, I love this as a language feature. I also appreciate that it's profoundly opt-in, and I agree that package management and memory safety are more pressing.
I'm curious, as a C++ outsider: what memory safety features are currently being discussed that look most promising? How many would retroactively apply to existing code bases if compiled against an appropriately recent `--std` setting?
I thought contracts were just sugar for pre- and post-conditions.
> If I understand contracts right, as in, that they're a basic form of dependent typing,
No, C++ contracts have nothing to do with the type system. It is purely predicate calculus using Hoare logic where subsets of state space are filtered from a larger program state space. The program is basically "steered" through the global state space using pre/post conditions.
Note however that theoretically (i.e. following from Curry-Howard correspondence) contracts can be thought of as dynamic counterparts to dependent types. But that is in a functional language with typing using constructive logic and not in an imperative language.
I’m not a C++ programmer but I like the idea of contracts. I’d be happy to have them in Java.
However, I think it’s insane to allow them to modify values. I get it probably really hard to prevent that in C++, but man is that going to be insanely hard to reason about.