Liste des Groupes | Revenir à col misc |
In alt.folklore.computers Dan Cross <cross@spitfire.i.gajendra.net> wrote:In article <vB5xP.126521$eNx6.22176@fx14.iad>,>
Charlie Gibbs <cgibbs@kltpzyxm.invalid> wrote:[snip]
Oh, and anyone who modifies code without updating the
corresponding comments to reflect the change deserves
some sort of nasty punishment. Maybe we can make them
maintain any other programs whose comments have become
outdated and misleading.
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
I read large part of this tekst. I fully agree with John's
critique of decomposed PrimeGenerator. Personally I find
the Knuth-based pre-decomposed version the clearest one:
- it is obviously correct once one gets loop invariants
- it is compact enough that loop invariants can be easily guessed.
>
I was able to understand this version in few minutes. Reference
to Knuth helped, because first (decomposed) version looked like
a monster which raised serious doubts about correctness and
efficiency, Knuth name assured me that this may be worth looking at.
I have some interest in generating primes and it is possible that
I saw this method before. Certainly I did not remember it.
So more remarks: testing divisibility only by numbers smaller or
equal to square root of candidate is standard obvious trick.
I it not clear how long it would take me to invent such thing,
but I saw it long ago and once I saw it it was obvious.
>
I correctness of John's version is more tricky: we should
increase number of primes used for testing once candidate
becoms equal to square of next prime. John uses different
looking condition and gives no justification that it is
equivalent to the correct one.
>
Part of the comment
>
: // ..........................(all elements after this are greater
: // than our current candidate, so they don't need to be considered).
>
is misleading: those elements are greater then _square root_ of
the candidate.
Concerning comments I am mostly on Martin's side. More precisly,
interfaces should be precisely specified. In some cases (like
math problems) code implements "well known" functions and then
there is not much to say (but things like limitations on arguments
and precision should be spelled out). In other cases one needs
to define appropriate terms and give more detail. OTOH
implementation in many cases needs no comments. In other case
one may want rather extensive description of method/algrorithm/
data structures. IMO extensive description if best provided
in a separate document. In case of standard algorithms one
can simply add reference to the literature. If something is
non-standard (new), then there should be a document describing
it. My point is that comment is not good place to put such
extensive description (for example there are typographic
restrictions) and, once person is familiar with the problem
large block of comments is only a distraction. Also, I have
much more faith in estabished texbook or paper in peer reviewed
journal, then in comments which frequently say a lot about
lack of understanding of person writnig the comment and only
a little about actual problem. There are cases when comments
are worthwile, but they are relatively infrequent. In particular
in modern times we have a lot of trivial code and when we
come to something nontrivial it is frequencly so complex that
one can not reasonably explain it in a comment.
Les messages affichés proviennent d'usenet.