Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107298
| 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 | Tue, 19 Apr 2016 08:02:03 +0000 |
| Lines | 38 |
| Message-ID | <mailman.1.1461052941.30862.python-list@python.org> (permalink) |
| References | <5713E52D.3060407@icloud.com> <CAGgTfkOR8e501zFfRXLgv3imVnbL7nBqKNGhc95rJVBPPwEYeg@mail.gmail.com> <57145CB4.5040100@icloud.com> <CAGgTfkM41po9gWS=spn4+imqSczhnJsKdwBjBT0NHYpSW82JoA@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de ooHQ91MHclehpJKwTLQANwFs+DaYOZjGwRZWV8P/uYhA== |
| 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.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'key.': 0.07; 'sanity': 0.07; 'subject:How': 0.09; 'explicitly': 0.15; '...,': 0.16; '2016': 0.16; 'coordinates': 0.16; 'dictionary,': 0.16; 'elsewhere,': 0.16; 'java.': 0.16; 'keyerror': 0.16; 'len': 0.16; 'locating': 0.16; 'pythonic': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'reusable': 0.16; 'subject:required': 0.16; 'wrote:': 0.16; 'string': 0.17; 'board.': 0.18; 'say,': 0.18; '>': 0.18; 'tests': 0.18; 'input': 0.18; 'variable': 0.18; 'library': 0.20; 'to:2**1': 0.21; 'color,': 0.22; 'constant': 0.22; "haven't": 0.24; 'examples': 0.24; 'header:In- Reply-To:1': 0.24; 'mon,': 0.24; 'checking': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'pieces': 0.27; '(it': 0.29; 'checking.': 0.29; 'dictionary': 0.29; 'quarter': 0.29; "i'm": 0.30; 'classes': 0.30; 'code': 0.30; '(i.e.,': 0.30; 'checks': 0.30; 'class.': 0.30; 'compared': 0.30; "i'd": 0.31; 'common': 0.33; 'michael': 0.33; 'traceback': 0.33; 'list': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'received:74.125.82': 0.35; 'unit': 0.35; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'being': 0.37; 'skip:& 10': 0.37; 'turn': 0.37; 'wrong': 0.38; 'anything': 0.38; 'why': 0.39; 'goes': 0.39; 'does': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; "you'll": 0.61; 'provide': 0.61; 'positions': 0.64; 'color': 0.67; '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=p7AmYVlyn0p/pgjTJ8OLetRqj58aY79dwK4m7RtQl94=; b=cEiuWu1k6oi8EFcJZgRgnt26CAl6OMoYtn7k/5OJ8I+5WNUIKPbTbPnvo1m4kLm+aL OqcdM+KCQ+p7zvwnIsBdRPSYX4QZlwN271YTt8uOrUrYwgQ1TzoS/yneNwGpac5p1rfn o7Q2uxTDZMW4tpVA+DorMBIZpWmLT2JjYrMV5bCj3mKDR8Pyxcfc4DQ9Nxoe+XkjUF+M Egxn9L6VSIHLos0wKIyR+3RoAZNBMR9lOBRk/b6j1J825QshAgXbjjjGe4PWTHtfQchM g2Zdxz1rWO85vxVxlueIUJSA/ujLeQi6ESRFNVCJyoIAd57eApD9lTkTKJQCVEsCxzse L97w== |
| 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=p7AmYVlyn0p/pgjTJ8OLetRqj58aY79dwK4m7RtQl94=; b=efZDYx+IC11inDkAQRGh1DUlOtsiJGaB7t1T4PjwexMHIwtJ+Mx3ejj2xuryeHGd0l vW6SXeE3x4Q2BtDpLToYTiOTjMZYogh2Un+dQ7WM2oyOz/kNnELQFsEp92XVNHKv3/3J uZRoDrL6lRs29JYbEnw7WWTSJxOc1VyMlM7k4pTaR68ezceSmFllva0hIg9vq9KJU4AN 8RIhpNgKl71ON7ruNyJCbO3+VyLR2JEl8ycBXdGAhOJhtjXFElHqK3/ZLxGolPhz3+1W ooOF0DIlsryECPFgEEr4acBTlQbq4uolhlYhuBcKoXeuwC90PmWFkO0rf1alb5pjzXfA x7Tg== |
| X-Gm-Message-State | AOPr4FUzJIjPd81KTNzguYirfL61OjvLKPmO/R3zEqcuNU84ET0BJ7huaLjzA4bML6aM8Cab6kndYzTBpuKoDw== |
| X-Received | by 10.28.31.22 with SMTP id f22mr2074745wmf.103.1461052933041; Tue, 19 Apr 2016 01:02:13 -0700 (PDT) |
| In-Reply-To | <57145CB4.5040100@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 | <CAGgTfkM41po9gWS=spn4+imqSczhnJsKdwBjBT0NHYpSW82JoA@mail.gmail.com> |
| X-Mailman-Original-References | <5713E52D.3060407@icloud.com> <CAGgTfkOR8e501zFfRXLgv3imVnbL7nBqKNGhc95rJVBPPwEYeg@mail.gmail.com> <57145CB4.5040100@icloud.com> |
| Xref | csiph.com comp.lang.python:107298 |
Show key headers only | View raw
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.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: How much sanity checking is required for function inputs? Michael Selik <michael.selik@gmail.com> - 2016-04-19 08:02 +0000
csiph-web