Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107240

Re: How much sanity checking is required for function inputs?

From Ethan Furman <ethan@stoneleaf.us>
Newsgroups comp.lang.python
Subject Re: How much sanity checking is required for function inputs?
Date 2016-04-17 22:26 -0700
Message-ID <mailman.138.1460957122.6324.python-list@python.org> (permalink)
References <5713E52D.3060407@icloud.com> <57146FFD.4090204@stoneleaf.us>

Show all headers | View raw


On 04/17/2016 12:34 PM, Christopher Reimer wrote:

> How much sanity checking is too much in Python?

What happens if your extensive sanity checks turn up a bug?

In Python the usual answer is you raise an error:

     raise ValueError('blahblah not a valid color')

What happens if you don't sanity check anything and the wrong color is 
passed in?

Python will raise an error for you:

Traceback
   ...
KeyError: 'blahblah' not found

---

I sanity check for three reasons:

1) raise a nicer error message

2) keep the point of failure close to the error

3) the consequences of bad data are Bad Bad Things (tm)

If none of those apply, I don't bother sanity checking.

--
~Ethan~

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: How much sanity checking is required for function inputs? Ethan Furman <ethan@stoneleaf.us> - 2016-04-17 22:26 -0700

csiph-web