You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/03-code-quality/03-comments/article.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ complex;
18
18
code;
19
19
```
20
20
21
-
But in a good code the amount of such "explanatory" comments should be minimal. Seriously, a code should be easy to understand without them.
21
+
But in good code the amount of such "explanatory" comments should be minimal. Seriously, code should be easy to understand without them.
22
22
23
23
There's a great rule about that: "if the code is so unclear that it requires a comment, then maybe it should be rewritten instead".
24
24
@@ -113,7 +113,7 @@ function addJuice(container) {
113
113
114
114
Once again, functions themselves tell what's going on. There's nothing to comment. And also the code structure is better when split. It's clear what every function does, what it takes and what it returns.
115
115
116
-
In reality, we can't totally evade "explanatory" comments. There are complex algorithms. And there are smart "tweaks" for purposes of optimization. But generally we should try to keep the code simple and self-descriptive.
116
+
In reality, we can't totally avoid "explanatory" comments. There are complex algorithms. And there are smart "tweaks" for purposes of optimization. But generally we should try to keep the code simple and self-descriptive.
117
117
118
118
## Good comments
119
119
@@ -146,7 +146,7 @@ Document a function usage
146
146
Also, there are tools like [JSDoc 3](https://github.com/jsdoc3/jsdoc) that can generate HTML-documentation from the comments. You can read more information about JSDoc at <http://usejsdoc.org/>.
147
147
148
148
Why is the task solved this way?
149
-
: What's written is important. But what's *not* written maybe even more important to understand what's going on. Why is the task solved exactly this way? The code gives no answer.
149
+
: What's written is important. But what's *not* written may be even more important to understand what's going on. Why is the task solved exactly this way? The code gives no answer.
150
150
151
151
If there are many ways to solve the task, why this one? Especially when it's not the most obvious one.
152
152
@@ -158,7 +158,7 @@ Why is the task solved this way?
158
158
Comments that explain the solution are very important. They help to continue development the right way.
159
159
160
160
Any subtle features of the code? Where they are used?
161
-
: If the code has anything subtle and counter-obvious, it's definitely worth commenting.
161
+
: If the code has anything subtle and counter-intuitive, it's definitely worth commenting.
162
162
163
163
## Summary
164
164
@@ -172,7 +172,7 @@ Good comments allow us to maintain the code well, come back to it after a delay
172
172
- Function usage.
173
173
- Important solutions, especially when not immediately obvious.
174
174
175
-
**Evade comments:**
175
+
**Avoid comments:**
176
176
177
177
- That tell "how code works" and "what it does".
178
178
- Put them only if it's impossible to make the code so simple and self-descriptive that it doesn't require those.
0 commit comments