What's the best way to minimize the need of run time checks?

Michael Selik michael.selik at gmail.com
Wed Aug 10 01:53:29 EDT 2016


On Wed, Aug 10, 2016 at 1:22 AM Juan Pablo Romero Méndez <
jpablo.romero at gmail.com> wrote:

> 1) catching exceptions at the point where you care, 2)
> preemptively check for certain runtime conditions to avoid exceptions 3)
> write as many tests as possible  4) learn to live with runtime errors.
>

I suggest focusing on #4, learn to appreciate/enjoy runtime errors. When
you've come around to that way of thinking, you'll have better judgement on
when to care about catching exceptions vs letting them stop your program.

As for writing as many tests as possible... eh. Think about your code
scientifically. You can disprove a falsifiable hypothesis, but you can't
prove a hypothesis. Sometimes you can formally prove the correctness of
your code via logical deduction, but that's not testing. Sometimes you can
exhaustively test all expected inputs, but it's impossible to exhaustively
test the infinity of possible inputs. So write tests as if you're
presenting evidence for a theory.



More information about the Python-list mailing list