Sujet : Re: The joy of FORTRAN
De : invalid (at) *nospam* invalid.invalid (Richard Kettlewell)
Groupes : alt.folklore.computers comp.os.linux.miscDate : 05. Mar 2025, 09:46:30
Autres entêtes
Organisation : terraraq NNTP server
Message-ID : <wwveczb7tll.fsf@LkoBDZeT.terraraq.uk>
References : 1 2 3 4 5
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
cross@spitfire.i.gajendra.net (Dan Cross) writes:
John Ousterhout recently published the contents of a written
"debate" he had with Robert C Martin that went into this at some
length. With the caveat that I think Martin is a charlatan,
folks here might find it interesting and relevant.
>
https://github.com/johnousterhout/aposd-vs-clean-code/blob/main/README.md
Most of the discussion focusses on the prime generators. A few thoughts:
- The disintegrated ‘Clean Code’ version is basically using function
names as comments, and some of them not much better than the “i++; //
add one to i” style rightly decried somewhere else in this
thread. They certainly don’t shed any light on how the algorithm
works.
- In contrast the single-method version has _no comments at all_.
Even a handful of comments explaining the purpose of each variable
would be a big step forward, although really it wants a higher-level
description of how this algorithm achieves its goals.
Both should be rejected.
As it happens some of the code I work with is responsible for finding
primes (or usually: two or three primes in a specific relationship to
one another), although rather larger than the ones here and using a
completely different algorithm. The code is somewhat decomposed, but not
to the extent of the ‘clean code’ version - iterating over candidates of
the right shape is separated from primality testing, etc.
While most of it was originally written by someone else, evolving
compliance targets and some associated code quality uplift meant it’s
had a lot of work done on it, and the first step was comments explaining
not just what the algorithm was but how each step contributed to the end
goals.
Incidentally, in C, when dealing with large integers, each arithmetic
operations is a function call; “Y=X+((R-X)%(2*r1*r2))” gets a lot
wordier when all the variables can be hundreds or thousands of bits
long. At that point it’s well worth comments that show how the result
builds up in more mathematical language. It’s not quite “i++; // add one
to i” but it isn’t actually that far off.
-- https://www.greenend.org.uk/rjk/