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


Groups > comp.lang.python > #72973

Re: Uniform Function Call Syntax (UFCS)

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 <pmiscml@gmail.com>
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 <pmiscml@gmail.com>
To Marko Rauhamaa <marko@pacujo.net>
Subject Re: Uniform Function Call Syntax (UFCS)
In-Reply-To <8738ff2y4g.fsf@elektro.pacujo.net>
References <8b96ae27-20fa-4df9-807e-c806fed983c0@googlegroups.com> <mailman.10859.1402169265.18130.python-list@python.org> <bvhsgeF2on9U2@mid.individual.net> <38058e64-0113-457c-ae63-cc66e8b569cd@googlegroups.com> <mailman.10876.1402229177.18130.python-list@python.org> <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 <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.10881.1402245958.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


Hello,

On Sun, 08 Jun 2014 18:56:47 +0300
Marko Rauhamaa <marko@pacujo.net> wrote:

> Paul Sokolovsky <pmiscml@gmail.com>:
> 
> > 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

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


Thread

Uniform Function Call Syntax (UFCS) jongiddy <jongiddy@gmail.com> - 2014-06-06 23:45 -0700
  Re: Uniform Function Call Syntax (UFCS) Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-07 13:20 -0600
    Re: Uniform Function Call Syntax (UFCS) Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-06-08 13:27 +1200
      Re: Uniform Function Call Syntax (UFCS) jongiddy <jongiddy@gmail.com> - 2014-06-08 01:26 -0700
        Re: Uniform Function Call Syntax (UFCS) Paul Sokolovsky <pmiscml@gmail.com> - 2014-06-08 15:06 +0300
          Re: Uniform Function Call Syntax (UFCS) Marko Rauhamaa <marko@pacujo.net> - 2014-06-08 18:56 +0300
            Re: Uniform Function Call Syntax (UFCS) Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-08 10:38 -0600
            Re: Uniform Function Call Syntax (UFCS) Paul Sokolovsky <pmiscml@gmail.com> - 2014-06-08 19:40 +0300
            Re: Uniform Function Call Syntax (UFCS) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-06-09 04:33 +0000
              Re: Uniform Function Call Syntax (UFCS) Marko Rauhamaa <marko@pacujo.net> - 2014-06-09 09:25 +0300
                Re: Uniform Function Call Syntax (UFCS) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-06-09 09:09 +0000
                Re: Uniform Function Call Syntax (UFCS) Chris Angelico <rosuav@gmail.com> - 2014-06-09 19:13 +1000
                Re: Uniform Function Call Syntax (UFCS) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-06-09 13:37 +0000
                Re: Uniform Function Call Syntax (UFCS) Chris Angelico <rosuav@gmail.com> - 2014-06-10 01:08 +1000
          Re: Uniform Function Call Syntax (UFCS) jongiddy <jongiddy@gmail.com> - 2014-06-08 09:24 -0700
            Re: Uniform Function Call Syntax (UFCS) jongiddy <jongiddy@gmail.com> - 2014-06-08 09:34 -0700
            Re: Uniform Function Call Syntax (UFCS) Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-08 10:54 -0600
            Re: Uniform Function Call Syntax (UFCS) Chris Angelico <rosuav@gmail.com> - 2014-06-09 03:10 +1000
              Re: Uniform Function Call Syntax (UFCS) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-06-09 03:20 +0000
                Re: Uniform Function Call Syntax (UFCS) Chris Angelico <rosuav@gmail.com> - 2014-06-09 13:44 +1000
                Re: Uniform Function Call Syntax (UFCS) jongiddy <jongiddy@gmail.com> - 2014-06-08 23:38 -0700
                Re: Uniform Function Call Syntax (UFCS) Roy Smith <roy@panix.com> - 2014-06-08 23:45 -0400
      Re: Uniform Function Call Syntax (UFCS) jongiddy <jongiddy@gmail.com> - 2014-06-08 02:25 -0700
        Re: Uniform Function Call Syntax (UFCS) Roy Smith <roy@panix.com> - 2014-06-08 10:59 -0400
          Re: Uniform Function Call Syntax (UFCS) jongiddy <jongiddy@gmail.com> - 2014-06-08 08:39 -0700
            Re: Uniform Function Call Syntax (UFCS) Chris Angelico <rosuav@gmail.com> - 2014-06-09 02:48 +1000
              Re: Uniform Function Call Syntax (UFCS) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-06-09 03:53 +0000
                Re: Uniform Function Call Syntax (UFCS) Chris Angelico <rosuav@gmail.com> - 2014-06-09 14:53 +1000
                Re: Uniform Function Call Syntax (UFCS) Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-09 08:24 -0600
                Re: Uniform Function Call Syntax (UFCS) jongiddy <jongiddy@gmail.com> - 2014-06-09 23:43 -0700
            Re: Uniform Function Call Syntax (UFCS) Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-08 11:08 -0600
            Re: Uniform Function Call Syntax (UFCS) Chris Angelico <rosuav@gmail.com> - 2014-06-09 03:13 +1000
            Re: Uniform Function Call Syntax (UFCS) Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-08 11:24 -0600
              Re: Uniform Function Call Syntax (UFCS) jongiddy <jongiddy@gmail.com> - 2014-06-08 13:35 -0700
    Re: Uniform Function Call Syntax (UFCS) jongiddy <jongiddy@gmail.com> - 2014-06-08 01:15 -0700
      Re: Uniform Function Call Syntax (UFCS) Paul Sokolovsky <pmiscml@gmail.com> - 2014-06-08 14:52 +0300
      Re: Uniform Function Call Syntax (UFCS) Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-08 11:00 -0600

csiph-web