in reply to Re^4: knowing your audience
in thread Programming *is* much more than "just writing code".

... read the comments and decided if they matched the code.

And that's exactly what is wrong with relying upon comments to make your code understandable.

Comments cannot be tested.

If I have to mentally run the code in order to decide if (my interpretation of) your comments seems like maybe, could be, if I squint and ignore the typos and grammatical errors and constant changes between first and third person narrative, might actually be correct, then I what? Save myself the effort if having to read the code.

What else?


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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^6: knowing your audience
by Rhandom (Curate) on May 09, 2007 at 17:16 UTC
    You are right. Comments cannot be tested. So skip the comments. You've still either wasted your employer's time by refactoring everything when you didn't need to (unless your employer intentionally pays you to work the way you do) or you have annoyed your coworkers by making their code conform to your style.

    You are right. Comments cannot be tested. That doesn't mean they cannot be trusted. All of human based language cannot be directly tested by a computer for validity. That doesn't make it less valuable. If this thread really boils down to you not trusting a human developer's comments - that is great - I am sorry for belaboring the issue.

    If grammatical issues are the driving force for this thread, well I can't help you there because my prose and the comments of most other programmers are full of errors. Somehow most people cope. Code often has style or "grammatical" errors that are not syntax errors. Somehow the computer copes as well.

    I do trust comments while I am reviewing somebody else's code for general functionality. I find that when properly done, comments provide a good 30000ft view. If I am doing code review then I look closer and start to evaluate the expressions in context of the comments, but with a little more scrutiny. But when I need to fix a bug I generally ignore comments - not because I don't trust them, but because I have found I can isolate the problem more quickly with other tools and techniques. But I will still be glad when the comments are there because they have previously and will potentially give insight into what some obscure code was intended to do.

    I hate the term "agree to disagree," but I think we must.

    my @a=qw(random brilliant braindead); print $a[rand(@a)];
Re^6: knowing your audience
by doom (Deacon) on May 09, 2007 at 16:57 UTC
    And that's exactly what is wrong with relying upon comments to make your code understandable.

    Comments cannot be tested.

    Sure they can. You read them and see if they work, i.e. increase your understanding. If they don't, then you need to fix them -- that's actually part of the job of a maintenance programmer. Though you should probably also ask yourself if they might increase the understanding of someone else working on the code (introspection alone isn't enough).

    (Note that if you're really in the habit of developing patches with copies of code with comments stripped, then when you port your fixes back to the original, there's a real danger that you're going to introduce code that's not in sync with surrounding comments... you're punting on the problem of communicating with future programmers).

      Sure they can. You read them and see if they work, i.e. increase your understanding.

      Hmm. A comment that might increase my understanding when I write it, may not do so for your understanding when you read it.

      It might help Fred, and leave Bill cold, whilst leading Harry right off down the garden path. It all comes back to the imprecision and variablility of interpretation of natural language. And that's before we get into the realms of social and cultural differences.


      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.

        Hmm. A comment that might increase my understanding when I write it, may not do so for your understanding when you read it.

        It might help Fred, and leave Bill cold, whilst leading Harry right off down the garden path. It all comes back to the imprecision and variablility of interpretation of natural language. And that's before we get into the realms of social and cultural differences.

        Yes, precisely. Working with other human beings is a pain, isn't it? Everywhere you turn, you're stuck with a certain amount of imprecision, even in questions like "does this code work?".