Skip to content

Commit 76dd708

Browse files
committed
add example for comment rules
1 parent b38e579 commit 76dd708

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

Diff for: README.md

+34-9
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ important” [[PEP8]](#user-content-references).
6464

6565
Do not blindly follow this guide but think for yourself. The goal of
6666
software development is keeping the code complexity low. Period. None of
67-
the fancy patterns matters if the code becomes impossible to maintain.
67+
the rules and fancy patterns matters if the code becomes impossible to maintain.
6868

6969

7070

@@ -147,9 +147,9 @@ dashboard.show( warnings )
147147
</td><td>
148148

149149
```python
150-
Sys.test():
151-
Engine.test():
152-
SparkPlug.test():
150+
sys.test():
151+
engine.test():
152+
sparkPlug.test():
153153
testIgnition()
154154
```
155155
</td></tr>
@@ -281,7 +281,7 @@ Int totalIncome(employee){
281281
&nbsp;
282282
## [Naming](#user-content-naming)
283283
284-
Code should communicate behavior to other humans with lower complexity than the behavior it inherits. Abstracting with meaningful names is therefore most important for readability.
284+
Code should communicate behavior to other humans with lower complexity than the behavior it inherits. Since code mostly consists of custom names, your ability to abstract concepts with meaningful names is most important for readability.
285285
286286
287287
@@ -341,7 +341,7 @@ for idx, score in scores:
341341

342342
### Use word pairs (opposites, antonyms).
343343

344-
If you `start` something, you should `stop` it and not `end` it [[CdCm]](#user-content-references).
344+
If you `start` something, you should `stop` it and not `end` it [[CdCm]](#user-content-references).
345345
While most opposites can be created by using `un-` or `de-` prefixes (`lock/unlock`), some are more distinct and allow code alignment:
346346

347347
Verb pairs with same length:
@@ -420,16 +420,41 @@ English is the language of programming, so documentation should also be in Engli
420420

421421

422422

423-
### Write brief comments of high quality.
423+
### Write few brief comments of high quality.
424+
425+
Choose your words carefully and comment only what the code cannot say, that is *why* you did it, maybe *what* you did, but never *how*.
426+
Change comments when code changes because “comments that contradict the code are worse than no comments” [[PEP8]](#user-content-references).
427+
428+
429+
<table>
430+
<tr><td><strong>Bad ❌</strong></td><td><strong>Better ✔</strong></td></tr>
431+
<tr>
432+
<td>
433+
434+
```python
435+
if t.h > NIGHT_H: # Check if night
436+
if ifr.sense(): # detect person
437+
turnLightOn() # set Pin 13
438+
lockLight(TIMEOUT) # TIMEOUT=5s
439+
```
440+
441+
</td><td>
442+
443+
```python
444+
if (isNightTime() and isPersonPresent()):
445+
turnLightOn()
446+
lockLight(TIMEOUT) # avoid flickering
447+
```
448+
449+
</td></tr></table>
424450

425-
Comment only if necessary and choose your words carefully. “Comments that contradict the code are worse than no comments” [[PEP8]](#user-content-references). Change comments when code changes. Comment only what the code cannot say, that is *why* you did it, maybe *what* you did, but never *how*.
426451

427452
Further Don'ts:
428453

429454
* Don't commit commented-out code. Just remove.
430455
* Don't create headings with `S E P A R A T E D` letters because you cannot search for them.
431456
* Don't assume insider knowledge but write simple comments for anybody on the planet.
432-
* Don't make jokes in comments. Tell them in person.
457+
* Don't make jokes or use cute language.
433458
* Don't comment closing braces. They just indicate that your blocks are too long.
434459

435460

0 commit comments

Comments
 (0)