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


Groups > comp.lang.python > #38148

Re: LBYL vs EAFP

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!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.015
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'case.': 0.05; 'failure.': 0.09; 'given,': 0.09; 'programmer': 0.11; "wouldn't": 0.11; 'library': 0.15; 'cases': 0.15; 'between.': 0.16; 'efficiency.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'inputs': 0.16; 'trace.': 0.16; 'wrote:': 0.17; 'examples': 0.18; 'feb': 0.19; 'all,': 0.21; 'earlier': 0.21; 'assuming': 0.22; "i'd": 0.22; 'programming': 0.23; 'seems': 0.23; 'idea': 0.24; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'checking': 0.27; 'thoughts': 0.27; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'lines': 0.28; "d'aprano": 0.29; 'secondly': 0.29; 'steven': 0.29; "i'm": 0.29; 'error': 0.30; 'code': 0.31; 'could': 0.32; 'zero': 0.33; 'to:addr:python-list': 0.33; 'point.': 0.33; 'received:google.com': 0.34; 'wrong': 0.34; 'third': 0.34; 'along': 0.35; 'fail': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.36; 'depends': 0.36; 'itself': 0.37; 'option': 0.37; 'two': 0.37; 'being': 0.37; 'rather': 0.37; 'received:209': 0.37; 'received:209.85.216': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'comment': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'help': 0.40; 'your': 0.60; 'situation': 0.62; 'middle': 0.66; 'user,': 0.69; 'obvious': 0.71; 'opinions': 0.72; '2013': 0.84; 'blow': 0.84; 'that),': 0.91; 'anywhere,': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=vp2rZEzX2ikUPZ+ZT3UlJj2VEAni/Nf/WH7Yywg3pwM=; b=i4nK4lWuf8vUrksRIPQXROlh9itje932vhJE9iKN5YTIxeYDU6QH4jsLHAg3ItRpsF RohBftVF3+DfQuAyUhfFac30HBFkwX5edZfZ1KVn7PJ32Y47jCwWeJBPYw3rSgTZBTNy 9laVGRE5vDV1Ps9WhQ4Aj4AKPucY1uw8VYkVaTsrP8lw5wMS1+cRTTEWx6goDewUEQ8q nuUEfnOloSb2RJI+XfKTjwxg9G942wImB1X5GZoIMz2P163eI6ZteKWw9DswcGObOhB9 ke/PtL7zI5nciElo7o7j6YgeYzHtLWTrGcjB4EwD1pBW931qsB2e1qEDxgRbLRc5z2Z4 RFBg==
MIME-Version 1.0
X-Received by 10.224.18.205 with SMTP id x13mr14488127qaa.9.1360021121417; Mon, 04 Feb 2013 15:38:41 -0800 (PST)
In-Reply-To <5110415c$0$29986$c3e8da3$5496439d@news.astraweb.com>
References <5110415c$0$29986$c3e8da3$5496439d@news.astraweb.com>
Date Tue, 5 Feb 2013 10:38:41 +1100
Subject Re: LBYL vs EAFP
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.1338.1360021130.2939.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360021130 news.xs4all.nl 6893 [2001:888:2000:d::a6]:55734
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38148

Show key headers only | View raw


On Tue, Feb 5, 2013 at 10:16 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> A third option is not to check x at all, and hope that it will blow up at
> some arbitrary place in the middle of my code rather than silently do the
> wrong thing. I don't like this idea because, even if it fails, it is better
> to fail earlier than later.
>
> Comments, thoughts and opinions please.

It depends on what could cause the failure. If only a programming
error could cause x to not be a number, I'd go with your third option
- let it blow up anywhere, and follow the trace. That option requires
zero forethought, which translates directly into programmer
efficiency. But if x came from a user,  then I'd be checking inputs at
a much earlier point.

Those are the two obvious cases though, and I'm assuming your
situation is neither of them. Writing library code is half way in
between. With the specific examples given, I wouldn't like to use "x +
0" as a check; it seems dodgy. Firstly because it doesn't look like a
data type check (though a comment can help with that), and secondly
because something might very well support having a number added to it
while definitely not itself being a number - eg something along the
lines of a database cursor. So I would recommend LBYL for this
particular case.

ChrisA

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


Thread

LBYL vs EAFP Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-05 10:16 +1100
  Re: LBYL vs EAFP Chris Angelico <rosuav@gmail.com> - 2013-02-05 10:38 +1100
    Re: LBYL vs EAFP Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-05 03:52 +0000
      Re: LBYL vs EAFP Chris Angelico <rosuav@gmail.com> - 2013-02-05 16:19 +1100
  Re: LBYL vs EAFP Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-04 16:46 -0700
    Re: LBYL vs EAFP Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-05 04:52 +0000
      Re: LBYL vs EAFP Chris Angelico <rosuav@gmail.com> - 2013-02-05 16:20 +1100
        Re: LBYL vs EAFP Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-05 06:31 +0000
          Re: LBYL vs EAFP Pete Forman <petef4+usenet@gmail.com> - 2013-02-05 09:49 +0000
            Re: LBYL vs EAFP Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-05 23:04 +1100
              Re: LBYL vs EAFP Chris Angelico <rosuav@gmail.com> - 2013-02-05 23:25 +1100
      Re: LBYL vs EAFP Ian Kelly <ian.g.kelly@gmail.com> - 2013-02-04 22:40 -0700
  Re: LBYL vs EAFP Dave Angel <davea@davea.name> - 2013-02-04 18:55 -0500
  Re: LBYL vs EAFP Chris Angelico <rosuav@gmail.com> - 2013-02-05 11:45 +1100
  Re: LBYL vs EAFP Ethan Furman <ethan@stoneleaf.us> - 2013-02-04 16:26 -0800
  Re: LBYL vs EAFP Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-05 01:00 +0000
  Re: LBYL vs EAFP Terry Reedy <tjreedy@udel.edu> - 2013-02-05 02:53 -0500

csiph-web