Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^6: On comments

by mr_mischief (Monsignor)
on Dec 29, 2010 at 09:01 UTC ( #879588=note: print w/replies, xml ) Need Help??


in reply to Re^5: On comments
in thread On comments

I agree with you about commenting being the exception rather than the rule. I also agree with comments being small, seldom, and to the point being helpful. I also see the advantage to sometimes using a higher-level programming language to comment a lower-level one. However, I don't see how using a higher-level language rather than English prose would help in every case.

I don't see, for example, restating the code helping someone to understand why it is important to zero-fill or zero-extend the high 32 bits of a 64-bit register when working in 32-bit mode on a hybrid 32-bit and 64-bit machine for security purposes. An explanation of why something is done really doesn't come from doing it again in a different way. When you really must explain why, explaining how does no help. Hardware vagaries and minute details of domain knowledge can be restated in many programming languages, but the reasoning behind the code is still a separate thing from the code itself.

Replies are listed 'Best First'.
Re^7: On comments
by BrowserUk (Pope) on Dec 29, 2010 at 12:17 UTC
    However, I don't see how using a higher-level language rather than English prose would help in every case.

    Definitely not "in every case". And to be honest, these days I'd use a good macro assembler (directives .while etc.) to code most loops, branches and procedures, which does away with the need for the HLL "description". But back then, the assembler did little more than translate the opcode mnemonics to binary, and perform (non-nested) branch calculations.

    Your 'security reasons' is an example(*) of when you should (ie. I would) justify breaking my basic "Don't comment." stance. It is a clear case of the exception that proves the rule.

    My "Don't comment" stance has a similar power to simplify and clarify, as modern moves in governments to switch from 'Everything is secret unless we say it is not' to 'Nothing is secret unless we say it is'. There is no intention to endanger people or things by giving away everything.

    Just a desire to ensure that (costly) security efforts to be concentrated upon those things that need it. Oh, and if by-the-by, it prevents a few politicians and civil servants from hiding their laziness, gross incompetence or worse, behind layers of "need to know", so much the better.

    And that's my take on comments. If you've justified the addition of a comment in a piece of otherwise sparingly commented code, you can bet your bottom dollar I am going to give it my full attention.

    But by my reckoning, there are about 7 or 8 significant comments in this, but I challenge anyone to find them in a hurry, so lost are they in a morass of unnecessary, irrelevant or downright misleading thoughts, feelings, opinions and speculations.

    (*)It is hard to tell from such a brief description of a real situation, but I actually, I still might not comment it. From my interpretation of your description, I would probably opt for self-documentation in the form of a macro: Say SEC_reg-zero <reg>; or SEC_reg-signExtend <reg>; and the detail of the security implications would be detailed once in the macro definition.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      If you've justified the addition of a comment in a piece of otherwise sparingly commented code, you can bet your bottom dollar I am going to give it my full attention.

      ++ Increasing verbosity --> decreasing attention.

        ++ Increasing verbosity --> decreasing attention.
        Yeah, that's why you should always golf your production code, then it gets the most attention from the person maintaining it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://879588]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2021-04-20 06:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?