Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed4.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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'essentially': 0.04; 'suppose': 0.07; 'len(x)': 0.09; 'objects)': 0.09; 'operator,': 0.09; 'runtime': 0.09; 'subject:Function': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; 'contexts,': 0.16; 'len(data)': 0.16; 'lisp': 0.16; 'namespace,': 0.16; 'think?': 0.16; 'types,': 0.16; 'usage,': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'memory': 0.22; 'cc:addr:python.org': 0.22; 'paul': 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'handling': 0.26; 'specially': 0.26; 'defined': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'url:mailman': 0.30; 'bunch': 0.31; 'extending': 0.31; 'idea,': 0.31; 'operators': 0.31; 'languages': 0.32; 'stuff': 0.32; 'url:python': 0.33; 'implemented': 0.33; 'plain': 0.33; 'core': 0.34; 'could': 0.34; 'subject: (': 0.35; 'classes': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'like,': 0.36; 'url:listinfo': 0.36; 'charset:us- ascii': 0.36; 'url:org': 0.36; 'should': 0.36; 'so,': 0.37; 'expected': 0.38; 'generic': 0.38; 'fact': 0.38; 'rather': 0.38; 'either': 0.39; 'url:mail': 0.40; 'how': 0.40; 'even': 0.60; 'consists': 0.60; 'cost.': 0.60; 'then,': 0.60; 'most': 0.60; 'email addr:gmail.com': 0.63; 'name': 0.63; 'high': 0.63; 'different': 0.65; 'side': 0.67; 'between': 0.67; 'fact,': 0.69; 'co.': 0.74; 'obvious': 0.74; 'intends': 0.84; '"how': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=b8R+SexVJt6W1PcA9EGrtebdA3aeR2rDzYdW3vESYAU=; b=TUSf4TvW07WDRJDaFJrPWcQqTuV/GJutuYfj7QNbaWKukspY5x2vXjD91uaGix9rIu 7s3xVRamm4SxobKWqoH53iKt9SgKMRT4EMrLHD8Lc5sTaDbM/IxOvcULqof0tJnyGqfR TjGQI6D0zrx6rGJsQUWcthKQguU+/3nlHMeDlzo8YP1LpiZoUfYFX0/MwDy8PJyLr6ct px6c5eE8M0Okr70uHxVGdqoDPMctMK5vaPrfU5I1MXATbr1xGzTaNtT/WxmtpyLt0V1H eikK2GJ2wyGwajY9TtixoS5WA47/m6hUASz0A23R7cVSrn20ZdcgDniPWNNQZuAM8oO2 5UNg== X-Received: by 10.14.4.199 with SMTP id 47mr2694099eej.9.1402245613373; Sun, 08 Jun 2014 09:40:13 -0700 (PDT) Date: Sun, 8 Jun 2014 19:40:09 +0300 From: Paul Sokolovsky To: Marko Rauhamaa Subject: Re: Uniform Function Call Syntax (UFCS) 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> X-Mailer: Claws Mail 3.10.0 (GTK+ 2.24.10; i686-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: python-list@python.org 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: 73 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1402245958 news.xs4all.nl 2917 [2001:888:2000:d::a6]:38492 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72973 Hello, On Sun, 08 Jun 2014 18:56:47 +0300 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__() > > etc. > > I suppose the principal reason is that people don't like UFCS. Plus > some legacy from Python1 days. I personally don't see it as "duality". There're few generic operators - the fact that they are really generic (apply to wide different classes of objects) is exactly the reason why the're defined in global namespace, and not methods. And yep, I see things like "len" as essentially an operator, even though its name consists of letters, and it has function call syntax. Then, there's just a way to overload these operators for user types, that's it. You *can* use x.__len__() but that's not how Python intends it. And like with any idea, one should not forget implementation side and efficiency - these operators are really core and expected to be used in performance-tight contexts, so they are implemented specially (optimized). Extending that handling to any function would cost either high memory usage, or high runtime cost. > Lisp & co. rigorously follow its UFCS. I think it works great, but > that is what people most ridicule Lisp for. Exactly my thinking - there're bunch of languages which follow that UFCS-like idea, likely most homoiconic (or -like) do. Or you can use plain old C ;-). So, I don't see why people want to stuff this into Python - there're lot of ready alternatives. And Python provides very intuitive and obvious separation between generic functions and object methods IMHO, so there's nothing to "fix". > > What do you think? Would you rather write/read: > > if size + len(data) >= limit: "How else could it be?" > > or UFCS-ly: > > if size.__add__(data.__len__()).__le__(limit): "OMG!" > Marko > -- > https://mail.python.org/mailman/listinfo/python-list -- Best regards, Paul mailto:pmiscml@gmail.com