Skip to main content

Timeline for C++ Binary Search

Current License: CC BY-SA 4.0

8 events
when toggle format what by license comment
Aug 21, 2023 at 19:29 comment added bst @chux-ReinstateMonica that's a reasonable perspective. If that's the philosophy for whatever project you're working on, I can respect that. In my experience, asserting assumptions is extremely valuable, regardless of whether the programmer has control over them or not. I've caught countless bugs where the programmer intended one thing, but the code did something else, especially in C++ where so much takes place implicitly and so many operations are overridable. Add churn from maintenance and multiple programmers on top of that and assumptions break even more easily.
Aug 21, 2023 at 19:21 comment added chux bst, The assertions that benefit most are the ones the function relies on and cannot control, like the values of parameters received - and that can be done once, outside the loop. An assert inside the loop is testing function logic, that is within the control of the programmer and is less needed. Every assert disturbs code at some level from the release version. Keeping the more critical aspects of the function un-asserted (e.g. inside the loop) increases consistency with the release version.
Aug 21, 2023 at 15:29 comment added bst @chux-ReinstateMonica because the loop changes the value of begin and end, so the assertion wants to ensure things remain sane. One could argue that the way those values are changed will never break the assertion from outside the loop, but the whole point of assertions is to verify assumptions and be humbly defensive. Trying to optimize that defeats the purpose.
Aug 20, 2023 at 14:38 comment added chux Why assert in the loop? Would not assert(begin < end); while (begin != end) { ... achieve the same? (and allow for 1 less compare when in debug mode)
Aug 9, 2023 at 18:09 history edited bst CC BY-SA 4.0
typo
Aug 9, 2023 at 18:03 history edited bst CC BY-SA 4.0
added 17 characters in body
S Aug 9, 2023 at 17:57 review First answers
Aug 9, 2023 at 19:10
S Aug 9, 2023 at 17:57 history answered bst CC BY-SA 4.0