Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

No line available at 300 baud.


devel / comp.lang.python / Re: Behavior of the for-else construct

SubjectAuthor
o Re: Behavior of the for-else constructRob Cliffe

1
Re: Behavior of the for-else construct

<mailman.143.1646357801.2329.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17320&group=comp.lang.python#17320

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rob.cli...@btinternet.com (Rob Cliffe)
Newsgroups: comp.lang.python
Subject: Re: Behavior of the for-else construct
Date: Fri, 4 Mar 2022 01:32:12 +0000
Lines: 112
Message-ID: <mailman.143.1646357801.2329.python-list@python.org>
References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
<YiFCPlGC+2aRIR0K@shallowsky.com>
<21739669.459456.1646348879560@mail.yahoo.com>
<CAPTjJmoXyHF_N1E2KFZ+YZmZ8+zm4E_Pra_hbXLHWuNs1XtiBQ@mail.gmail.com>
<46ef1b7f-5689-0cd5-ce89-be4c453d262f@btinternet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de w6x63Myw1ox8Ewg1N6YtrQ9XLeimLqSi2f+RgiUFUQFg==
Return-Path: <rob.cliffe@btinternet.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=btinternet.com header.i=@btinternet.com header.b=ehFnfLUO;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '2022': 0.05; 'fairly':
0.05; 'e.g.': 0.07; 'else.': 0.07; 'mar': 0.07; 'translate': 0.07;
'used.': 0.07; 'wrong.': 0.07; 'python.': 0.08; '"just': 0.09;
'angelico': 0.09; 'else:': 0.09; 'emacs': 0.09; 'it)': 0.09;
'language,': 0.09; 'like,': 0.09; 'operators': 0.09;
'received:192.168.1.64': 0.09; 'supported': 0.15; 'syntax': 0.15;
"(i'm": 0.16; '[1]:': 0.16; 'analogy': 0.16; 'arbitrary': 0.16;
'avi': 0.16; 'chrisa': 0.16; 'constructs.': 0.16; 'executed':
0.16; 'explicit': 0.16; 'feature.': 0.16; 'gross': 0.16; 'idea.':
0.16; 'instead.': 0.16; 'intuitive': 0.16; 'mean,': 0.16;
'order?': 0.16; 'presumably': 0.16; 'programmer.': 0.16; 'recall':
0.16; 'reminds': 0.16; 'safe".': 0.16; 'sentences,': 0.16;
'subject:else': 0.16; 'triggered': 0.16; 'tuple': 0.16; 'typing':
0.16; 'vague': 0.16; 'yield': 0.16; 'wrote:': 0.16; 'code.': 0.17;
'instead': 0.17; "can't": 0.17; 'implement': 0.19; 'to:addr
:python-list': 0.20; 'language': 0.21; "i've": 0.22; 'languages':
0.22; 'advanced': 0.22; 'exception': 0.22; 'fri,': 0.22; 'maybe':
0.22; 'problem,': 0.22; 'version': 0.23; 'idea': 0.24; 'python,':
0.25; 'examples': 0.25; 'saying': 0.25; 'anyone': 0.25; 'seems':
0.26; 'tried': 0.26; 'binary': 0.26; 'do,': 0.26; "isn't": 0.27;
'leave': 0.27; 'else': 0.27; 'bit': 0.27; 'function': 0.27;
'chris': 0.28; 'it,': 0.29; 'header:User-Agent:1': 0.30;
'wondering': 0.31; 'think': 0.32; '(as': 0.32; 'context': 0.32;
'execution': 0.32; 'fine.': 0.32; 'language.': 0.32;
'programmers': 0.32; 'python-list': 0.32; 'returning': 0.32;
'suitable': 0.32; 'unexpected': 0.32; 'words,': 0.32;
'received:192.168.1': 0.32; 'but': 0.32; "i'm": 0.33;
'subject:for': 0.33; 'there': 0.33; 'particular': 0.33; 'someone':
0.34; 'able': 0.34; 'same': 0.34; 'core': 0.34; 'mean': 0.34;
'skip:" 20': 0.34; 'work.': 0.34; 'header:In-Reply-To:1': 0.34;
'running': 0.34; 'item': 0.35; 'meaning': 0.35; 'one.': 0.35;
'tool': 0.65; 'wish': 0.66; 'now,': 0.67; 'types': 0.67; 'back':
0.67; '[1]': 0.67; 'body': 0.67; 'heard': 0.67; 'items': 0.68;
'order': 0.69; 'perfectly': 0.69; 'little': 0.73; 'easy': 0.74;
'tools': 0.74; 'hearing': 0.75; 'features': 0.75; 'features.':
0.76; 'sponsored': 0.76; 'supposed': 0.76; 'points': 0.84;
'reasons': 0.84; 'absolutely': 0.84; 'bind': 0.84; 'desperately':
0.84; 'exceptions': 0.84; 'feature,': 0.84; 'happened.': 0.84;
'incorrect': 0.84; 'macro': 0.84; 'rob': 0.84; 'say,': 0.84;
'signs': 0.84; 'speaking,': 0.84; 'spelling': 0.84; 'was.': 0.84;
'heads': 0.91; 'scared': 0.91; 'will.': 0.91; 'cut': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=btinternet.com;
s=btmx201904; t=1646357535;
bh=N3EDbRou3Z/MAjOJa9xLBsGiVCEHeiiIDS2GwvyiPc0=;
h=Message-ID:Date:MIME-Version:Subject:To:References:From:In-Reply-To;
b=ehFnfLUODzDfo0ip/Liwf2ek1aFf968RHXT2YaPpTIfLVvu+K3JZOwcSt6pKI6C1aUilBAct3SRXN3jkEa4aK6sWZLWNOw14UeIBqVPUBn+2SicEsE95HA4WtqH4ZTVZNQcEZLsadfC6SzLJzA4+bucnv+KezRcqBW1nvwmpcpg0vKlbu5USNTF2HBlg5kU2DjGHXV80tgI6KBZ/TVHM+jLq5xsxrG6q9dI/CQ5TWtEyz7bGZ19fWw7+S0qeGp3UmUQudaZsXf/2n4t2VdDlp7cfq/othrilGCPHqsFNYrCJ7bPIQRJo8Tn81sqP1PbJbngPfdyGGkmYzDsyVXWIiQ==
Authentication-Results: btinternet.com;
auth=pass (PLAIN) smtp.auth=rob.cliffe@btinternet.com;
bimi=skipped
X-SNCR-Rigid: 613A901C172C3A3C
X-Originating-IP: [86.173.124.29]
X-OWM-Source-IP: 86.173.124.29 (GB)
X-OWM-Env-Sender: rob.cliffe@btinternet.com
X-VadeSecure-score: verdict=clean score=0/300, class=clean
X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvvddruddtjedgfeehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomheptfhosgcuvehlihhffhgvuceorhhosgdrtghlihhffhgvsegsthhinhhtvghrnhgvthdrtghomheqnecuggftrfgrthhtvghrnhepvdetudfhtefgveegieffleelvdeugfeikeevveehudetgfevieejfedtteevtdegnecukfhppeekiedrudejfedruddvgedrvdelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghloheplgduledvrdduieekrddurdeigegnpdhinhgvthepkeeirddujeefrdduvdegrddvledpmhgrihhlfhhrohhmpehrohgsrdgtlhhifhhfvgessghtihhnthgvrhhnvghtrdgtohhmpdhnsggprhgtphhtthhopedupdhrtghpthhtohepphihthhhohhnqdhlihhsthesphihthhhohhnrdhorhhg
X-RazorGate-Vade-Verdict: clean 0
X-RazorGate-Vade-Classification: clean
X-SNCR-hdrdom: btinternet.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Content-Language: en-GB
In-Reply-To: <CAPTjJmoXyHF_N1E2KFZ+YZmZ8+zm4E_Pra_hbXLHWuNs1XtiBQ@mail.gmail.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <46ef1b7f-5689-0cd5-ce89-be4c453d262f@btinternet.com>
X-Mailman-Original-References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
<YiFCPlGC+2aRIR0K@shallowsky.com>
<21739669.459456.1646348879560@mail.yahoo.com>
<CAPTjJmoXyHF_N1E2KFZ+YZmZ8+zm4E_Pra_hbXLHWuNs1XtiBQ@mail.gmail.com>
 by: Rob Cliffe - Fri, 4 Mar 2022 01:32 UTC

