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


Groups > comp.lang.python > #107239

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

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Christopher Reimer <christopher_reimer@icloud.com>
Newsgroups comp.lang.python
Subject Re: How much sanity checking is required for function inputs?
Date Sun, 17 Apr 2016 21:04:04 -0700
Lines 29
Message-ID <mailman.137.1460955847.6324.python-list@python.org> (permalink)
References <5713E52D.3060407@icloud.com> <CAGgTfkOR8e501zFfRXLgv3imVnbL7nBqKNGhc95rJVBPPwEYeg@mail.gmail.com> <57145CB4.5040100@icloud.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de bJSXvlFJ9aACdHfFRBANnwmR9G13JTnAWqTjGYskG/jQ==
Return-Path <christopher_reimer@icloud.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'key.': 0.07; 'sanity': 0.07; 'subject:How': 0.09; 'explicitly': 0.15; '...,': 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; 'subject:required': 0.16; 'wrote:': 0.16; 'string': 0.17; 'board.': 0.18; 'tests': 0.18; 'variable': 0.18; 'library': 0.20; 'color,': 0.22; 'constant': 0.22; "haven't": 0.24; 'thanks,': 0.24; 'examples': 0.24; 'header:User-Agent:1': 0.26; 'chris': 0.26; 'checking': 0.27; 'question': 0.27; 'pieces': 0.27; 'received:17': 0.27; '(it': 0.29; 'checking.': 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; 'received:10.0.0': 0.32; 'common': 0.33; 'michael': 0.33; 'received:10.0': 0.34; 'list': 0.34; 'could': 0.35; 'unit': 0.35; 'should': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'two': 0.37; 'turn': 0.37; 'anything': 0.38; 'why': 0.39; 'does': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'header:MIME- version:1': 0.60; 'your': 0.60; "you'll": 0.61; 'positions': 0.64; 'color': 0.67; 'header:In-reply-to:1': 0.84; 'subject:much': 0.91
X-Proofpoint-Virus-Version vendor=fsecure engine=2.50.10432:,, definitions=2016-04-18_04:,, signatures=0
X-Proofpoint-Spam-Details rule=notspam policy=default score=0 spamscore=0 clxscore=1015 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1510270003 definitions=main-1604180060
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2
In-reply-to <CAGgTfkOR8e501zFfRXLgv3imVnbL7nBqKNGhc95rJVBPPwEYeg@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
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 <57145CB4.5040100@icloud.com>
X-Mailman-Original-References <5713E52D.3060407@icloud.com> <CAGgTfkOR8e501zFfRXLgv3imVnbL7nBqKNGhc95rJVBPPwEYeg@mail.gmail.com>
Xref csiph.com comp.lang.python:107239

Show key headers only | View raw


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 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.

Thanks,

Chris R.

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


Thread

Re: How much sanity checking is required for function inputs? Christopher Reimer <christopher_reimer@icloud.com> - 2016-04-17 21:04 -0700

csiph-web