Re: DRY way to insert source code into an article?

"John Hughes" <[email protected]>
Newsgroups gmane.comp.programming.language-of-the-year
Message-ID <D03E11CDE0B64FF488F6D4B8ECC58CC2@HallDesktop>


  Hi all,

  I'm starting to write articles about programming and I'd like to
  include source code snippets into my article. My strategy was to get
  the source code examples working, then annotate sections of code which
  should be imported into the body of the article. The goal here was to
  avoid copy-paste problems of putting incorrect or stale source code
  examples into the document.

  How do other pragmatists approach this problem? 




   .

I generally use a very simple home-grown tool generating LaTeX or HTML (I like to tweak!). Whether I put LaTeX in the comments in my source code, or source code in my LaTeX for extraction by my tool, depends on the kind of document I'm writing.

Something I've found very useful when doing this with Haskell is to build in the ability to run examples while rendering the document. When I include an example in the text, it's automatically compiled and run, and the output pasted back into the document, every time the document is generated. I've found many, many mistakes because the example output was actually an error message!

Haskell's "calculator"-style interface makes this particularly easy to do, but I'm sure you could adapt the idea to Java.

John Hughes
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.