3 ms·
I remember attending a talk by Walter Bright maybe three decades ago, back when he was known for his C++ compiler for Windows, and before that his compilers for
by not2b 4y ago
I remember attending a talk by Walter Bright maybe three decades ago, back when he was known for his C++ compiler for Windows, and before that his compilers for DOS. He talked about his very paranoid approach to assertions; in addition to a huge number of asserts for preconditions, he would start out with asserts essentially at every basic block; he'd take them out as he produced tests that reached this point. This was the DOS days and he didn't have a coverage tool, so the presence of an unconditional assert meant that this line hadn't been reached yet in testing.
He said he developed that style because the lack of protection in DOS meant that any error (like a buffer overrun) could trash everything, right down to damaging the machine.
He said that early on those asserts were enabled in the shipping code, making it appear that his compiler was less reliable than competitors when he felt it was the opposite, but I think he wound up having to modify his approach.
- leeoniya 4y agohe actively hangs out here, btw :) https://news.ycombinator.com/user?id=WalterBright https://news.ycombinator.com/user?id=WalterBright
- mise_en_place 4y agoEven with these approaches, you will inevitably run into Heisenbugs that creep up as runtime errors. Even the most powerful compiler in the world can't catch those. It can be mitigated by having a system that is traceable from start to finish.
- pvillano 4y agolast Advent of Code I took to putting asserts for every invariant in my code. most of my time was spent debugging, not the first write or running code. adding so many asserts provided a number of benefits: * asserts are a compact form of documenting invariants both expected and produced, making code easier to reason about * each assert serves as a tiny unit test with exactly the necessary cases * most importantly, asserts catch logic bugs when code doesn't produce the intended results P.S. that has me thinking, there should be a tool to transform asserts into testing. The tool would have another keyword "expect" in addition to "assert", for preconditions. With both preconditions and postconditions, individual functions can be automatically verified with a prover or a fuzzer! The tool could also check that preconditions are met at each call site, without having to write and rewrite unit tests for each call site!