Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Entropy requires no maintenance. -- Markoff Chaney


devel / comp.lang.python / RE: Friday Finking: Contorted loops

SubjectAuthor
o RE: Friday Finking: Contorted loopsAvi Gross

1
RE: Friday Finking: Contorted loops

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: avigross@verizon.net (Avi Gross)
Newsgroups: comp.lang.python
Subject: RE: Friday Finking: Contorted loops
Date: Mon, 13 Sep 2021 17:50:48 -0400
Lines: 185
Message-ID: <mailman.721.1631569856.4164.python-list@python.org>
References: <097bf31d-44e8-da35-df41-3834524716c9@DancesWithMice.info>
<she6e0$3bi$1@ciao.gmane.io> <shffd3$p0h$1@ciao.gmane.io>
<YTzAN/9aoKmr9O/P@hjp.at> <shioie$oag$1@ciao.gmane.io>
<YT44tuiwcqezPrbG@scrozzle> <YT5n2c181DufCcmq@hjp.at>
<022501d7a81a$d308bbe0$791a33a0$@verizon.net> <YT+mPYyPDOqZxknY@hjp.at>
<03a101d7a8e9$69e80a60$3db81f20$@verizon.net>
Mime-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de v7J4Pd12Az1vEV8bijq2bgYTfb4ZUdOBPt6xrHgA0+5g==
Return-Path: <avigross@verizon.net>
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=verizon.net header.i=@verizon.net header.b=DBaU21FR;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'looks': 0.02; 'project,':
0.03; 'comments': 0.03; 'chances': 0.05; 'frequent': 0.05;
'usage': 0.05; 'variable': 0.05; 'field.': 0.07; 'intermediate':
0.07; 'loop': 0.07; 'matches': 0.07; 'programmer': 0.07;
'suggestion': 0.07; 'better,': 0.09; 'comment,': 0.09; 'meant':
0.09; 'memory.': 0.09; 'rarely': 0.09; 'smaller': 0.09;
'something,': 0.09; '"creative': 0.16; '__/': 0.16; 'assumptions':
0.16; 'avi': 0.16; 'cases,': 0.16; 'challenge!"': 0.16;
'controlling': 0.16; 'examine': 0.16; 'explaining': 0.16;
'explicit': 0.16; 'gross': 0.16; 'help:': 0.16; 'hjp@hjp.at':
0.16; 'holzer': 0.16; 'inclusion': 0.16; 'indentation': 0.16;
'interpreter': 0.16; 'japan,': 0.16; 'loops': 0.16; 'mention.':
0.16; 'nested': 0.16; 'outer': 0.16; 'purely': 0.16; 'reality.':
0.16; 'received:(vzm hermes smtp server)': 0.16;
'received:74.6.135.42': 0.16;
'received:sonic302-3.consmr.mail.bf2.yahoo.com': 0.16; 'refresh':
0.16; 'relatively': 0.16; 'releases': 0.16; 'somewhat': 0.16;
'spot': 0.16; 'stross,': 0.16; 'syntactic': 0.16; 'tends': 0.16;
'things,': 0.16; 'times,': 0.16; 'url-ip:212.17.106.137/32': 0.16;
'url-ip:212.17.106/24': 0.16; 'url-ip:212.17/16': 0.16; 'url:hjp':
0.16; '|_|_)': 0.16; 'wrote:': 0.16; 'problem': 0.16; 'instead':
0.17; 'uses': 0.19; 'figure': 0.19; 'to:addr:python-list': 0.20;
'language': 0.21; 'input': 0.21; 'written': 0.22; "i've": 0.22;
'returns': 0.22; 'code': 0.23; 'command': 0.23; 'goal': 0.23;
'lines': 0.23; 'idea': 0.24; 'anything': 0.25; 'skip:- 10': 0.25;
'section': 0.25; 'seems': 0.26; 'object': 0.26; 'bit': 0.27;
'function': 0.27; 'done': 0.28; 'purpose': 0.28; 'sense': 0.28;
'example,': 0.28; 'code,': 0.31; 'takes': 0.31; 'comment': 0.31;
'13,': 0.32; 'checks': 0.32; 'collected': 0.32; 'end.': 0.32;
'friday': 0.32; 'language.': 0.32; 'python-list': 0.32;
'returning': 0.32; 'structure': 0.32; 'management': 0.68; 'right':
0.68; 'know.': 0.68; 'adds': 0.69; 'change.': 0.69; 'files:':
0.69; 'ones,': 0.69; 'processing,': 0.69; 'url-ip:212/8': 0.69;
'vast': 0.69; 'within': 0.69; 'below': 0.69; 'them,': 0.70;
'too.': 0.70; '2021': 0.71; 'carry': 0.71; 'longer': 0.71;
'future': 0.72; 'global': 0.73; 'tools': 0.74; 'hundreds': 0.75;
'records': 0.75; 'yourself': 0.75; '....': 0.76; 'languages,':
0.76; 'sent:': 0.78; 'discuss': 0.78; 'field': 0.78; 'major':
0.78; 'out.': 0.80; 'quickly': 0.80; 'up,': 0.84; 'absolutely':
0.84; 'clause': 0.84; 'clue': 0.84; 'comments,': 0.84; 'expedite':
0.84; 'figuring': 0.84; 'inputs': 0.84; 'lose': 0.84;
'management.': 0.84; 'metrics': 0.84; 'requires.': 0.84; 'varies':
0.84; 'weird': 0.84; '"do': 0.91; 'badly': 0.91; 'particular,':
0.91; 'line,': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=verizon.net; s=a2048;
t=1631569853; bh=hNlXXb9d0zCB1AiS20HzT3cyf4kReeyf9fMhpErjGWw=;
h=From:To:References:In-Reply-To:Subject:Date:From:Subject:Reply-To;
b=DBaU21FRfsrphxKH4SFrHn3qTusyUvEhfEv4YGyHb1z5CdxsWehvcbTbO8aS0ZtJQcyokRpI+j/ymMrXNAP58KvYILuz5RfR/vCX+0J1w3O2Bz+44CPdS+s7ZTQGTumPeoJtKP8Kjh9Gb6RJ0aGMWr3R0jm6KLOu8+Q8DSlQ8eDrifUb1iI/c3AeBtdGH9WZ8Osq5r19YjZ7Z0UCIR9CiQfwgsX4xddYosl1zHaB+UcOOdFzsaY6Glswzf9ko8cvkQ/eh81lv6mv/jQ3LJW7MEJ1cyizC9U81m6bnVHW/PBP/Aeji/5NUVSlWknI/5St+ry3xaNm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ENQ2XDLk1iAZo33eedZhi635x0bmtACQMau4oaD4pCEaD6guddt.DnZM4
IIp8dR6EDcR_vtzEHM_TiIDNyM65UP5WV90cipH7EsYB9e9eWcqbI7yjyw1d4YYg8pLwHbfBnSem
PVe0Z2vJ0KkN1sgiTFE66wvxinmkHFlYMBZQ2OhOZ3rI4JWTUQio25XtbBDfkwu1BTp8Q23htV29
GxbP.qZZJJTY9uZQwTg9xYxh8BdW6cf0BYwR_v.2A2t0k26OQ95dQ0ZKLOUFc6rnUPK.YrTHK9eE
f87W2wFt6YUoPW6UjCcDBaR0lFovVC82KMN5nc6UdBwx4_fGYKUUCGj6wecPmPCC1yIyQlS.nryD
T7H1ixivF7PJELrRnS1ncvuw74EgKYqPlTZcR2QzikDvRaCYJHW89bGjpHr1NI_wtlUdv3Upmaed
PVfOPvrfv2PVykuTiN0RUfH4zqJR.Fge4n14lX38lSQeIIzvD8_cfgSqf1cWnLUDZUBK86pawpJx
y__XHsW50APe445mISkwK3TW04533p9GTdHYVzWt_mg24LswRRBgr3LEd6HPLjaxyclkN0ck0A3N
.XsEUtp6jRKnxPGnp_As_i3X3dFyax4zCM5urydXb_tPyBah.G7BP.e7hsHG2TVpNLjOHTyFIxc.
43wcQTMs_
X-Sonic-MF: <avigross@verizon.net>
In-Reply-To: <YT+mPYyPDOqZxknY@hjp.at>
X-Mailer: Microsoft Outlook 16.0
Thread-Index: AQH8RFnQrsJfLkU50XE9+Q5aLLwBIgI1rsnrAPdcHy0COQJ+rgDeecX1Akraiz8CSfUVdgMZtZEXAkQvWOOq14owkA==
Content-Language: en-us
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
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: <03a101d7a8e9$69e80a60$3db81f20$@verizon.net>
X-Mailman-Original-References: <097bf31d-44e8-da35-df41-3834524716c9@DancesWithMice.info>
<she6e0$3bi$1@ciao.gmane.io> <shffd3$p0h$1@ciao.gmane.io>
<YTzAN/9aoKmr9O/P@hjp.at> <shioie$oag$1@ciao.gmane.io>
<YT44tuiwcqezPrbG@scrozzle> <YT5n2c181DufCcmq@hjp.at>
<022501d7a81a$d308bbe0$791a33a0$@verizon.net> <YT+mPYyPDOqZxknY@hjp.at>
 by: Avi Gross - Mon, 13 Sep 2021 21:50 UTC

