Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Michael Selik Newsgroups: comp.lang.python Subject: Re: Method Chaining Date: Fri, 17 Jun 2016 13:34:33 +0000 Lines: 31 Message-ID: References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de kOHb8RJVWG8tMTwbCYPedgZ+BGG6WKIGMoHhWtNmbxBw== Return-Path: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <74831a84-7b05-4242-b4c0-4a90d147717b@googlegroups.com> <33f73a24-4dcf-429b-9264-a3f3098f1cc3@googlegroups.com> <5763c2a7$0$1602$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:110053 On Fri, Jun 17, 2016 at 5:31 AM Steven D'Aprano 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/