Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Joel Goldstick Newsgroups: comp.lang.python Subject: Re: Why not allow empty code blocks? Date: Sun, 24 Jul 2016 08:28:40 -0400 Lines: 124 Message-ID: References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de mMLWnXPEb5qdB/hFZXf2Fw3fH69gDGJTZksfHVHo7lKQ== 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; 'think,': 0.05; 'block;': 0.07; 'problem?': 0.07; 'subject:code': 0.07; 'trailing': 0.07; 'cc:addr:python-list': 0.09; 'high-level': 0.09; 'insertion': 0.09; 'likely.': 0.09; 'pressing': 0.09; 'statements': 0.09; 'subject:Why': 0.09; 'tab': 0.09; 'typed': 0.09; 'thread': 0.10; 'url:blog': 0.10; 'python': 0.10; 'subject:not': 0.11; 'def': 0.13; '(do': 0.16; '2016': 0.16; '24,': 0.16; 'attention,': 0.16; 'backspace': 0.16; 'conclusion:': 0.16; 'dog': 0.16; 'editor,': 0.16; 'head,': 0.16; 'inserting': 0.16; 'pressed': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'run.': 0.16; 'sequence:': 0.16; 'sheer': 0.16; 'space;': 0.16; 'subject:allow': 0.16; 'tabs': 0.16; 'to:addr:pearwood.info': 0.16; "to:name:steven d'aprano": 0.16; 'worse.': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'say,': 0.18; 'runs': 0.18; 'language': 0.19; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'arguments': 0.22; 'pass': 0.22; 'programming': 0.22; 'am,': 0.23; 'code.': 0.23; 'insert': 0.23; "python's": 0.23; 'sets': 0.23; 'somewhere': 0.24; 'header:In- Reply-To:1': 0.24; 'sort': 0.25; "i've": 0.25; 'error': 0.27; '(e.g.': 0.27; 'coding': 0.27; 'followed': 0.27; 'least': 0.27; 'message-id:@mail.gmail.com': 0.27; 'errors.': 0.27; 'said,': 0.27; 'actual': 0.28; 'accidentally': 0.29; 'argue': 0.29; 'handful': 0.29; 'indentation': 0.29; 'character': 0.29; 'typically': 0.29; 'allows': 0.30; 'work.': 0.30; 'code': 0.30; 'certainly': 0.30; 'programmers': 0.30; 'guess': 0.31; 'probably': 0.31; 'another': 0.32; "can't": 0.32; 'point': 0.33; 'common': 0.33; "d'aprano": 0.33; 'errors,': 0.33; 'steven': 0.33; '2009': 0.34; 'correctly': 0.34; 'editor': 0.34; 'structure': 0.34; 'except': 0.34; 'this?': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'text': 0.35; 'configured': 0.35; 'execution': 0.35; 'nothing.': 0.35; 'possible,': 0.35; 'quite': 0.35; "isn't": 0.35; 'but': 0.36; 'should': 0.36; 'instead': 0.36; 'beginning': 0.36; 'depends': 0.36; 'loaded': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'two': 0.37; 'suggestion': 0.37; 'things': 0.38; 'times.': 0.38; 'delete': 0.38; 'wrong': 0.38; 'end': 0.39; 'why': 0.39; 'goes': 0.39; 'sure': 0.39; "didn't": 0.39; 'still': 0.40; 'space': 0.40; 'some': 0.40; 'your': 0.60; 'press': 0.61; 'leading': 0.61; 'body': 0.61; 'needing': 0.63; 'more': 0.63; 'times': 0.63; 'of:': 0.66; 'talking': 0.67; 'subject': 0.70; 'url:info': 0.71; 'jul': 0.72; 'protect': 0.76; 'align:': 0.84; 'compiles': 0.84; 'delete,': 0.84; 'disappear': 0.84; 'subtly': 0.84; 'joel': 0.91; 'write:': 0.91; 'hundred': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=JR6dqvBdp8lhp+k8PIfq5/sc5H3hPRwVGCFnHdh+PG4=; b=aHsfQWMYZJHVpxYFEOMlBMb9gnGe6qLxZ+1wMhhDnoftTuFqBzefFE6SNns186tPEi AvA3VwDztahzRNqRzVmCLKSbeuwFx7hRRHQH/pEAy4cAJryn6hcci3gtdokwElELgXAf M4Cgi1LNebgQDA8Cfiwit7GU+s74gDu4KglIM9gkDK2BJOzk+4TIHxoSx5CxrmLCqUSj FSlpa54yZ6EH0nNTlOELQhca4U58kJLxDSH7X+Y2Nus2vFr+ZZWib/tp/sVvcDAZb9Yt m2C1qLp2BmhhhIx8vvxjB+P51wNRbtSjpdfBbLtcrJTnaQ2o/dcfpsxcr/u9wtUA4cd9 7Gpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=JR6dqvBdp8lhp+k8PIfq5/sc5H3hPRwVGCFnHdh+PG4=; b=Wv5lzhF+zS/r1bE8WxvAm4GBsaPsmRaDSwErtTQsNUGWrmK0TZGEy+NpzLR3Ychjfh iI+gp+jXZSqCjU4tJjWS+uV509Xzm08SUfJHaK43N9nn1bin45BAHHlipi+JWiMWKFzQ 5DELAdsy+wURD0ogIH5zrWUFI9qiPWFiZ77Y4YKGYdowg3Q8Z6mSEVxMeu59nJamnPV1 C4qvREePDzv55nHw/+4OPhvOvnfvNekVMtCkz+LBaZq2jKlW6JbuubzfsxzYxJlRmS+v er4WZtcXWd1GDVwyMMhZKSf0A45dbPsd/iw6tuhH7N2IF84PUJpR2eFx+LGmxord6rzC c7yQ== X-Gm-Message-State: AEkoousET4Iu61dFzcyeZFbJSJt3+dtSDXMEWz+twhK/ZDnTamVkbDQMAAD8VOxB8xkOW2tymrj5zJnGqcJaCA== X-Received: by 10.157.1.214 with SMTP id e80mr7582964ote.141.1469363320777; Sun, 24 Jul 2016 05:28:40 -0700 (PDT) In-Reply-To: <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <5792cd34$0$1587$c3e8da3$5496439d@news.astraweb.com> <87vazwppxx.fsf@elektro.pacujo.net> <20160723082947.7cae8bd1@imp> <87fur0a44p.fsf@elektro.pacujo.net> <20160723095441.29562c54@imp> <57939373$0$1586$c3e8da3$5496439d@news.astraweb.com> <5794b1d7$0$1620$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:111804 On Sun, Jul 24, 2016 at 8:17 AM, Steven D'Aprano wrot= e: > On Sun, 24 Jul 2016 08:35 pm, BartC wrote: > >> I didn't want to get into this subject again, but Python's indentation >> scheme is fragile. > > *shrug* > > Okay, it's fragile. In 20 (give or take a couple) years of programming in > Python, do you know how many times this fragility has been an *actual* > problem? Why don't you take a guess? > > >> Given an otherwise correctly typed program that compiles with no errors, >> then it is very easy (if Backspace or Delete is inadvertently pressed >> for example), for an indent to disappear without your noticing, > > Not really. It depends on the editor, but typically you need to have your > text insertion point somewhere in the indent. > > And when you do accidentally press Delete, what happens? The high-level > structure of the code changes. Typically things will no longer align: > > def f(): > for x in seq: > do_this() > do_that() > do_more() > > which is a SyntaxError. It requires quite the coincidence before you can > accidentally delete an indent and have the code still run. Far more likel= y > is that accidentally pressing delete will break the code in a way that > can't be detected until runtime: > > def f(): > for x in seq: > do_this() > d_that() > do_more() > > Conclusion: if you're the sort of person who habitually presses the Delet= e > or Backspace key without paying attention, you're going to have a bad tim= e. > > (Do other professions make arguments like this? Do carpenters, say, argue > against nail guns because "well if you accidentally hold a loaded nail gu= n > to your head, then press the trigger, bad things will happen"? Or is it > just programmers who make a common practice of arguing that the programmi= ng > language should protect the user from sheer carelessness?) > > >> but a >> program still compiles. And still runs without execution errors. But >> might now be subtly wrong. > > That's certainly *theoretically* possible, but its really not likely. The > only way it could happen is: > > - you have a block with at least two lines; > - your insertion point is in the indent of the last line of the block; > - but not the actual text part; > - your editor is configured to dedent on Delete/Backspace, not just > delete a single space; or you're using tabs to indent; > - and the block isn't followed by another block (e.g. if...else...) > > > >> Deleting any other character than a leading space or tab I think is more >> likely to result in an error that would be noticed, generate a compile >> error, or execute error ('variable not initialised'), or that goes wrong >> more obviously. > > pi =3D 314159 # oops accidentally hit delete > > > [...] >> But my suggestion is simply that you can write: >> >> for x in sequence: >> end >> >> instead of: >> >> for x in sequence: >> pass >> >> The first now allows statements to be added or removed from the body of >> the loop without needing to change the 'end'; it wouldn't look out of >> place as a trailing 'pass' would. > > You know, I suspect that you've probably spent more time talking about th= e > effort required to delete and insert "pass" than the *actual* effort spen= t > by a hundred programmers deleting and inserting "pass" in their code. > > >> But thinking about it some more, it wouldn't work. All the blocks that >> don't now use 'end' would look odd. I think it would either have to be >> all or nothing. I guess nothing. > > > > > -- > Steven > =E2=80=9CCheer up,=E2=80=9D they said, =E2=80=9Cthings could be worse.=E2= =80=9D So I cheered up, and sure > enough, things got worse. > This thread is beginning to feel like a dog whistle for people who like braces. I've been python coding since 2009 I think, and I think I have used pass less than a handful of times. ... and except for sets and dicts, I can't remember using a { --=20 Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays