DEV Community

Discussion on: Best Practices for Code Documentation and Comments: A Guide for Budding Programmers

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ • Edited

Might want to revise the examples somewhat. In section 2, this is 'good':

# Increment the total score by 1
total_score = total_score + 1
Enter fullscreen mode Exit fullscreen mode

Then in section 4, this is marked as 'bad':

# This line increments the counter by 1.
counter = counter + 1
Enter fullscreen mode Exit fullscreen mode
Collapse
 
raulferreirasilva profile image
Raul Ferreira

I ended up noticing it and was confused about it too. But the rest of the content is very good, thank you for sharing 🦀.

Collapse
 
alinp25 profile image
Alin Pisica

I pretty much think that he meant it based on the variable's name. In the first example, section 2, total_score is pretty self explanatory by its name, while in the second example you gave, in section 4, counter is not so easy to understand in terms of goals and where it is used (what does it count? apples?), but the comment would give an overview over the fact that it counts the total number of occurrences (as mentioned in the article).

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ

I don't think so. The article is about comments, not variable naming. The comments shown here give no more information about the variables' content - they just repeat the name.

Thread Thread
 
montyharper profile image
Monty Harper

The article is about documentation, which encompasses both comments and variable naming. Also, I took each example to be illustrative of a particular point. In point 2, the example went from "bad" to "good" by providing context, while both versions happen to be redundant. In point 4 the example went from "bad" to "good" by removing redundancy. In both cases the code could be further improved by applying both principals. In point 2 the "good" example could be made even better by dropping the comment altogether to remove the redundancy. In point 4 the "good" example could provide even more context with a better variable name (in which case a comment may not be needed), or a more specific comment (occurrences of what?). But I believe the author's intent was to create examples that focus on one issue at a time.

Thread Thread
 
saloman_james profile image
James saloman

Got my point..