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


Groups > comp.lang.python > #100041

Re: increment/decrement operators

From BartC <bc@freeuk.com>
Newsgroups comp.lang.python
Subject Re: increment/decrement operators
Date 2015-12-05 17:18 +0000
Organization A noiseless patient Spider
Message-ID <n3v653$g0g$1@dont-email.me> (permalink)
References <dcg4apF3gq3U1@mid.individual.net> <n3umug$f0$1@news.albasani.net> <20151205094115.01751274@imp> <mailman.225.1449330245.14615.python-list@python.org>

Show all headers | View raw


On 05/12/2015 15:43, Terry Reedy wrote:
> On 12/5/2015 9:41 AM, D'Arcy J.M. Cain wrote:
>> On Sat, 5 Dec 2015 13:56:47 +0100
>> Robin Koch <robin.koch@t-online.de> 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.

The latter is not the same. Some of the differences are:

* ++ and -- are often inside inside expressions and return values 
(unlike x+=1 in Python)

* x++ and x-- return the /current/ value of x, unlike x+=1 even if it 
were to return a value; it would be the new value

* x+=1 requires you to hard-code the value 1, but ++ is not necessarily 
stepping by 1. You can imagine ++ stepping something to its next value.

However, if ++ and -- are only used as statements, then why not simply 
map them to x+=1? In Python, that would need to be x++ and x-- as ++x or 
--x have existing meanings.

-- 
Bartc

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


Thread

increment/decrement operators Tony van der Hoff <tony@vanderhoff.org> - 2015-12-05 12:40 +0000
  Re: increment/decrement operators Robin Koch <robin.koch@t-online.de> - 2015-12-05 13:56 +0100
    Re: increment/decrement operators Tony van der Hoff <tony@vanderhoff.org> - 2015-12-05 14:14 +0000
    Re: increment/decrement operators "D'Arcy J.M. Cain" <darcy@VybeNetworks.com> - 2015-12-05 09:41 -0500
    Re: increment/decrement operators Terry Reedy <tjreedy@udel.edu> - 2015-12-05 10:43 -0500
      Re: increment/decrement operators BartC <bc@freeuk.com> - 2015-12-05 17:18 +0000
        Re: increment/decrement operators Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-07 17:24 -0700

csiph-web