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?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Michael Selik <michael.selik@gmail.com>
Newsgroups comp.lang.python
Subject Re: How much sanity checking is required for function inputs?
Date Wed, 20 Apr 2016 05:18:23 +0000
Lines 35
Message-ID <mailman.13.1461129515.12923.python-list@python.org> (permalink)
References <5713E52D.3060407@icloud.com> <CAGgTfkOR8e501zFfRXLgv3imVnbL7nBqKNGhc95rJVBPPwEYeg@mail.gmail.com> <57145CB4.5040100@icloud.com> <CAGgTfkM41po9gWS=spn4+imqSczhnJsKdwBjBT0NHYpSW82JoA@mail.gmail.com> <5716E77B.6030306@icloud.com> <CAGgTfkM5qiaXMN2274YvHVDP57hd0jeFX1y+g+V7HmqdbjJb6A@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de z7HZWIPm1vTVLpQhDYz0PgfWfF1XEJce2UCHFyNG1vEA==
Return-Path <michael.selik@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.017
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'sanity': 0.07; 'subject:How': 0.09; 'exception': 0.13; 'suggest': 0.15; '2016': 0.16; '``in``': 0.16; 'bug...': 0.16; 'compares': 0.16; 'inputs': 0.16; 'keyerror': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'reusable': 0.16; 'subject:required': 0.16; 'wrote:': 0.16; 'say,': 0.18; '&gt;': 0.18; 'input': 0.18; 'to:2**1': 0.21; 'occurs': 0.22; 'am,': 0.23; 'code,': 0.23; 'code.': 0.23; 'seems': 0.23; 'second': 0.24; 'header:In-Reply-To:1': 0.24; 'sort': 0.25; 'possibility': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'boundary': 0.29; 'dictionary': 0.29; "i'm": 0.30; 'board': 0.30; 'code': 0.30; 'michael': 0.33; 'traceback': 0.33; 'similar': 0.33; 'tue,': 0.34; 'lists': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'received:74.125.82': 0.35; 'but': 0.36; 'lines': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'being': 0.37; 'skip:& 10': 0.37; 'suggestion': 0.37; 'thought': 0.37; 'wrong': 0.38; 'mean': 0.38; 'why': 0.39; 'goes': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'avoid': 0.61; 'provide': 0.61; 'different': 0.63; 'positions': 0.64; 'goals': 0.67; 'obvious': 0.76; 'positions.': 0.84; 'reading,': 0.84; 'checks.': 0.91; 'subject:much': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=gwTio9e9EZK15UTYPSMiYDABqtQ21A3kfjybLbz2oJA=; b=Wie9apJo6iTbkf/KWg+/GNNSAFMx5QxIekEWyx5gzUJoFHVj/slM6wEmTcASu6Dpbb Rq0jwOm8gPa2hFIAIhVAAesEGjd2ihNXLo7WQbWa63fyAqp6F0fsZkaLeW6ug4mWmGkg X3Q5fPjTmKHr82sDO6aVR9ErKsfe4wrrKiCRhm+4jfvu0EZKlkoq9hDIYDmDJyV1RDqC PjQJ/KTrjEGUfDdPGVSn8pdAcnfdyiQUFQm7EjOZgzFOgZ0Jgez5mMHYPRTuVo8yFNg6 yHzejOmHYoeOPsddYZf31dVhbV0vdwjnTWnbSivnwcnzmbrYv/FYSUjh9YHy2NcFLc+F lpMA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=gwTio9e9EZK15UTYPSMiYDABqtQ21A3kfjybLbz2oJA=; b=mV2S/aNzzg+N5Spg+QuLS0vHki1F/euteYDsjie/VsCWh/SIODnTxGJByLphT8uCSs X1K0G0h/ZEJEdMZ+S5ROiRGep3NYIUq4iT1LOfli0G4fpjFlcUqxN6HCb9XcyKXzCXqh yc93R6aXZ0EuHdvP/uuOz5xZX/jqrFYf00hYS3oyhn4JPmInnkcgGJPd7ECyYjGpX76Y NLCbj76oNfcvwb+pxNhWjOzAZTPW66rSYcZe9kFLMqvfiKoUgYYOT66y/PD1o5cyvFMp q4mTOcATS0nkuDetvgz0YRHdCH8iRLW/AM8KY1HVNuZA6qB6HvX0hyIxmKJS5ipskzHz 0Ejg==
X-Gm-Message-State AOPr4FVguA76rYE5wX+ofazf5WcdYEM04Mtw+xqYMRDxrAJL4WVF2vXMqMLk/66DBPvy809oPYC/6EUXy6+boA==
X-Received by 10.28.31.22 with SMTP id f22mr7068132wmf.103.1461129513686; Tue, 19 Apr 2016 22:18:33 -0700 (PDT)
In-Reply-To <5716E77B.6030306@icloud.com>
X-Content-Filtered-By Mailman/MimeDel 2.1.22
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <CAGgTfkM5qiaXMN2274YvHVDP57hd0jeFX1y+g+V7HmqdbjJb6A@mail.gmail.com>
X-Mailman-Original-References <5713E52D.3060407@icloud.com> <CAGgTfkOR8e501zFfRXLgv3imVnbL7nBqKNGhc95rJVBPPwEYeg@mail.gmail.com> <57145CB4.5040100@icloud.com> <CAGgTfkM41po9gWS=spn4+imqSczhnJsKdwBjBT0NHYpSW82JoA@mail.gmail.com> <5716E77B.6030306@icloud.com>
Xref csiph.com comp.lang.python:107394

Show key headers only | 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