arborint wrote:I definitely prefer unit tests and almost not comments (except for what is needed by a documentor). I have two problems with comments:
1. Comments are mostly useless and just obscure the code.
2. Comments just increase the amount of text that has to be maintained because they have to be updated whenever the code is changed.
As to hypothetical "application with thousands of lines without comments" I really don't see how comments will help you grasp what a 1000 lines of code do. Use cases, unit tests and examples maybe, but not comments.
Although I can agree, that in an HLL like PHP, comments are less nessecary than say assembler, in which case their absolutely essential...I cannot agree that they are completely useless.
Perhaps in everyday business logic, using properly named variables and function names, etc, one could deduce the meaning of non-commented code, but I am sure there are instances which would stump even the most seasoned developer without the use of comments in source code or at least slow him/her down while they dig through docs, etc...
Deeply nested recursive functions or esoteric binary operations when used in conjuction with complex nested loops and if statements are not easily decoded even with all the tools of trade and comments included, as well as articles and documents explaining an algorithm, nevermind without comments.
Comments are not intended to give anyone an overall picture of a system or class or whatever, their used to quickly grasp non-trivial concepts which may not fit well in the domain of documentation or be indicated at all in automated tools like unit tests, flow chart generators, etc...
I agree that there are many ways to help describe code:
- Call graphs
- API documents
- Flow charts
- Unit Tests
And so on....each of which does a good job helping decode...the...meaning...of...code
However, IMHO, there is a difference between understanding a system overall and being able to make atomic changes. The latter is where comments usually come in handy and everything else would likely fail.
I understand that commenting is personal choice, but for you to say mostly useless is an understatement...
Perhaps when programming languages resemble natural language more than they do an artificial syntax of such, perhaps then, we can do away with comments all togather, but until that day, I'm afraid I personally advocate the use of comments.
Besides, there are editors which allow you to hide "most" of your comments using source folding...
Wow

I can't believe I put that much energy into defending my stance on use of comments
My apologies for the boring rant

*ducks under desk*
Cheers
