5 ms·
Do you mean checked by a human reader? If so, a linear sequence of if statements that return early is far easier to check than than deeply nested statements whe
by quietbritishjim 7y ago
Do you mean checked by a human reader? If so, a linear sequence of if statements that return early is far easier to check than than deeply nested statements where the error handling for failures is effectively back-to-front at the end.
Or are you saying that there are some lines of code at the end checking the post conditions? I'm not exactly sure what that would look like, it sounds a bit insane, especially if you do it for every function. Could you give an example?
- augustk 7y agoI mean programmatically with an assertion statement or similar. You don't want to add the same assertion before each return statement.
- darwingr 7y agoI’d love an example if you have one. I’ve used assertions lots as guards or pre-condition checks on entering the function but never right before returning.
- augustk 7y agoA complicated sorting algorithm could assert that the result is sorted before returning.
- raiph 7y agoHopefully you saw Liz's comment. Raku has a zero cost way to add arbitrary post processing that kicks in no matter where or how a block of code exits. This provides a general mechanism accessible by arbitrary user defined control flow related constructs. Raku also ships with a dozen or so built in constructs such as PRE and POST blocks that are the foundational elements for DbC, plus UNDO and KEEP blocks for transactional semantics, and so on.