3 ms·
But why? You can do everything contracts do in your own code, yes? Why make it a language feature? I'm not against growing the language, but I don't see the nec
by quotemstr 7mo ago
But why? You can do everything contracts do in your own code, yes? Why make it a language feature? I'm not against growing the language, but I don't see the necessity of this specific feature having new syntax.
- jandrewrogers 7mo agoDYI contracts don't compose when mixing code using different DYI implementations. Some aspects of contracts have global semantics.
- deleted 7mo ago[deleted]
- jevndev 7mo agoThe common argument for a language feature is for standardization of how you express invariants and pre/post conditions so that tools (mostly static tooling and optimizers) can be designed around them. But like modules and concepts the committee has opted for staggered implementation. What we have now is effectively syntax sugar over what could already be done with asserts, well designed types and exceptions.
- addaon 7mo agoContracts are about specifying static properties of the system, not dynamic properties. Features like assert /check/ (if enabled) static properties, at runtime. static_assert comes closer, but it’s still an awkward way of expressing Hoare triples; and the main property I’m looking for is the ability to easily extract and consider Hoare triples from build-time tooling. There are hacky ways to do this today, but they’re not unique hacky ways, so they don’t compose across different tools and across code written to different hacks.
- spacechild1 7mo agoPre- and postconditions are actually part of the function signature, i.e. they are visible to the caller. For example, static analyzers could detect contract violations just by looking at the callsite, without needing access to the actual function implementation. The pre- and postconditions can also be shown in IDE tooltips. You can't do this with your own contracts implementation. Finally, it certainly helps to have a standardized mechanisms instead of everyone rolling their own, especially with multiple libraries.
- kevin_thibedeau 7mo agoIs a pointer parameter an input, output, or both?
- drfloyd51 7mo agoInput. You are passing in a memory location that can be read or written too. That’s it.
- kevin_thibedeau 7mo agoA pointer doesn't necessarily point to memory.
- j1elo 7mo agoA nitpick to your nitpick: they said "memory location". And yes, a pointer always points to a memory location. Notwithstanding that each particular region of memory locations could be mapped either to real physical memory or any other assortment of hardware.
- peterfirefly 7mo agoNo. Neither in the language (NULL exists) nor necessarily on real CPUs.
- bluGill 7mo agoNULL exists on real CPUs. Maybe you meant nullptr which is a very different thing, don't confuse the two.
- tialaramex 7mo agoI don't agree. Null is an artefact of the type system and the type system evaporates at runtime. Even C's NULL macro just expands to zero which is defined in the type system as the null pointer. Address zero exists in the CPU, but that's not the null pointer, that's an embarrassment if you happen to need to talk about address zero in a language where that has the same spelling as a null pointer because you can't say what you meant.