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


Groups > comp.lang.python > #53244

Re: Interface and duck typing woes

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'output': 0.05; 'back.': 0.09; 'exception,': 0.09; 'oh,': 0.09; 'postgresql,': 0.09; 'rewrite': 0.09; 'scripts,': 0.09; 'python': 0.11; 'bug': 0.12; 'changes': 0.15; '"alter': 0.16; '(written': 0.16; 'example)': 0.16; 'exception?': 0.16; 'exceptions,': 0.16; 'fetches': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hmm.': 0.16; 'script,': 0.16; 'scripts.': 0.16; 'stderr': 0.16; 'stuff,': 0.16; 'wary': 0.16; 'exception': 0.16; 'prevent': 0.16; 'appropriate': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'all,': 0.19; 'trying': 0.19; 'commit': 0.19; 'thu,': 0.19; 'not,': 0.20; 'aug': 0.22; 'putting': 0.22; 'error': 0.23; 'junior': 0.24; 'file.': 0.24; "haven't": 0.24; '(or': 0.24; 'sort': 0.25; 'script': 0.25; 'handling': 0.26; '(for': 0.26; 'developing': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'patch': 0.29; "doesn't": 0.30; 'errors': 0.30; 'joe': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; 'code': 0.31; 'catching': 0.31; 'end,': 0.31; 'terminate': 0.31; 'probably': 0.32; 'covered': 0.32; 'critical': 0.32; 'me?': 0.32; 'run': 0.32; 'another': 0.32; 'bugs': 0.33; 'could': 0.34; 'problem': 0.35; 'transaction': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'disk': 0.36; 'skip:> 10': 0.36; 'so,': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'catch': 0.60; 'most': 0.60; 'till': 0.61; 'full': 0.61; 'simply': 0.61; 'simple': 0.61; "you'll": 0.62; 'soon': 0.63; 'our': 0.64; 'more': 0.64; '(that': 0.65; 'articles': 0.65; 'talking': 0.65; 'believe': 0.68; 'skill': 0.68; 'subject': 0.69; 'safe': 0.72; 'therefore': 0.72; 'integrity': 0.74; 'article': 0.77; '"real': 0.84; 'usage.': 0.84; 'error;': 0.91; 'acknowledge': 0.93; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Lh8cZuff4B98c0UgOiw8J2VpU/z63kAk+OVaCNQED+U=; b=NwhZTPVqL6PyPFijQ7yde5rvefChXczSFkoBP+adFYVB/CAEpJ2G2YdnAvjl7nuYBr QXz29G4p9VK5vPH7ZauQcgHAyg9fNtBJtUAy/eR1W3dMqT9w74CGze7vk8lSwnoMaWBo zIx53O5bfivo2so11aHFZz6+lCg7uOjjgDDfq1pJRywIbn6AvDtutztB4aR7CF0XVGcm t+hz0SoJEQSYx90h7qnCPAi8UmiREFuE/J6ayn97+JvqZ6L6WqqzULpzz33mN9v3Kp3+ vUPyooNXJGCLjgjZxKTQOXQYZurNiWRVMIU8U2X94RwUEqUuvm5vDF79uNXupJyXKcH+ 23vg==
MIME-Version 1.0
X-Received by 10.58.136.4 with SMTP id pw4mr3148023veb.10.1377781644904; Thu, 29 Aug 2013 06:07:24 -0700 (PDT)
In-Reply-To <CADuC2CssnrZExb7v58X=wEw3MpF9mA9EHYb0QqChj6_+ifwdjA@mail.gmail.com>
References <mailman.327.1377724351.19984.python-list@python.org> <pan.2013.08.29.09.41.38.945000@nowhere.com> <CADuC2CssnrZExb7v58X=wEw3MpF9mA9EHYb0QqChj6_+ifwdjA@mail.gmail.com>
Date Thu, 29 Aug 2013 23:07:24 +1000
Subject Re: Interface and duck typing woes
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.363.1377781653.19984.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1377781653 news.xs4all.nl 15958 [2001:888:2000:d::a6]:44950
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:53244

