Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed1.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'syntax': 0.03; 'subject:Python': 0.05; 'case.': 0.05; 'context': 0.05; '21,': 0.07; 'objects,': 0.07; 'python': 0.09; 'augmented': 0.09; 'methods,': 0.09; 'mutable': 0.09; 'terry': 0.09; 'trees': 0.09; 'violates': 0.09; 'wrong,': 0.09; 'language': 0.14; 'cases': 0.15; 'dec': 0.15; 'abusing': 0.16; 'clone': 0.16; 'dsl,': 0.16; 'expects': 0.16; 'flag,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'mutate,': 0.16; 'numpy': 0.16; 'reedy': 0.16; 'return,': 0.16; 'sensibility': 0.16; 'surprising': 0.16; 'using,': 0.16; 'wrote:': 0.17; 'certainly': 0.17; 'exists': 0.17; 'thu,': 0.17; 'saying': 0.18; 'versions': 0.20; 'preferred': 0.20; 'assignment': 0.22; 'beauty': 0.22; 'latter': 0.22; 'object.': 0.22; 'defined': 0.22; 'header:In-Reply-To:1': 0.25; 'looks': 0.26; 'candidate': 0.26; 'implemented': 0.27; 'language.': 0.27; 'possibly': 0.27; 'rules': 0.27; 'tree': 0.27; 'message-id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'arrays': 0.29; 'context,': 0.29; "d'aprano": 0.29; 'dom': 0.29; 'enforce': 0.29; 'steven': 0.29; 'array': 0.29; 'class': 0.29; "i'm": 0.29; 'fri,': 0.30; 'sense': 0.31; 'not.': 0.32; 'could': 0.32; 'problem': 0.33; 'anyone': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'apply.': 0.35; 'returning': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'expensive': 0.36; 'visual': 0.36; 'method': 0.36; 'should': 0.36; 'does': 0.37; 'two': 0.37; 'rather': 0.37; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'mean': 0.38; 'some': 0.38; 'things': 0.38; 'to:addr:python.org': 0.39; 'short': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'easy': 0.60; 'most': 0.61; 'is.': 0.62; 'between': 0.63; 'necessarily': 0.63; 'different': 0.63; 'hesitate': 0.66; 'believe': 0.69; 'cut': 0.71; 'obvious': 0.71; 'vital': 0.75; 'confusing': 0.84; 'confusion.': 0.84; 'dsl': 0.84; 'returns.': 0.84; 'horror': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=LyyQ61HGq/pXOjB9cmUwU9SJfc5CDsMI7p9zRxnhA0I=; b=sZ9/QREY8DlZB8ZV8Fvg+AG2l3E18V16wbaFhru/Lt126i/Y78XMLw2r5U0gEYmj52 v6O1Q89by2K/E7Nx7+islscrMpPnxq2AEPidaVr++Dx/atgCrKk4uNAnL1Z7aDAV2fgr b/QJMdnZLi1hXXaBLyyxxSGKWqz8FnpkNo7Bi0k1+dw7VWNhYV0QMfIwvlIgmPkN4xrE zre8Tbf0J4/ZFGkmlMdo5NVTgAy0bLRIrkEYsVj3zbJIM9vMptJHguXa1Gstuddg4ZQ0 zbq4jD/+MZcXZjR56ElG9DZHMs2rc/aY1kCu48IjkZzq02xrl6ytRMf4r/U0sBgbUFn8 wPIw== MIME-Version: 1.0 In-Reply-To: <50d3c3ce$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <9122ba06-bc02-42a3-84a6-568c3fab4598@googlegroups.com> <50d3c3ce$0$29967$c3e8da3$5496439d@news.astraweb.com> Date: Fri, 21 Dec 2012 16:07:40 +1100 Subject: Re: Brython - Python in the browser From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 56 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356066463 news.xs4all.nl 6892 [2001:888:2000:d::a6]:37208 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35267 On Fri, Dec 21, 2012 at 1:05 PM, Steven D'Aprano wrote: > On Thu, 20 Dec 2012 18:59:39 -0500, Terry Reedy wrote: >> What Python does have is 11 versions of the augmented assignment >> statement: +=, -=, *=, /=, //=, %=, **=, >>=, <<=, &=, ^=, |=. Moreover, >> these are *intended* to be implemented in place, by mutation, for >> mutable objects, with possibly class-specific meanings. > > I don't believe that is the case. The problem is that augmented > assignment that mutates can be rather surprising to anyone who expects > "a += b" to be a short cut for "a = a + b". This is confusing only because it violates the principle that exists with methods, that it _either_ mutates _or_ returns. The augmented assignment operators must return, and in some cases also mutate, hence confusion. > One might even have a class where (say) __iadd__ is defined but __add__ > is not. That would be plausible, if it had an easy way to clone an object. This would in fact be my preferred way to do things if the clone operation is expensive - such as in this case. Adding two DOM trees could be prohibitively expensive (if the tree is deep), but parenting a tree to another is cheap. >> <= is a comparison expression operator, which is completely different. > > <= is a comparison operator for ints, floats, strings, lists, ... but not > necessarily for *everything*. That's the beauty and horror of operator > overloading. Any operator can mean anything. > > If it were intended to only return a flag, then 1) Python would enforce > that rule, and 2) the numpy people would be most upset. There's a difference between returning a different data type that makes good sense (compare two arrays and get an array of booleans) and abusing an operator for its visual characteristics. The former is a good reason to have the language grant freedom; the latter is proof that freedom can be used in many ways. I'm not saying it's always wrong, but it certainly isn't right as often as the other is. > I have no opinion on the usefulness or sensibility of using <= as an in- > place mutator method in this context, but I will say that if I were > designing my own mini-DSL, I would not hesitate to give "comparison > operators" some other meaning. Syntax should be judged in the context of > the language you are using, not some other language. If you are using a > DSL, then normal Python rules don't necessarily apply. <= in particular > looks just like a left-pointing arrow and is an obvious candidate for > overloading. But there's no corresponding => arrow! How can you make your DSL look like PHP arrays without that vital array creation operator? ChrisA