views:

73

answers:

4

Couldn't we write the design documentation for source code within the source itself? I suppose like Doxygen but with the focus taken away from implementation towards design. Essentially (and rather excitingly) you have a nice big chunk of markdown at the end of your source file.

Each time I create a new source file (and begin writing in its crisp white pages) I think to myself it would be nice if the first things written there were notes, thoughts and ideas; an exploration of what the module hoped/needed/dreamed to accomplish. Perhaps proximity to the source code will encourage more frequent and fervent attention to the documentation of it?

Or maybe I should be spending my time crafting self-documenting code.

A: 

Something I do a lot is that I first create an empty method stub and put the technical design in it as comment, fleshed out per line. Then, after each line of comment, I write the code that does what the design says.

tdammers
+1  A: 

You can do this - it's called Literate Programming, invented by Donald Knuth. As for self-documenting code, all I can say is that I've never seen any.

anon
+1  A: 

One problem with embedding the design in the source code is that the source layout / structure is probably too granular to be documented at a file level - that is covered by writing good, clean, self-documenting code. If you're a refactoring nut you may also have a lot of small files, and documenting each one is pointless (as reading all the notes would be very difficult).

That said, having a more general design note (readme) at the namespace / module / component level can be really useful - an "if I was seeing this for the first time what would I want to know" type of document, written in plain english, and with open questions, decisions etc. clearly noted down.

Hugo Rodger-Brown
A: 

Who says we don't?

Documentation XML or Doxygen documentation comments (e.g. on a class) are an ideal place to describe how a class works.

Historically the biggest problem with embedded documentation (stored in source files) is that it has to be text-based, making it difficult to write and read, especially where screenshots and diagrams are needed. However, with Visual Studio 2010 it is now easy to embed additional information into source code files (bitmap images, etc) so I think you'll soon see a few extensions appearing that allow you to embed wysiwyg documentation directly into the code.

In the meantime, for more complex documentation where screenshots and diagrams are needed, we simply store our documents in 'Docs' folders alongside the code - so if you wish to use an assembly, the overview/design of the assembly is given by versioned documents that sit right next to the code. That's not quite embedded in the source code, but it's always close to hand when you need it.

Jason Williams
Personally, I'm not a big fan of wysiwyg editors; I feel that the appearence of a document and its content should be separable as I am seldom thinking about one when I am working on the other. I've got to say I'm a little horrified that an IDE would provide the capability of embedding bitmaps in source code :) ... What happens when you open such a file in, say, a non-Microsoft product?But you're right, embedding the documentation in a separate directory in the repository is functionally identical to having it in the source code itself.
Will Baker
'WYSIWYG' documentation is more than just text styles - diagrams and pictures are often vital, which is when I resort to an accompanying .doc file. VS2010 has the *capability* to render this sort of external 'metadata' inline with code. If used well, documentation could be very usefully included into the source code *display*. That doesn't mean it needs to be stored *in* the source code. (It is a similar concept to mixing a disassembly and its source code - a very useful visualisation at times)
Jason Williams