text
stringlengths
0
444
# good
# BuggyClass returns an internal object, so we have to dup it to modify it.
x = BuggyClass.something.dup
# This is algorithm 6.4(a) from Worf & Yar's _Amazing Graph Algorithms_ (2243).
def compute_dependency_graph
...30 lines of recursive graph merging...
end
----
=== English Comments [[english-comments]]
Write comments in English.
=== Hash Space [[hash-space]]
Use one space between the leading `#` character of the comment and the text of the comment.
=== English Syntax [[english-syntax]]
Comments longer than a word are capitalized and use punctuation.
Use https://en.wikipedia.org/wiki/Sentence_spacing[one space] after periods.
=== No Superfluous Comments [[no-superfluous-comments]]
Avoid superfluous comments.
[source,ruby]
----
# bad
counter += 1 # Increments counter by one.
----
=== Comment Upkeep [[comment-upkeep]]
Keep existing comments up-to-date.
An outdated comment is worse than no comment at all.
=== Refactor, Don't Comment [[refactor-dont-comment]]
[quote, old programmers maxim, 'https://eloquentruby.com/blog/2011/03/07/good-code-and-good-jokes/[through Russ Olsen]']
____
Good code is like a good joke: it needs no explanation.
____
Avoid writing comments to explain bad code.
Refactor the code to make it self-explanatory.
("Do or do not - there is no try." Yoda)
== Comment Annotations
=== Annotations Placement [[annotate-above]]
Annotations should usually be written on the line immediately above the relevant code.
[source,ruby]
----
# bad
def bar
baz(:quux) # FIXME: This has crashed occasionally since v3.2.1.
end
# good
def bar
# FIXME: This has crashed occasionally since v3.2.1.
baz(:quux)
end
----
=== Annotations Keyword Format [[annotate-keywords]]
The annotation keyword is followed by a colon and a space, then a note describing the problem.
[source,ruby]
----
# bad
def bar
# FIXME This has crashed occasionally since v3.2.1.
baz(:quux)
end
# good
def bar
# FIXME: This has crashed occasionally since v3.2.1.
baz(:quux)
end
----
=== Multi-line Annotations Indentation [[indent-annotations]]
If multiple lines are required to describe the problem, subsequent lines should be indented three spaces after the `#` (one general plus two for indentation purposes).
[source,ruby]
----
def bar
# FIXME: This has crashed occasionally since v3.2.1. It may
# be related to the BarBazUtil upgrade.
baz(:quux)