Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100035 > unrolled thread
| Started by | Tony van der Hoff <tony@vanderhoff.org> |
|---|---|
| First post | 2015-12-05 12:40 +0000 |
| Last post | 2015-12-07 17:24 -0700 |
| Articles | 7 — 6 participants |
Back to article view | Back to comp.lang.python
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
| From | Tony van der Hoff <tony@vanderhoff.org> |
|---|---|
| Date | 2015-12-05 12:40 +0000 |
| Subject | increment/decrement operators |
| Message-ID | <dcg4apF3gq3U1@mid.individual.net> |
Hi, I'm a relative newbie to python, and this NG, but it's certainly growing on me. One thing I'm missing is the increment/decrement operator from C, ie x++, and its ilk. Likewise x += y. is there any way of doing this in Python? TIA, Tony
[toc] | [next] | [standalone]
| From | Robin Koch <robin.koch@t-online.de> |
|---|---|
| Date | 2015-12-05 13:56 +0100 |
| Message-ID | <n3umug$f0$1@news.albasani.net> |
| In reply to | #100035 |
Am 05.12.2015 um 13:40 schrieb Tony van der Hoff: > Hi, > > I'm a relative newbie to python, and this NG, but it's certainly growing > on me. > > One thing I'm missing is the increment/decrement operator from C, ie > x++, and its ilk. Likewise x += y. > > is there any way of doing this in Python? Quick answer: x += y works. (Well, it should.) x++ doesn't. Long answer: I'm sure someone more experienced will come up with one shortly. :-) Until then I found this: http://stackoverflow.com/a/1485854 -- Robin Koch
[toc] | [prev] | [next] | [standalone]
| From | Tony van der Hoff <tony@vanderhoff.org> |
|---|---|
| Date | 2015-12-05 14:14 +0000 |
| Message-ID | <dcg9qjF4scfU1@mid.individual.net> |
| In reply to | #100036 |
On 05/12/15 12:56, Robin Koch wrote: > Am 05.12.2015 um 13:40 schrieb Tony van der Hoff: >> Hi, >> >> I'm a relative newbie to python, and this NG, but it's certainly growing >> on me. >> >> One thing I'm missing is the increment/decrement operator from C, ie >> x++, and its ilk. Likewise x += y. >> >> is there any way of doing this in Python? > > Quick answer: > > x += y works. (Well, it should.) > > x++ doesn't. > > Long answer: > > I'm sure someone more experienced will come up with one shortly. :-) > > Until then I found this: > http://stackoverflow.com/a/1485854 > Thanks for the link
[toc] | [prev] | [next] | [standalone]
| From | "D'Arcy J.M. Cain" <darcy@VybeNetworks.com> |
|---|---|
| Date | 2015-12-05 09:41 -0500 |
| Message-ID | <mailman.224.1449326482.14615.python-list@python.org> |
| In reply to | #100036 |
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 -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy@Vex.Net VoIP: sip:darcy@VybeNetworks.com
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2015-12-05 10:43 -0500 |
| Message-ID | <mailman.225.1449330245.14615.python-list@python.org> |
| In reply to | #100036 |
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. 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
[toc] | [prev] | [next] | [standalone]
| From | BartC <bc@freeuk.com> |
|---|---|
| Date | 2015-12-05 17:18 +0000 |
| Message-ID | <n3v653$g0g$1@dont-email.me> |
| In reply to | #100040 |
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
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2015-12-07 17:24 -0700 |
| Message-ID | <mailman.42.1449534294.12405.python-list@python.org> |
| In reply to | #100041 |
On Dec 5, 2015 10:21 AM, "BartC" <bc@freeuk.com> wrote: > > > 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 Since x+=1 is not an expression, this is moot. > * 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. Note that x+=1 does not necessarily have to mean stepping by 1 either. You could even do something like x+=5 to mean skip the next four values and step x to the value after that. > 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. I think a better question is if they're only going to be statements, then why bother adding them? x++ doesn't give you anything you can't get from x+=1, so why commit to supporting the extra syntax?
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web