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


Groups > comp.lang.python > #107394

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

From Michael Selik <michael.selik@gmail.com>
Newsgroups comp.lang.python
Subject Re: How much sanity checking is required for function inputs?
Date 2016-04-20 05:18 +0000
Message-ID <mailman.13.1461129515.12923.python-list@python.org> (permalink)
References (1 earlier) <CAGgTfkOR8e501zFfRXLgv3imVnbL7nBqKNGhc95rJVBPPwEYeg@mail.gmail.com> <57145CB4.5040100@icloud.com> <CAGgTfkM41po9gWS=spn4+imqSczhnJsKdwBjBT0NHYpSW82JoA@mail.gmail.com> <5716E77B.6030306@icloud.com> <CAGgTfkM5qiaXMN2274YvHVDP57hd0jeFX1y+g+V7HmqdbjJb6A@mail.gmail.com>

Show all headers | View raw


On Tue, Apr 19, 2016 at 11:23 PM Christopher Reimer <
christopher_reimer@icloud.com> wrote:

> On 4/19/2016 1:02 AM, Michael Selik wrote:
>
> > 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?
>
> I think you misread my code. No dictionary exception occurs in the
> sanity checks. Below is the full function with the revised sanity check
> for positions that compares the input list with the two valid lists of
> board positions.
>

Perhaps I did misread it. What is the purpose of the "sanity check"? If
it's not obvious I suggest revising the code rather than adding comments.

The first time I read your code, I thought the check was designed to avoid
the possibility of a KeyError a few lines later. My suggestion was to
simply allow bad inputs to cause KeyErrors and not clutter your code. This
second time I'm reading, it seems to be a sort of boundary check, but using
``in`` which would cause a bug... Did you mean to use an inequality?


> > 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.
>
> I have no desire to write reusable code for two
> similar but different games at the same time.
>

Reusability is a nice side-effect of fewer "sanity checks". Other goals are
clarity, efficiency, and productivity.

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


Thread

Re: How much sanity checking is required for function inputs? Michael Selik <michael.selik@gmail.com> - 2016-04-20 05:18 +0000

csiph-web