Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: increment/decrement operators Date: Mon, 7 Dec 2015 17:24:44 -0700 Lines: 34 Message-ID: References: <20151205094115.01751274@imp> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de NmshbBQkU0Vff2C+JBCzXQvWJ15VfKRmOqe79B3Jr7tQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'received:209.85.223': 0.03; 'python)': 0.05; 'expressions': 0.07; 'commit': 0.15; 'value.': 0.15; '(unlike': 0.16; 'hard-code': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'statements,': 0.16; 'stepping': 0.16; 'subject:operators': 0.16; 'value;': 0.16; 'wrote:': 0.16; 'skip': 0.18; '>': 0.18; '2015': 0.20; 'either.': 0.22; 'latter': 0.22; 'am,': 0.23; 'dec': 0.23; 'unlike': 0.23; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'values': 0.28; 'them?': 0.29; 'subject:/': 0.30; 'that.': 0.30; "can't": 0.32; 'are:': 0.32; 'received:google.com': 0.35; 'next': 0.35; 'could': 0.35; 'something': 0.35; 'step': 0.36; 'but': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'received:209': 0.38; 'anything': 0.38; 'mean': 0.38; 'why': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'necessarily': 0.63; 'differences': 0.66; "they're": 0.66; 'syntax?': 0.84; 'to:name:python': 0.84; 'imagine': 0.96 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=0znkSI8CEAAWOw6qf0CQevXS8QjWKgWlBa/U7+mj2N0=; b=M7EGrnPfOr0cmeyqjaYFvSK40A42bFknubgAG1/THDyLAFs4hTEmbKBI/3dCT26wx+ BLhvYbADgbcUq0nkt2QjpoBQo5mkkfikfya0eI3q7i33WJ/Hqw19O+buDhXwxr1s5s0O 15/UOjH40UOG79ZQpuicMAv/prB1uKlJdyir1jdUTVATLvZfd4+qFRCdchMpoocD3gty TpwmaCpMuK1t3YCB76BkrE9ZQ+GAsq09E5jhFEczmld7YrfcVR1RWKE3L0glBIBsa4LU C0rfaOhM7SyZm09jGdvPH9PxYOBWNVJDARRZGOMTOl1jzYtxOTiWOpxxGYy2H68BBvcj 8Kfw== X-Received: by 10.107.164.154 with SMTP id d26mr1180369ioj.111.1449534284889; Mon, 07 Dec 2015 16:24:44 -0800 (PST) In-Reply-To: X-Content-Filtered-By: Mailman/MimeDel 2.1.20+ 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:100121 On Dec 5, 2015 10:21 AM, "BartC" 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?