logoalt Hacker News

dataflow • today at 1:23 AM • 2 replies • view on HN

> because you could pass a flag that simply turned all of them off

I don't understand why that's bad. What's wrong with letting users decide if they want safety or not?


Replies

Maxatar • today at 4:14 AM

The issue is more specific, namely that in C++ most code uses header files, and contracts must be specified in the header file, so that it creates the possibility where the same function can be compiled with and without contracts on and off.

This is known as an ODR-violation, where the same function is compiled with two or more definitions, and there's no rule in C++ to pick which definition should be used. One way to resolve this would be to introduce a rule to pick between these definitions (always pick the function with the contract check disabled, or pick with it enabled), but no one could agree on which rule to use and even if they did it would not work for shared libraries.

There is no doubt that once contracts get standardized, compilers will offer a flag to disable them categorically, ie. disable all of them across all definitions. That won't be an issue because then all definitions will be consistent. But the original proposal allowed flipping contracts on or off per "source-file" with the hopes that developer discipline would ensure that people were consistent about its usage.

legobmw99 • today at 1:36 AM

A long history of security flaws and bad decisions. Especially if you’re arguing that this feature exists for safety and can make libraries safer, it being completely ignorable meant you couldn’t rely on it for anything important, and anyone who wanted to force a runtime check would never use it over existing solutions, so why add it at all?