3 ms·
Hi, (robo)Martin, My opinion on comments is, that they are extremely useful for functions, classes (f.e. javadoc). It is essential to know, what a part of code
by greenmanmax 14y ago
Hi, (robo)Martin,
My opinion on comments is, that they are extremely useful for functions, classes (f.e. javadoc). It is essential to know, what a part of code does.
In the function body, I think it is much more important to use meaningful variable names. I mean: Do I really have to comment a variable like "numberOfUsers" with a statement "The number of users"?
- robomartin 14y agoOf course, variable names need to be really descriptive. And, no, they don't each need a comment. Here's an example, in a recent app I had to slice an image based on a given number of rows and columns. The variables were named: int image_rows; int image_columns; The actual code, with comment, went something like this: // These variables will determine how the image is sliced. // They are bounds-limited in code to max values imposed by hardware and // defined in configuration_settings.h int image_rows; int image_columns; A year from now I won't need to read far into the code to understand what they do.