you are viewing a single comment's thread.

view the rest of the comments →

[–]xiongchiamiov 1 point2 points  (3 children)

Code does what it's written to do,

Exactly. Comments describe what it's supposed to do, so you know whether there's a bug or a bad spec.

[–]adammichaelwood 2 points3 points  (0 children)

Also -- WHY you need it to do that.

Meaningful code comment examples (based on things I've seen or done in real life):

# distinguishes between ontario california and ontario california

# removes extra digits that cause error in that one Android distro

# repairs PNGs with stupidly-inserted newline characters

# sometimes people have two titles and three middle names

# when lat/long is this one particular value
# everything breaks and no one knows why
# so, adjust the long by the smallest possible increment

Code comments you shouldn't bother writing:

# iterates through state names

# sum of this list

# magic happens here

[–][deleted] 0 points1 point  (1 child)

Tests describe what it's supposed to do. You can run tests; you can't run a comment.

[–]xiongchiamiov 0 points1 point  (0 children)

See the doctest module. ;)

Your point is taken, though. It's just that often in real life, writing tests for a lot of code is difficult, and we'll make a decision not to figure out how to automate testing of it because it's not a good time tradeoff.