Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Terry Reedy Newsgroups: comp.lang.python Subject: Re: increment/decrement operators Date: Sat, 5 Dec 2015 10:43:17 -0500 Lines: 70 Message-ID: References: <20151205094115.01751274@imp> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de AYUsmx0Z71FQjHN048LPFwddFlSGnX/eX5/nMVJ52YKA== 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; 'python,': 0.02; 'works.': 0.07; '"if': 0.09; "'''": 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subtle': 0.09; 'types:': 0.09; 'url:github': 0.09; 'jan': 0.11; 'languages,': 0.15; '"def"': 0.16; '(well,': 0.16; 'increment': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'subject:operators': 0.16; 'undesirable': 0.16; 'url:proposals': 0.16; 'wrote:': 0.16; 'integer': 0.18; 'language': 0.19; '2015': 0.20; 'void': 0.22; 'programming': 0.22; 'am,': 0.23; 'code.': 0.23; 'defined': 0.23; '(like': 0.23; 'dec': 0.23; 'sat,': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; '+0100': 0.27; '3.0': 0.27; 'finally,': 0.27; 'does,': 0.29; 'loop,': 0.29; 'operators': 0.29; 'objects': 0.29; 'summary': 0.29; 'subject:/': 0.30; 'code': 0.30; 'minimal': 0.30; 'operations': 0.31; 'language.': 0.32; 'point': 0.33; 'common': 0.33; 'shorter': 0.33; '(for': 0.34; 'add': 0.34; 'could': 0.35; 'fail': 0.35; 'but': 0.36; 'should': 0.36; 'apple': 0.36; 'received:71': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'why': 0.39; "didn't": 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'relatively': 0.63; 'different': 0.63; 'burden': 0.66; 'special': 0.73; 'increase': 0.73; 'complexity': 0.84; 'confusing': 0.84; 'depended': 0.84; 'expressive': 0.84; 'url:master': 0.84; 'received:fios.verizon.net': 0.91; 'swift': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: pool-71-185-227-36.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 In-Reply-To: <20151205094115.01751274@imp> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100040 On 12/5/2015 9:41 AM, D'Arcy J.M. Cain wrote: > On Sat, 5 Dec 2015 13:56:47 +0100 > Robin Koch wrote: >> x += y works. (Well, it should.) > > It does, even on objects other than numbers. > >>>> x = "abc" >>>> y = "def" >>>> x += y >>>> x > 'abcdef' > >> x++ doesn't. > > No but it's just a special case of the above. > >>>> x = 1 >>>> x += 1 >>>> x > 2 Apple is removing the ++ and -- pre- and post- increment and decrement operators from Swift 3.0 as redundant with += 1. https://github.com/apple/swift-evolution/blob/master/proposals/0004-remove-pre-post-inc-decrement.md The following section is a good summary of why they were never added to Python, and should not be. ''' Disadvantages of These Operators 1. These operators increase the burden to learn Swift as a first programming language - or any other case where you don't already know these operators from a different language. 2. Their expressive advantage is minimal - x++ is not much shorter than x += 1. 3. Swift already deviates from C in that the =, += and other assignment-like operations returns Void (for a number of reasons). These operators are inconsistent with that model. 4. Swift has powerful features that eliminate many of the common reasons you'd use ++i in a C-style for loop in other languages, so these are relatively infrequently used in well-written Swift code. These features include the for-in loop, ranges, enumerate, map, etc. 5. Code that actually uses the result value of these operators is often confusing and subtle to a reader/maintainer of code. They encourage "overly tricky" code which may be cute, but difficult to understand. 6. While Swift has well defined order of evaluation, any code that depended on it (like foo(++a, a++)) would be undesirable even if it was well-defined. 7. These operators are applicable to relatively few types: integer and floating point scalars, and iterator-like concepts. They do not apply to complex numbers, matrices, etc. 8. Having to support these could add complexity to the potential revised numerics model. Finally, these fail the metric of "if we didn't already have these, would we add them to Swift 3?" ''' -- Terry Jan Reedy