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


Groups > comp.lang.python > #80589

Re: I love assert

Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'operator': 0.03; 'explicitly': 0.05; 'debug': 0.07; 'pep': 0.09; 'worse': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '2.7': 0.14; 'be:': 0.16; 'finney': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ternary': 0.16; 'too?': 0.16; 'language': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'code,': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'keyerror:': 0.31; 'python"': 0.31; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'consistent': 0.36; 'opposed': 0.36; 'should': 0.36; 'example,': 0.37; 'ben': 0.38; 'nov': 0.38; 'version,': 0.38; 'pm,': 0.38; 'track': 0.38; 'rather': 0.38; '12,': 0.39; 'read': 0.60; 'expression': 0.60; 'first': 0.61; 'happen': 0.63; 'more': 0.64; 'importantly,': 0.68; 'stated': 0.69; 'present.': 0.74; 'trick,': 0.84; 'to:none': 0.92
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:cc :content-type; bh=wuErvj9N15bUYTVjP2213Rjm5nEkSoZaI/SA2HAYiIM=; b=oAg/kt19qOpmKcX3SxM19K0Ts8kXpV1/4xuuF2uBafrunB6izbVdNUmasOuUoNmRSV IWN8X7dK14NVr8ENTM58H0ooD5eayROO7cfnpm+RZ3seqJajvg605i4lmWnTRfG5fgef jnVOPlH8emrn+U+QYbgvIJRRhHEzdJiOMUnuOLqGvgqL4tBUcC/XG65BLDOZCfVOX4pn PMtlOh6vQHof+rbzrkJoEbLX/+EL66oB73r+pGbTR3q4q5YW40bg3knMN5xkCDYt515O oc7i/rlXClpzZaK3dqvNIuKhDK8xML4t96fcd4cEXZwGrl+SNQK0uYTix/Oxlvso0tTE hTsw==
MIME-Version 1.0
X-Received by 10.50.61.209 with SMTP id s17mr37073273igr.34.1415760250855; Tue, 11 Nov 2014 18:44:10 -0800 (PST)
In-Reply-To <85lhnh5enq.fsf@benfinney.id.au>
References <96c138e4-ab95-4e5f-a0c8-e696b5a926bb@googlegroups.com> <85389pcxn5.fsf@benfinney.id.au> <CAPTjJmoWqRC2EfGtV=-q97XGpXkd=PygZisfTthynr1E860uuw@mail.gmail.com> <85lhnh5enq.fsf@benfinney.id.au>
Date Wed, 12 Nov 2014 13:44:10 +1100
Subject Re: I love assert
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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 <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>
Newsgroups comp.lang.python
Message-ID <mailman.15712.1415760259.18130.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1415760259 news.xs4all.nl 2912 [2001:888:2000:d::a6]:43804
X-Complaints-To abuse@xs4all.nl
Path csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Xref csiph.com comp.lang.python:80589

Show key headers only | View raw


On Wed, Nov 12, 2014 at 1:35 PM, Ben Finney <ben+python@benfinney.id.au> wrote:
> The more things people need to keep in mind when reading my code that
> isn't stated explicitly in the code, the worse I consider the code to
> be.

Then the ternary if/else operator should also be abolished.

track["APIC:"].data if "APIC:" in track else None

(With PEP 463, this would be:
track["APIC:"].data except KeyError: None
But this is from Python 2.7 code, so that was never going to happen anyway.)

When you read the if/else version, you need to remember that it's
evaluated middle-to-outside rather than outside-to-inside, and more
importantly, that the first expression won't be evaluated at all if
the key isn't present. So should we treat if/else as a "clever but
obfuscatory trick, opposed to that property of Python" too? Or should
people just get to know the language they're using? At least with
'assert', it's consistent across all Python programs; with my DEBUG
example, it's per-project, as it's custom crafted.

ChrisA

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


Thread

