Skip to content

Commit c2ab104

Browse files
wrsbbatsov
authored andcommitted
Add rationale-comments
1 parent 2a50dfa commit c2ab104

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,6 +2486,31 @@ condition](#safe-assignment-in-condition).
24862486
Write self-documenting code and ignore the rest of this section. Seriously!
24872487
<sup>[[link](#no-comments)]</sup>
24882488
2489+
* <a name="rationale-comments"></a>
2490+
If the *how* can be made self-documenting, but not the *why* (e.g., the
2491+
code works around non-obvious library behavior, or implements an algorithm from
2492+
an academic paper), add a comment explaining the rationale behind the code.
2493+
2494+
```ruby
2495+
# bad
2496+
2497+
x = BuggyClass.something.dup
2498+
2499+
def compute_dependency_graph
2500+
...30 lines of recursive graph merging...
2501+
end
2502+
2503+
# good
2504+
2505+
# BuggyClass returns an internal object, so we have to dup it to modify it.
2506+
x = BuggyClass.something.dup
2507+
2508+
# This is algorithm 6.4(a) from Worf & Yar's _Amazing Graph Algorithms_ (2243).
2509+
def compute_dependency_graph
2510+
...30 lines of recursive graph merging...
2511+
end
2512+
```
2513+
24892514
* <a name="english-comments"></a>
24902515
Write comments in English.
24912516
<sup>[[link](#english-comments)]</sup>

0 commit comments

Comments
 (0)