views:

112

answers:

5

I'm finding comments on code starting to get annoying. I feel that once you achieve some level of expertise, code is pretty much self documenting. But comments are still a necessity. What I would like to know if there's such a plugin or IDE with this idea of comments separated from the code. If such a thing doesn't exists, what ideas do you think would work great on a plugin for an IDE like Eclipse?

Take this Python code for example:

def do_something(self, var):
    # * 541
    ...

Then some XML like this:

<comments>
 <comment id="541" file="x.py" line="14">This is a comment</comment>
<comments>

Thanks!

A: 

Donald Knuth explored this topic heavily under the title of "literate programming" (which is a fine starting point for Googling). He wrote a program called Weave (or was it Web?) and Tangle which does something like what you ask, but for Pascal code.

I'm afraid the idea never got very far off the ground and I've never heard of anything similar for Python.

These days, there's a community of programmers who believe in writing short methods with names and variable names sufficiently descriptive to make comments (usually) unnecessary. The rest of us just plod along and comment the way we've always done.

UPDATE

I lied! There's something called PyLit, here: http://pylit.berlios.de/literate-programming/index.html . Also, a pretty extensive discussion of the whole thing.

Carl Smotricz
So far as I can see literate programming is the exact opposite of what is being asked for (IMHO: Good:-) in that it expects the combination of code and comments to be a readable whole.
djna
There's at least two Python options then, if you count http://en.wikipedia.org/wiki/Leo_%28text_editor%29 the Literate Editor with Outlines.
Peter Hansen
There is also the Leo editor for literate programming - written in Python, and has support for programming in Python amongst other languages.http://webpages.charter.net/edreamleo/front.html
Dave Kirby
+2  A: 

Good comments add information, such as why, they don't repeat code, so I don't agree with the premise of the question.

However, to go along with the idea for a moment, I can imagine an IDE that hides comments while you are editing, but storing them separately is a recipe for confusion.

djna
Self documenting code is a real thing and it has nothing to do with repeating code in the comments. Its about using conventions to make the why known without the need for as much commenting. Not saying come commenting is not necessary, just less of it.http://en.wikipedia.org/wiki/Self-documenting
MitMaro
"come" == "some" in my comments.
MitMaro
I'm responding to the original questions: "I'm finding comments on code starting to get annoying." - I contend that good comments should not be annoying because the illuminate. I do agree that good naming and structure can greatly reduce the amount of comment. I'm unconvinced that complete self-documentation is possible.
djna
+2  A: 

Don't forget that good comments explain intent and consequences, not literally what the code is doing.

Having said that, have you looked at code folding within IDEs ? Eclipse (for one) will collapse comments and hide them. You can reveal them at the press of a button. The comments remain in the code and tied to the relevant sections without any indirection (as you're proposing) so you can view them in any editor/environment.

Brian Agnew
+5  A: 

I've never heard of such a thing as externalized comments, and I think they'd be slow or easily corrupted, because they'd always have to be updated to stay in sync with the code. Furthermore, if your idea is to completely eliminate them from your view while you're working on your code, you could forget to update them and they could become inaccurate.

A feature you should look into is code folding. Instead of separating the comments into a different file, they're collapsed into a smaller space when you don't want to look at them. Many IDEs implement it (eclipse is one).

cosmic.osmo
Folding is definitely good advice. But I'd like to warn users of it they they might end up forgetting to update comments when they change code.
Christian
+1  A: 

A quick fix that will work with most editors is to change the syntax highlighting colour scheme to make the comments invisible or barely visible, e.g. light grey text on white background.

If your editor supports multiple colour schemes then you could have one that hides the comments and one that hides everything except comments, then swap between them.

Dave Kirby
Hooray for low-tech solutions! :)
Carl Smotricz