Show key headers only | View raw


On Thu, Aug 29, 2013 at 10:40 PM, Joe Junior <joe.fbs.junior@gmail.com> wrote:
> @ChrisA
>>Do you believe that you can write code to catch every bug you might
>>make? If so, you are naive and probably haven't spent much time
>>programming yet :) And if not, then you must acknowledge that bugs
>>WILL happen; therefore you will need to cope with them after the
>>event. So rather than trying to prevent them all, just improve your
>>means of coping, and you'll accomplish the same end with much less
>>trouble.
>
> Oh, no! I'm not that presumptuous (or naive)! But what do you mean by
> "improve means of coping"? Do you know any article on the subject you
> could point me?

Hmm. l don't know of any good articles off-hand. But what I'm talking
about is simply developing the skill of reading exceptions, plus a few
simple things like knowing where it's appropriate to catch-and-log;
sometimes, what that means is actually writing some code to (for
example) email you whenever there's an exception, but more likely it
means writing no code at all, and just looking at STDERR of your live
usage. Works really well for >95% of Python scripts.

The most important thing to consider is: What happens if my code
doesn't run all the way through? Is it safe for this to run part way,
then bomb with an exception? For many scripts, it's pretty easy: fix
the problem and rerun the script, and it'll completely rewrite its
output file. For others, this is a good reason for putting all your
"real data" into a transactional database - you begin a transaction at
the top, don't commit till the end, and if an exception kills your
script, your transaction will be rolled back. I have a system for
patching our database based on a script (written in Pike, not Python,
but the same applies); if I have any sort of critical failure in the
patch script, it'll bomb out as soon as I test it - but since I use
PostgreSQL, all that DDL (eg "ALTER TABLE") is covered by
transactional integrity (which it isn't with MySQL - another reason to
be wary of MySQL), so my patch will be backed out, and I can fix it
and start over. I don't need to have a Look Before You Leap approach
to database changes - I can simply do stuff, and if it crashes, all's
well. (That same script also has a system for catching errors at a
mid-level point that means that the process doesn't terminate when
there's an error; it supports full code reload, so once I fix the
patch, I send the process a SIGHUP and it fetches from disk again.)
*That* is error handling the safe way.

ChrisA

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


Thread

Interface and duck typing woes Joe Junior <joe.fbs.junior@gmail.com> - 2013-08-28 18:09 -0300
  Re: Interface and duck typing woes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-28 23:24 +0000
  Re: Interface and duck typing woes Nobody <nobody@nowhere.com> - 2013-08-29 10:41 +0100
    Re: Interface and duck typing woes Joe Junior <joe.fbs.junior@gmail.com> - 2013-08-29 09:40 -0300
      Re: Interface and duck typing woes alex23 <wuwei23@gmail.com> - 2013-08-30 10:14 +1000
      Re: Interface and duck typing woes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-30 02:42 +0000
        Re: Interface and duck typing woes Roy Smith <roy@panix.com> - 2013-08-30 06:35 -0400
          Re: Interface and duck typing woes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-31 00:13 +0000
            Re: Interface and duck typing woes Ned Batchelder <ned@nedbatchelder.com> - 2013-08-30 20:45 -0400
            Re: Interface and duck typing woes Joshua Landau <joshua@landau.ws> - 2013-09-01 00:18 +0100
            Re: Interface and duck typing woes Roy Smith <roy@panix.com> - 2013-08-31 20:52 -0400
    Re: Interface and duck typing woes Chris Angelico <rosuav@gmail.com> - 2013-08-29 23:07 +1000
    Re: Interface and duck typing woes Joe Junior <joe.fbs.junior@gmail.com> - 2013-08-29 11:11 -0300
  Re: Interface and duck typing woes jussi.santti@ard.fi - 2013-08-29 22:37 -0700

csiph-web