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


Groups > comp.lang.python > #110053

Re: Method Chaining

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: Method Chaining
Date Fri, 17 Jun 2016 13:34:33 +0000
Lines 31
Message-ID <mailman.102.1466170491.2288.python-list@python.org> (permalink)
References <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <CAGgTfkPETwxb8kx1PcR+F5qVEm-pkxHFDE4=aw+WNE2itsM3+w@mail.gmail.com> <mailman.99.1466137450.2288.python-list@python.org> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <ed84c81e-a905-48d9-96ca-58aa5f419e68@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> <CAGgTfkOUK_cEYULxa9emH_3FECvPCc8M8wi-ZiQURwLSHsdXhg@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de kOHb8RJVWG8tMTwbCYPedgZ+BGG6WKIGMoHhWtNmbxBw==
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.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'modified': 0.05; 'none,': 0.05; '[0]': 0.07; 'chunk': 0.07; 'behave': 0.09; 'none.': 0.09; 'way:': 0.09; 'itself.': 0.11; 'explicitly': 0.15; '2016': 0.16; 'chained': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'to:addr:pearwood.info': 0.16; "to:name:steven d'aprano": 0.16; 'wrote:': 0.16; 'library': 0.20; 'to:2**1': 0.21; 'libraries': 0.22; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'looks': 0.29; 'consistency': 0.29; 'indentation': 0.29; 'code': 0.30; "i'd": 0.31; 'operate': 0.32; "d'aprano": 0.33; 'steven': 0.33; 'similar': 0.33; 'case,': 0.34; 'skip:& 20': 0.35; 'received:google.com': 0.35; 'returning': 0.35; "isn't": 0.35; 'but': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'expect': 0.37; 'method': 0.37; 'version': 0.38; 'received:209': 0.38; 'or,': 0.38; 'to:addr:python.org': 0.40; 'where': 0.40; 'mark': 0.40; 'your': 0.60; 'matter': 0.63; 'more': 0.63; 'better.': 0.66; "they're": 0.66; 'yours': 0.89; 'hand,': 0.97
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=XR0kskFTsZW7nuO6wHnAEAza4S3ISOUcML2kfOP0zqw=; b=qwhfF/lfqdHEgxhrTaxNOstdjLgqiOg31jzNMXLR1liLBNokyz9VhZqw1mrPoxPF0T sxvLSVcjRh3+5iHh9sTQQWIxTs6dWjzYCh7fU0NB4U+p8xJWm+aX56sPhofqnJMbHNvc 8CuCXTVbg5QuSDWX6ZQ/HxugdOvoHGKl0sEJyRxob6ZeBZYZB0SAMCS1Uve4L3qR/mE3 dBx6QpNaoh5Sc0ozoKk9wKog1kV8GwQAsM5DQ5K7UmoK1XuFjcw6LfqCBk1aQ6y8QFFx AU25rMklJDSWenBAHfyo7kLJ7ImHLlEXHODP2BFAo81OVCtMx8a456YQP86epProRcdL EA/g==
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=XR0kskFTsZW7nuO6wHnAEAza4S3ISOUcML2kfOP0zqw=; b=DE+WpjjtHI5NWjDdtQJNklRVSa0JEUpzPjLShG8gVdsjyjDd4TAwdGq1my4+qOkW9q t5NtnQ2f7TOeYnnXNcdCqWAbI7mS3pyzZ5F/uAWh0WaqImTYt4iiNyIYW9s7lWcCgTmy o49QB9PoOm+ugTm/n/Uzx8CuoAZVRp3m9rREVcpDxUD9sqv4tF0hJtdHeBQvN0NZQ11a yGpXFbMko1jSQeFWguXk5D3bFxlgbUt4hSxv6RZbGD9S4iW5FLfpc0A5z+gL7qgKoX7m XkoIFDEcr5B6EBqwA3pI2MvUuRcXRNQBY1edx201jefhbiqBaoL/OE96vzgrhLQ+yXBJ NZlg==
X-Gm-Message-State ALyK8tKF2EyqI/ME398vdDZOMI9FNJbDiqC6l3FHgUs8NlV4tu7ECivktm3zFOxlW4GvvvCzMe20uMiG6tibCA==
X-Received by 10.140.41.164 with SMTP id z33mr2197160qgz.54.1466170483582; Fri, 17 Jun 2016 06:34:43 -0700 (PDT)
In-Reply-To <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.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 <CAGgTfkOUK_cEYULxa9emH_3FECvPCc8M8wi-ZiQURwLSHsdXhg@mail.gmail.com>
X-Mailman-Original-References <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <CAGgTfkPETwxb8kx1PcR+F5qVEm-pkxHFDE4=aw+WNE2itsM3+w@mail.gmail.com> <mailman.99.1466137450.2288.python-list@python.org> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <ed84c81e-a905-48d9-96ca-58aa5f419e68@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com>
Xref csiph.com comp.lang.python:110053

