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


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

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

Started byMichael Selik <michael.selik@gmail.com>
First post2016-04-19 08:02 +0000
Last post2016-04-19 08:02 +0000
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? Michael Selik <michael.selik@gmail.com> - 2016-04-19 08:02 +0000

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

FromMichael Selik <michael.selik@gmail.com>
Date2016-04-19 08:02 +0000
SubjectRe: How much sanity checking is required for function inputs?
Message-ID<mailman.1.1461052941.30862.python-list@python.org>
On Mon, Apr 18, 2016 at 1:05 AM Christopher Reimer <
christopher_reimer@icloud.com> wrote:

> On 4/17/2016 3:18 PM, Michael Selik wrote:
>
> > I'd rather turn the question around: how much sanity checking is
> > necessary or useful? You'll find the answer is "surprisingly little"
> > compared to your experience in Java.
>
> I'm looking for a pythonic approach to sanity checking. From what I read
> elsewhere, sanity checking belongs in the unit tests and/or library
> classes designed for other people to use. I haven't seen many examples
> of sanity checks that is common in Java.
>
> > For example, you don't need to
> > explicitly check whether the color is present in your dictionary,
> > because it'll give you a KeyError if you look up a bad key.
>
> Without the sanity check against the constant dictionary, the color
> variable could be anything (it should be a string value). Looking at the
> code again, I should relocate the sanity checks in the Piece base class.
>

Why relocate rather than remove? What message would you provide that's
better than ``KeyError: 42`` with a traceback that shows exactly which
dictionary is being used and how?

> Why does the len of positions need to be 16?
>
> The positions variable is list of coordinates for 16 chess pieces (eight
> pawns, two rooks, two knights, two bishops, a king and a queen) for each
> color, locating the pieces on either the bottom quarter (i.e., [(1,1),
> ..., (2,8)]) or the top quarter (i.e., [(7,1), ..., (8,8)]) of the board.
>

I meant, what goes wrong if the number of positions input is other than 16?
Without these "sanity" checks, your functions might be reusable in, say, a
checkers game.

[toc] | [standalone]


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


csiph-web