Re:How not to write shitty code: Intentional Conditions
by lonelappde on Sunday April 19, 2020 @06:49PM
(#22919443)
Writing extra error prone code just to make easier debugging seems like a bad trade-off.
Better to learn how to use a debugger, and check preconditions, and log state changes, and write tests.
Similar to code being read a lot more than written, you should prioritise debugger user experience over other aspects. One thing I try to do is have a temporary variable called result in many places and immediately return that on the next line. Though in some versions of Visual Studio you can faff about and add a watch with some magic name ($return Value?) to inspect the return value its much easier to have an easy location to chuck a breakpoint. Similarly chaining method calls or LINQ should be broken up with easy inspection variables so you can easily verify the state.
It seems like needless verbosity but when prod is broken and you desperately need to fix something you'll be glad of it.