I love assert Peter Cacioppi <peter.cacioppi@gmail.com> - 2014-11-11 11:40 -0800
  Re: I love assert Ben Finney <ben+python@benfinney.id.au> - 2014-11-12 07:03 +1100
    Re: I love assert Grant Edwards <invalid@invalid.invalid> - 2014-11-11 21:43 +0000
  Re: I love assert Ethan Furman <ethan@stoneleaf.us> - 2014-11-11 12:08 -0800
  Re: I love assert Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-11-11 12:20 -0800
  Re: I love assert Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-11 20:34 +0000
  Re: I love assert TP <wingusr@gmail.com> - 2014-11-11 12:57 -0800
  Re: I love assert Terry Reedy <tjreedy@udel.edu> - 2014-11-11 17:34 -0500
  Re: I love assert Ben Finney <ben+python@benfinney.id.au> - 2014-11-12 09:52 +1100
  Re: I love assert Tim Chase <python.list@tim.thechases.com> - 2014-11-11 17:03 -0600
  Re: I love assert Peter Cacioppi <peter.cacioppi@gmail.com> - 2014-11-11 15:02 -0800
  Re: I love assert Ethan Furman <ethan@stoneleaf.us> - 2014-11-11 15:38 -0800
  Re: I love assert Dan Stromberg <drsalists@gmail.com> - 2014-11-11 17:56 -0800
  Re: I love assert Chris Angelico <rosuav@gmail.com> - 2014-11-12 13:21 +1100
  Re: I love assert Ben Finney <ben+python@benfinney.id.au> - 2014-11-12 13:35 +1100
    Re: I love assert Grant Edwards <invalid@invalid.invalid> - 2014-11-12 14:10 +0000
  Re: I love assert Chris Angelico <rosuav@gmail.com> - 2014-11-12 13:44 +1100
    Re: I love assert wxjmfauth@gmail.com - 2014-11-11 23:14 -0800
  Re: I love assert Terry Reedy <tjreedy@udel.edu> - 2014-11-12 03:29 -0500
  Re: I love assert Anton <anton.schattenfeld@gmail.com> - 2014-11-12 12:53 -0800
    Re: I love assert Marko Rauhamaa <marko@pacujo.net> - 2014-11-12 23:41 +0200
      Re: I love assert Ethan Furman <ethan@stoneleaf.us> - 2014-11-12 13:52 -0800
        Re: I love assert Marko Rauhamaa <marko@pacujo.net> - 2014-11-12 23:56 +0200
          Re: I love assert Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-12 15:04 -0700
            Re: I love assert Anton <anschatten@gmail.com> - 2014-11-12 14:13 -0800
              Re: I love assert Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-12 15:41 -0700
                Re: I love assert Anton <anschatten@gmail.com> - 2014-11-12 14:48 -0800
                Re: I love assert Marko Rauhamaa <marko@pacujo.net> - 2014-11-13 01:01 +0200
                Re: I love assert Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-15 10:40 +1100
                Re: I love assert Marko Rauhamaa <marko@pacujo.net> - 2014-11-15 02:12 +0200
                Re: I love assert Chris Angelico <rosuav@gmail.com> - 2014-11-15 12:04 +1100
                Re: I love assert Marko Rauhamaa <marko@pacujo.net> - 2014-11-15 03:30 +0200
                Re: I love assert Chris Angelico <rosuav@gmail.com> - 2014-11-15 12:48 +1100
                Re: I love assert Tim Chase <python.list@tim.thechases.com> - 2014-11-14 20:14 -0600
                Re: I love assert Chris Angelico <rosuav@gmail.com> - 2014-11-15 13:16 +1100
                Re: I love assert albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-11-29 17:35 +0000
                Re: I love assert Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-12 16:02 -0700
                Re: I love assert Anton <anschatten@gmail.com> - 2014-11-12 15:43 -0800
                Re: I love assert Chris Angelico <rosuav@gmail.com> - 2014-11-13 10:10 +1100
                Re: I love assert Marko Rauhamaa <marko@pacujo.net> - 2014-11-13 01:23 +0200
                Re: I love assert Chris Angelico <rosuav@gmail.com> - 2014-11-13 10:27 +1100
                Re: I love assert Marko Rauhamaa <marko@pacujo.net> - 2014-11-13 01:31 +0200
              Re: I love assert Ethan Furman <ethan@stoneleaf.us> - 2014-11-12 14:47 -0800
                Re: I love assert Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-14 22:37 +1100
                Re: I love assert Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-14 09:40 -0700
          Re: I love assert Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-12 15:07 -0700
            Re: I love assert Marko Rauhamaa <marko@pacujo.net> - 2014-11-13 00:47 +0200
              Re: I love assert Ethan Furman <ethan@stoneleaf.us> - 2014-11-12 14:56 -0800
              Re: I love assert Chris Angelico <rosuav@gmail.com> - 2014-11-13 09:58 +1100
              Re: I love assert Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-12 16:05 -0700
                Re: I love assert Marko Rauhamaa <marko@pacujo.net> - 2014-11-13 01:12 +0200
              Re: I love assert Lie Ryan <lie.1296@gmail.com> - 2014-11-14 01:09 +1100
        Re: I love assert Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-14 22:33 +1100
          Re: I love assert Ethan Furman <ethan@stoneleaf.us> - 2014-11-14 10:18 -0800
            Re: I love assert Marko Rauhamaa <marko@pacujo.net> - 2014-11-14 21:12 +0200
              Re: I love assert Ethan Furman <ethan@stoneleaf.us> - 2014-11-14 12:41 -0800
                Re: I love assert Marko Rauhamaa <marko@pacujo.net> - 2014-11-14 22:50 +0200
            Re: I love assert Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-15 13:58 +1100
              Re: I love assert Ethan Furman <ethan@stoneleaf.us> - 2014-11-14 20:09 -0800
                Re: I love assert Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-17 13:09 +1100
                Re: I love assert Ethan Furman <ethan@stoneleaf.us> - 2014-11-16 19:25 -0800
      Re: I love assert Anton <anschatten@gmail.com> - 2014-11-12 14:00 -0800
        Re: I love assert Anton <anschatten@gmail.com> - 2014-11-12 14:04 -0800
          Re: I love assert Marko Rauhamaa <marko@pacujo.net> - 2014-11-13 00:34 +0200
    Re: I love assert Chris Angelico <rosuav@gmail.com> - 2014-11-13 09:43 +1100
  Re: I love assert Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-14 22:15 +1100
  Re: I love assert Richard Riehle <rriehle@itu.edu> - 2014-11-14 14:09 -0800
    Decorators (was: Re: I love assert) Marko Rauhamaa <marko@pacujo.net> - 2014-11-15 00:18 +0200
      Re: Decorators Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-14 22:37 +0000
        Re: Decorators Marko Rauhamaa <marko@pacujo.net> - 2014-11-15 00:47 +0200
      Re: Decorators (was: Re: I love assert) Richard Riehle <rriehle@itu.edu> - 2014-11-14 18:19 -0800
        Re: Decorators (was: Re: I love assert) Mayank Tripathi <oquanox@gmail.com> - 2014-11-15 02:36 +0000
        Re: Decorators (was: Re: I love assert) Tim Chase <python.list@tim.thechases.com> - 2014-11-14 20:30 -0600
          Re: Decorators Marko Rauhamaa <marko@pacujo.net> - 2014-11-15 09:00 +0200
            Re: Decorators Grant Edwards <invalid@invalid.invalid> - 2014-11-15 15:32 +0000
        Re: Decorators (was: Re: I love assert) Richard Riehle <rriehle@itu.edu> - 2014-11-14 23:42 -0800
        Re: Decorators Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-15 13:12 +0000
          Re: Decorators Marko Rauhamaa <marko@pacujo.net> - 2014-11-15 15:24 +0200
            Re: Decorators Terry Reedy <tjreedy@udel.edu> - 2014-11-15 15:28 -0500
        Re: Decorators (was: Re: I love assert) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-16 02:39 +1100
  Re: I love assert TP <wingusr@gmail.com> - 2014-11-27 01:22 -0800
    Re: I love assert alister <alister.nospam.ware@ntlworld.com> - 2014-11-27 09:59 +0000
      Re: I love assert Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-29 12:30 +1100
        Re: I love assert MRAB <python@mrabarnett.plus.com> - 2014-11-29 02:56 +0000
          Re: I love assert Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-29 20:31 +1100
            Re: I love assert Chris Angelico <rosuav@gmail.com> - 2014-11-29 21:40 +1100
            Re: I love assert MRAB <python@mrabarnett.plus.com> - 2014-11-29 19:49 +0000
        Re: I love assert Chris Angelico <rosuav@gmail.com> - 2014-11-29 14:02 +1100
        Re: I love assert Ethan Furman <ethan@stoneleaf.us> - 2014-11-29 14:33 -0800
          Re: I love assert Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-30 19:18 +1100
            Re: I love assert Ethan Furman <ethan@stoneleaf.us> - 2014-11-30 11:34 -0800

csiph-web