Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '(at': 0.04; 'interfaces': 0.04; 'consistency': 0.09; 'len(x)': 0.09; 'subject:Function': 0.09; 'python': 0.11; 'be:': 0.16; "function's": 0.16; 'len(data)': 0.16; 'subclasses.': 0.16; 'think?': 0.16; 'wrote:': 0.18; 'passing': 0.19; 'paul': 0.24; 'pass': 0.26; 'least': 0.26; 'defined': 0.27; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'am,': 0.29; 'generally': 0.29; 'message-id:@mail.gmail.com': 0.30; 'easier': 0.31; 'allows': 0.31; 'probably': 0.32; 'interface': 0.32; 'programmers': 0.33; 'style': 0.33; 'subject: (': 0.35; 'common': 0.35; 'operations': 0.35; 'received:google.com': 0.35; 'like,': 0.36; 'too': 0.37; 'list.': 0.37; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'itself': 0.39; 'to:addr:python.org': 0.39; 'easy': 0.60; 'fact,': 0.69; 'hoping': 0.75; 'around,': 0.84; 'prefers': 0.84; 'proposal.': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=GMvW27ZiL7wydBSYR4+jko/JynkxF+t8ATsIpBbXfnM=; b=IBiyJSfYaVI97MpiG1N4zXpzJ1fXwtiMJCwPuzx6tk8ijXZN6T3g8ZVu20bioaFzXP rT/4Mgcyf7pKPphUEZy4fRZ3l0+cFl3Zf1eDmF6NC5WyWAz+TxrCtUxwlqHjTsaYYEdc FR9riObX07PEs13vG1lWGpmomsUDCis6Rjrp+5bxsNIY46r+DEfac5xWnWYFjJPEO3lT 1B1+zjXOE0hPmb8h3RmVxR8q4qqH7TQ9v8NWbQBLZ1kUgvjQG0YCzse+UmAXrH+VLzCh Df6MTBna1v4JEPAz3ZOmtdip7PTN9hjTqTP/AiP7FlOVRdBG0EYUcCc7b4uPIMBh5vqO KkoA== X-Received: by 10.236.132.139 with SMTP id o11mr2903139yhi.101.1402245563518; Sun, 08 Jun 2014 09:39:23 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <8738ff2y4g.fsf@elektro.pacujo.net> References: <8b96ae27-20fa-4df9-807e-c806fed983c0@googlegroups.com> <38058e64-0113-457c-ae63-cc66e8b569cd@googlegroups.com> <8738ff2y4g.fsf@elektro.pacujo.net> From: Ian Kelly Date: Sun, 8 Jun 2014 10:38:43 -0600 Subject: Re: Uniform Function Call Syntax (UFCS) To: Python 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1402245571 news.xs4all.nl 2949 [2001:888:2000:d::a6]:35546 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72972 On Sun, Jun 8, 2014 at 9:56 AM, Marko Rauhamaa wrote: > Paul Sokolovsky : > >> Python already has that - like, len(x) calls x.__len__() if it's >> defined > > In fact, what's the point of having the duality? > > len(x) <==> x.__len__() > > x < y <==> x.__lt__(y) > > str(x) <==> x.__str__() Python prefers having functions for operations that are common to a lot of types rather than methods. This allows for consistency of interface -- think of len() as the interface and .__len__() as the implementation. If .len() were the interface then it would be easy (and probably all too common) for Python programmers to change those interfaces in subclasses. It also means that if you want to pass the len function itself around, you just pass around len and know that it will work generally -- instead of passing around list.len and hoping that whatever it gets applied to is a list. This is a fair point against UFCS -- if x.len() comes to mean len(x) then it both makes it easy to change that interface (at least for the x.len() spelling) and makes it easier to pass around the function's implementation rather than its interface. > What do you think? Would you rather write/read: > > if size + len(data) >= limit: > > or UFCS-ly: > > if size.__add__(data.__len__()).__le__(limit): You may be misunderstanding the proposal. The UFCS style of that would be: if size + data.len() <= limit: