Why do I care that the constant is "2"? I want to know what it
means/signifies. If it is "37" I'd care no more, nor less.
> The fact is you understood what I had written at a glance, otherwise
> you would not have complained.
I understood it because of the code. I saw "BNE" and recognized a
conditional branch. I saw a target address (label) indicating
the mnemonic YOU had selected to represent the "branch taken"
condition. And, the addition of another label for the "branch not taken"
condition. Hence, deduce "take branch for fcs32, else fcs16".
I don't need a comment for that.
> When your output is about 150-200kB of source text per month - as mine
> has been over the decades - I can only wish you good luck going
> back to code you wrote 10-20 years ago. There is no chance you can
> remember millions of lines, you read some of the old code as if
> someone else has written it.
The code I posted is almost 40 years old. If you had asked me (prior to
digging it up) how it worked, I would have said "a programmable timer
creates square waves that are filtered and amplified". That would
have been the extent of my recollection (and, I suspect if you'd
asked anyone a similar question they'd come up with a similar
GUESSTIMATE).
But, looking through the prose that I wrote, it was clear to me
how the timer was used, how notes were articulated, how I
generated the various constants for each note, how I generated
the "interpretive code" to play melodies, etc. Without
having to read through a series of half-line comments to
piece it all together.
> And I have managed to understand and modify it when necessary,
> so my writing style must be comprehensible.
To you. I can look at code I've written or hardware I've
designed and instantly recognize it as mine. I "know my style".
But, someone else has to be able to read mine -- because I'm
rarely the person who maintains my code.
And, I have to be able to read/understand/maintain code that
has been written by others. I've had to "patch" the code in
several FOSS projects to fix bugs or tweek it to my needs.
So, I'm frequently encountering stuff that has been written
by ??? And, the writer isn't available for me to query.
So, I have to read ALL of the comments "cautiously"; there's
no guarantee that they reflect what the code is actually doing
*or* what it was intended to do.
OTOH, the *code* tells me exactly what the CPU will be doing!
So, that's where my focus inevitably lies.
I think you've been working in a "sheltered" (poor choice of
words) environment for so long that you likely don't realize
what it's like to have to deal with other folks' code,
coding styles, discipline (or lack thereof), etc.
> OTOH I have tried to read disassembled code once or twice which
> obviously had no comments, it is incomparably harder, trust me.
But, it had *no* comments. Not even the blocks of prose that
I've added. Reading decomppiled code for which a symbol table
is available is considerably easier -- you know the names the
developer assigned to variables, functions, etc. If you have
something explaining what each function does, the role of
each variable, etc. you'd not need a "comment per line" to
understand the code.
In the past, I've had compiler vendors not provide sources
for "helper routines", libraries, etc. So, when I'd encounter
a bug in one of those, I'd have to decompile the code to
figure out why it was broken. All I know is the name of
the function (some of which may be documented as standard
library functions).
But, I could look through the machine code and reconstruct
what was happening (early compilers tending to be pretty poor
at optimization). Then, from the reconstructed code, figure
out how to patch the "source" to generate a new binary -- that
would work. Email a copy of the patched source to the
vendor and let HIM figure out how to merge my changes with
the "real" (though still hidden) sources.
>> Your description of what the code WILL be doing (before the code
>> body) would make that clear. "WHY would I want to take the fcs16
>> branch instead of the fcs32 branch? On what criteria would I base
>> that decision?"
>
> Or I could write it the way I did and be as efficient as I am.
> What now, do you want to compare your efficiency to mine.
You and Me don't matter. It's Bob and Elizabeth that we're
concerned with. Both how they can adapt to our particular
coding practices and how we can adapt to theirs.
>> The lack of space for per-line comments means you end up
>> adopting cryptic abbreviations so your comment will fit
>> in the space provided.
>
> Nonsense. I tend to fit things within 100 columns (an 800 pixels
> wide window) and very rarely do I have to extend a line
> comment to the line below. And no, my abbreviations are
> as cryptic as necessary, usually they fit within 8
> characters. The superlong-instead-of-a-comment C style
> labelling are impractical (as is C but this is a much longer
> story) for many reasons.
I fit things in 80 columns. I would rather have 10 windows
open on my screen (5K pixels wide) than one wide window
filled with text.
A statement in a HLL isn't as width-constrained as in ASM.
You can assume your "code" will only eat up ~30 columns;
the rest being available for comment. In a HLL, the
*statement* can span multiple lines. Adding a comment
just makes it more cumbersome.
Let the code explain what it's doing. Write a paragraph
above each "significant stanza" to put what follows into
a context that the reader can understand.
>>>> rts *return*
>>>>
>>>> REALLY??? Do you need to be reminded what RTS stands for??
>>>
>>> While I write this out of habit it can (and sometimes does)
>>> have a meaning. Although RTS stands for "return from subroutine"
>>> what it actually does is pull an address from the stack and go
>>> there.
>>> Sometimes this is exactly the most efficient way to *call* an
>>> address, not to return from something. For example, in 68k
>>> land, one might "push efective address" calculated somehow then
>>> do rts to *go* there.
>>
>> Yes. But, I would NOT document the "normal case" and would
>> only document the exception.
>
> So *why* would you skip the *return* comment, other than making it so
> much harder to spot the point of return on that page at a glance.
How does the comment make the "RTS" stand out? It's yet-another-comment
among a list of such comments.
Again, I say, if YOU are your sole/primary code-consumer, then you only
have to worry about making it easy/efficient for YOU to understand
what you've written.
I build tools that are solely for my own use. How I document them
and support them is entirely under my control -- and, my "problem".
OTOH, I have built tools for others to use. While I have the same
control over how I design/build them, I now have to ensure my
(user) documentation fits THEIR needs. I can't just throw error
codes and have them make sense of these. They won't be interested
in logged minutiae of what's going on inside the code. They want
to know how to *use* it and how to respond to the various types
of situations (which they haven't yet encountered) when they
occur WITHOUT HAVING TO TELEPHONE ME!
The same is true of designs (software and hardware). I could
leave each net in a schematic with it's "default" name
(NETxxxxx). The tools don't care that I've named it
"nChipSelect". And, the circuit will operate the same, regardless
of the representation in the schematic.
Signal names convey meaning to the (human) reader/viewer. If
I know how the circuit works, why bother adding this extra stuff?
Because "I" will likely not be the only consumer of that
documentation.
Labeling EVERY signal isn't necessarily "better". And, you
would likely end up with a mess that has others saying "why the
hell did you label the junction of R26 and Q18?"
OTOH, if it was the *only* such junction labeled, they might
see this as a hint to it having special significance (even
if just labeled as a "test point").
IMO, you want to give people the information they need to
understand a problem; no more and no less. If they don't
understand how a transistor works, there's no amount of
additional information you could add to the schematic to
help them!
Likewise, if they don't understand the instruction set of
the processor (and how the hardware works), then they
shouldn't be looking at the code.