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


Groups > comp.lang.python > #107240 > unrolled thread

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

Started byEthan Furman <ethan@stoneleaf.us>
First post2016-04-17 22:26 -0700
Last post2016-04-17 22:26 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

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

FromEthan Furman <ethan@stoneleaf.us>
Date2016-04-17 22:26 -0700
SubjectRe: How much sanity checking is required for function inputs?
Message-ID<mailman.138.1460957122.6324.python-list@python.org>
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~

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web