How to Write Comments
Denis Krukovsky writes "Should I write comments? What is a good comment? Is it possible to comment a class in 5 minutes? See "
Everybody knows that good code is self documenting- which is why my prof in college demanded we write in Ada. I instead suggest commenting in haiku.
Problem with Slashdot comments is like code comments... too few is bad, too much is bad. // This line outputs the result
How many times can we see a line like this... that's just writing comments without any reason.
I prefer function header comments which describe what the piece of code as whole does. Not everyline, as teachers say it should be done.
Here's the original code:
L = Cholesky(cov0);
th1 = L.i() * th0;
lrt = (th1.t() * th1).Trace();
which is supposed to compute the same answer as the code:
lrt = (th0.t() * cov0.i() * th0).as_scalar();
I do agree that in general code should be self-documenting when possible, but sometimes you need a few lines of comments to explain a single line of code, or a few paragraphs of comments to explain a few lines of code. I added 17 lines of comments to that part of the program to explain 3 lines of code.
What a fool believes, he sees, no wise man has the power to reason away.
Some comments I've written:
Here the purpose of the comments is to explain the math.
All code should have well-written comments. As Wirth pointed out years ago, people who can't express themselves well in their native language are generally poor programmers.