Peter,

Choosong when and how to comment is an invidual thing and certainly the
interpreter does not care.

Yes, I gave an example where my comment used inner/outer as the words but
more often I am more explicit along the lines you mention. Sometimes I
include most of the text into the comment such as
if x <10 {
.... MANY LINES
} # END if x <10

But please understand the goal is many fold. One simple goal is that by
having to comment the code, you sort of have to explain it to yourself and
use the opportunity to see if it makes sense and matches any requirements or
perhaps even adds new functionality not already documented.

Secondarily, it is for you to read much later when returning to the code to
refresh your memory.

In many organizations, including where I worked, there can be levels of code
review that work better if others have a clue what they are reviewing or
why.

And of course, others often take over your code or examine it.

At one point I was doing field support on a project, way back when it meant
something to carry a beeper. I had written some of the code but the vast
majority was done by others on the team. When I got beeped at 3 AM from a
place like Japan, I often had to make rapid decisions on how big a problem
was and whether I should wake someone up, including developers and their
management or even rarely upper management. I often dove into the code to
find the likely locus of a problem and even to see if I could spot the place
that might be patched. That often let me wake up the right person and work
with them to expedite an emergency change. Even in less chaotic or major
times, I had to work with getting a problem acknowledged and scheduled for
inclusion in a future release. Being able to read all kinds of source code
and figuring it out quickly was important and sometimes comments were
helpful. In particular, some people did not need to be woken up if I was
able to see the problem was not in their code!

