Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107394 > unrolled thread
| Started by | Michael Selik <michael.selik@gmail.com> |
|---|---|
| First post | 2016-04-20 05:18 +0000 |
| Last post | 2016-04-20 05:18 +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.
Re: How much sanity checking is required for function inputs? Michael Selik <michael.selik@gmail.com> - 2016-04-20 05:18 +0000
| From | Michael Selik <michael.selik@gmail.com> |
|---|---|
| Date | 2016-04-20 05:18 +0000 |
| Subject | Re: How much sanity checking is required for function inputs? |
| Message-ID | <mailman.13.1461129515.12923.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web