Show key headers only | View raw


On Fri, Jun 17, 2016 at 5:31 AM Steven D'Aprano <steve@pearwood.info> wrote:

> (g.move_to((p1 + p2a) / 2)
>   .line_to(p1 + (p2 - p1) * frac)
>   .line_to((p1 + p1a) / 2)
>   .stroke()
>   )
>
> the parens and indentation more clearly mark this chunk of code as a
> unit.


I prefer reserving indentation for where they're required ("for", "while",
"if", etc.). In this case, I'd use an extra blank line before and after.
Or, better, I'd move the chunk of code into a function by itself.

On the other hand, I like the fact that methods which are
> conceptually procedures that operate by side-effect return None.
>

Exactly. The chained version looks like each method is returning a modified
copy. The Pandas library isn't perfect, but it has a good consistency for
methods returning copies unless explicitly "inplace=True", in which case
the method returns None.

Paraphrasing Jakob's law of user experience [0], it doesn't matter if your
design is better. People are more familiar with the design of other
libraries and will expect yours to behave the same way: impure methods
return None, unless named "pop" or a similar standard.

[0] https://www.nngroup.com/articles/end-of-web-design/

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


Thread

Method Chaining Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-16 19:02 -0700
  Re: Method Chaining Steven D'Aprano <steve@pearwood.info> - 2016-06-17 12:39 +1000
  Re: Method Chaining Michael Selik <michael.selik@gmail.com> - 2016-06-17 04:23 +0000
    Re: Method Chaining Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-16 21:37 -0700
      Re: Method Chaining Ned Batchelder <ned@nedbatchelder.com> - 2016-06-17 01:13 -0700
        Re: Method Chaining Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-17 01:38 -0700
          Re: Method Chaining Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-06-17 11:45 +0300
        Re: Method Chaining Steven D'Aprano <steve@pearwood.info> - 2016-06-17 19:28 +1000
          Re: Method Chaining Michael Selik <michael.selik@gmail.com> - 2016-06-17 13:34 +0000
            Re: Method Chaining Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-17 15:26 -0700
              Re: Method Chaining Michael Selik <michael.selik@gmail.com> - 2016-06-17 22:45 +0000
              Re: Method Chaining Michael Selik <michael.selik@gmail.com> - 2016-06-17 23:10 +0000
          Re: Method Chaining Rustom Mody <rustompmody@gmail.com> - 2016-06-17 09:48 -0700
            Re: Method Chaining Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-17 15:25 -0700
            Re: Method Chaining Pete Forman <petef4+usenet@gmail.com> - 2016-06-18 13:04 +0100
              Re: Method Chaining Joonas Liik <liik.joonas@gmail.com> - 2016-06-18 17:05 +0300
                Re: Method Chaining Pete Forman <petef4+usenet@gmail.com> - 2016-06-18 16:42 +0100
              Re: Method Chaining Rustom Mody <rustompmody@gmail.com> - 2016-06-18 08:35 -0700
                Re: Method Chaining Pete Forman <petef4+usenet@gmail.com> - 2016-06-19 11:16 +0100
              Re: Method Chaining Ethan Furman <ethan@stoneleaf.us> - 2016-06-18 13:47 -0700
              Re: Method Chaining Joonas Liik <liik.joonas@gmail.com> - 2016-06-19 14:56 +0300
              Re: Method Chaining Ethan Furman <ethan@stoneleaf.us> - 2016-06-19 08:01 -0700
              Re: Method Chaining Michael Torrie <torriem@gmail.com> - 2016-06-19 09:14 -0600
              Re: Method Chaining Ethan Furman <ethan@stoneleaf.us> - 2016-06-19 08:56 -0700
                Re: Method Chaining Rustom Mody <rustompmody@gmail.com> - 2016-06-19 09:03 -0700
        Re: Method Chaining Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-17 15:22 -0700
          Re: Method Chaining Ned Batchelder <ned@nedbatchelder.com> - 2016-06-17 17:02 -0700

csiph-web