Comments do often have a rather weird purpose. Sometimes we collected
metrics on how many lines of code were new or changed between releases and
unless the tools removed comments, ...

But I have found over the years that too many comments are badly done. For
example, rather than ending every line of a function definition with all
kinds of things that clutter things, it is often better to place a few block
comments above a function definition explaining the general purpose of the
function, what inputs are expected on the command line, what assumptions are
made about them, whether it uses any other resources (including dreaded
global variables) and what it returns or what errors it may generate and so
on. You can also discuss the overall idea of how the function does the job.
Then, within the function, you can have smaller mainly one-liners like:
# This section checks if the variables are all within expected bounds.
...
# Combine ...
...
# quit if not satisfied
...
# Make the changes requested.
...
# return successfully with a structure holding ...
...

Again individual taste. My personal commenting style has evolved and varies
from language to language. In many cases, I have used well-chosen variable
names that are meaningful to me but not keywords. Sadly for some others, I
sometimes choose variable names in other human languages, sometimes
transliterated as sticking to ASCII requires. Most people are not able to
even guess, so say commenting in Hungarian or German or Hebrew may only be
of use to me and other weird people.

I do find that for frequent enough usage of something, such as an object
like a deque, you get to know it so well that you may stop commenting on how
you are using some built-in feature as it seems routine.

-----Original Message-----
From: Python-list <python-list-bounces+avigross=verizon.net@python.org> On
Behalf Of Peter J. Holzer
Sent: Monday, September 13, 2021 3:28 PM
To: python-list@python.org
Subject: Re: Friday Finking: Contorted loops

On 2021-09-12 17:11:58 -0400, Avi Gross via Python-list wrote:
> Yes, large units of code, and even smaller ones, may be a chore to
> figure out. Arguably harder when you use indentation and the next/last
> parts are not even on the same screen as the rest. Sometimes you want
> to use a split-screen in some editor to line up the two parts or some
> other technique.
>
> But my suggestion is to COMMENT things well and I mean too much!
>
> do {
> <CODE>
> } while <COND>
>
> Why not add a comment at the top like:
>
> # The following loop has a WHILE clause controlling it at the end.
>
> do { # until the while clause below
> <CODE>
> } while <COND> # End of the do loop.

Because those comments don't tell me anything that I as a C programmer don't
already know. Even though do/while loops are relatively rare, I've seen
hundreds of them. Seeing "do {" and recognizing it as the top of a do/while
loop takes absolutely no conscious thought - reading a comment does.

> My code tends to have brief comments especially when I have nested
> constructs such as multiple nested loops or in sequence, or if
> statements inside others. The comment often looks like
>
> ... # END of inner if
>
> ... # END of outer if

Those are a bit better, but they still don't help much. What is the "inner
if", what is the "outer if"? Chances are that I have to find the
corresponding if to find out - I can do that without a comment, too.

There are end-of-construct comments which I do find useful (at least
occasionally) but those are semantic.

Imagine a somewhat longish function which read several files which are
comprised of records which are comprised of field.

for file in files:

some setup for each file here

for record in file:

some setup for each record here

for field in record:

process field

do some postprocessing for the record

do some postprocessing for the file

If each of these blocks is longer than a few lines you might lose track
where you are, so some comments might help:

for file in files:

some setup for each file here

for record in file:

some setup for each record here

for field in record:

process field

# end of field loop

do some postprocessing for the record

# end of record loop

do some postprocessing for the file

# end of file loop

Note that the comments say which part of the input the loop is processing,
not just that it is the end of a loop or "the outer loop", "the intermediate
loop" and "the inner loop" or some other purely syntactic information.

(In most cases I would just break up such a function into smaller functions
instead of adding comments, though)

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"


devel / comp.lang.python / RE: Friday Finking: Contorted loops

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor