Quote:
Slighty OT but....

I've never really understood why some people get majorly obsessive about commenting code - I don't know how many times I've heard "code without comments is bad".

Generally speaking, your code should speak for itself, if it isn't then there's something wrong somewhere! I know that in practice this isn't always possible, but when I come across a situation like this, a single line comment usually suffices.

Like above, giving variables and functions proper descriptive names is about the biggest favour you can give yourself and others who access the code.

Bad code is bad code, no amount of commenting is going to fix it!


I see it as the comments being a higher level to the code. It's not that people can't understand the code itself, it's just faster and easier to understand english than it is to understand any programming language. My philosophy is to be able to read the whole program like a book without looking at one line of code. "// Increment i" is too low level for that.

I used to use little tricks to make each line of code as small and as fast as possible, but in reality, for the average program you can't tell any difference when it runs on today's computers. I also used to find it amusing that no one else could read my code, until I started realizing that I couldn't read it either a week after I wrote it. Now, if it makes it easier to read I'll write a piece of code in several lines when I could do it in one. And now I sort of get a kick out of how easy it is to read my code.

Execution speed and program size are no longer top priorities. Readable and maintainable code is, because processers and hard drives are cheap, but a programmer's time isn't.