- Feb 8, 2004
- 12,604
- 15
- 81
Has code to be so readable that it shouldn't require comments? Is that the general view in the industry?
Has code to be so readable that it shouldn't require comments? Is that the general view in the industry?
I comment my code a lot, most every line. Why not comment it while you know what you are trying to do? Compiler takes it out so no slow down in executable.
You or somebody will be happy in a few years when something needs to be changed or fixed.
// Get dataset with customer info
DataSet custInfo = SomeClass.GetCustomerInfo();
+1There's a fine line. Tons of comments can make the code very hard to read. I don't need comments on each line. Can they be helpful and explanatory? Sure. But code needs to be readable and comprehensible, and if you need to comment every line in order to make what you're doing clear, something must be wrong. I typically write comments in the flowerbox before a method if the method does something unintuitive (but I try not to write unintuitive methods to begin with), and will occasionally write them in the body of a method if something really needs explaining, but those are rare. When I do have comments in the method body it's most often to mark something that is temporary, or a to-do, etc.
// Get account information
Account->GetAccountInformation()
// Querying the account information to determine if the account has an email flag required to send out a notice.
Account->GetAccountInformation()