On 04/03/2022 00:34, Chris Angelico wrote:
> On Fri, 4 Mar 2022 at 10:09, Avi Gross via Python-list
> <python-list@python.org> wrote:
>> The drumbeat I keep hearing is that some people hear/see the same word as implying something else. ELSE is ambiguous in the context it is used.
>>
> What I'm hearing is that there are, broadly speaking, two types of
> programmers [1]:
>
> 1) Those who think about "for-else" as a search tool and perfectly
> understand how it behaves
> 2) Those who have an incorrect idea about what for-else is supposed to
> do, don't understand it, and don't like it.
Or those who have a vague fuzzy idea about it and have trouble
remembering what it does.
>
> You could easily make a similar point about a lot of other advanced
> constructs. Some people don't understand threading, and either dislike
> it or are scared of it. Some people never get their heads around
> asyncio and the way that yield points work. Some people can't grok
> operator precedence, so they parenthesize everything "just to be
> safe". And some people dislike exceptions so much that they warp all
> their functions into returning a (value,True) or (error,False) tuple
> instead. Does this mean that all these features are bad? No.
You could add examples ad nauseam.  I submit that for-else is a special
case.  As evidenced by the number of people (including me) who say they
have trouble grokking it.
>
> There's no way to make every feature perfectly intuitive to every
> programmer. Those features are still incredibly useful to the
> programmers that DO use them.
>
> Maybe, with hindsight, for-finally would have been a slightly better
> spelling than for-else.
No.  "finally" suggests (as analogy to try...finally) that the "finally"
suit body is always executed.  Presumably even if an untrapped exception
occurs in the for-loop body (or even in the for-loop iterator).  A
for-loop can be terminated with "break" for many  conceptually different
reasons e.g.
    A search for a suitable item has found one.
    Something unexpected has happened.
    A pre-set allowed execution time has been exceeded.
