News for hackers. Stuff that matters.
Re:Does anyone use comments any more? by greenmanmax on Friday July 06, 2012 @03:58AM (#4206821)
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"?
Re:Does anyone use comments any more? by robomartin on Friday July 06, 2012 @04:34AM (#4206914)
Of 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.