"nobreak"/"no_break" etc. is explicit and conceptually neutral.
> Who knows. But people simply need to
> understand it, just like people need to understand how binary
> floating-point works, and claiming that it's "ambiguous' is simply
> wrong. It has one meaning in the language, and then if programmers
> have an incorrect expectation, they need to learn (or to not use the
> feature, which isn't really a problem, it's just not taking advantage
> of it).
>
>> And naturally, since nobody desperately wants to use non-reserved keywords, nobody seems ready to use a word like INSTEAD instead.
>>
>> Ideally, a language should be extendable and some languages like R allow you to place all kinds of things inside percent signs to make new operators like %*% or %PIPE% ...
>>
> I don't know what you mean by "extendable", but if you mean that
> different people should be able to change the language syntax in
> different ways, then absolutely not. When two different files can be
> completely different languages based on a few directives, it's
> extremely difficult to read.
+0.9, although I do sometimes wish for a macro feature in Python. Like,
say, one that would translate "nobreak" into "else". 😁
>
> (Import hooks, and tools like MacroPy, can be used for this sort of
> effect.
I haven't tried MacroPy yet, maybe someday I will.
> I do not think that we should be using them on a regular basis
> to change core syntax.)
>
>> Just because some feature may be wanted is not a good reason to overly complicate a language. Can you imagine how hard it would be both to implement and read something like:
>>
>> ...
>> ELSE:
>> ...
>> OK:
>> ...
>> FINALLY:
>> ...
>> ULTIMATELY:
>> ...
>>
>> What if multiple of things like the above example need to be triggered in some particular order?
It would be easy to read if they were spelt sensibly, e.g.
    if_no_iterations:
    if_one_iteration:
    if_multiple_iterations:
    if_any_iterations:
    if_break:
    if_no_break:
(I'm not saying that all of these are desirable, just conveying the idea.)
If multiple clauses were triggered, they should be executed in the order
in which they occur in the code.
> I don't know what they'd all mean, but if they were all in the core
> language, they would have to be supported in arbitrary combinations.
> It's possible to have a "try-except-else-finally" block in Python, for
> instance. But if you mean that they should all do what "else" does
> now, then this is a terrible idea. One way of spelling it is just
> fine.
>
>> This reminds me a bit of how some programs add so much functionality because someone thought of it without wondering if anyone (including the ones who sponsored it) would ever want to use it or remember it is there or how. I recall how a version of emacs had a transpose-letter function so after typing "teh" you could hit control-t and a little mock LISP macro would go back and co a cut and go forward and do a paste and leave the cursor where it was. That was sometimes useful, but often just as easy to backspace and retype. But I recall gleefully adding a transpose for words, sentences, paragraphs and was going to add more but I was running out of keystrokes to bind them to and besides it can be fairly easy to select items and yank them and move to where you want them and replace them.
>>
> SciTE has a "transpose lines" feature. I use it frequently. But editor
> features are quite different from language features.
>
> ChrisA
>
> [1] Something tells me I've heard this before
Of course you have.  There are three types of programmer: those that can
count, and those that can't.
Rob Cliffe

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor