5

Has anyone used the noweb literate programming tool on a large Java project, where several source code files must be generated in different subdirectories? How did you manage this with noweb? Are there any resources and/or best practices out there?

lindelof
  • 34,556
  • 31
  • 99
  • 140

2 Answers2

5

Noweb will dump out files relative to the current working directory, or at the absolute path you specify. Just don't use * at the end of your filename (to avoid inserting the # preprocessor directives). I would recommend using %def with @ to show where you define and use names.

<</path/to/file.java>>=
  reallyImportantVariable += 1;
@ %def reallyImportantVariable

noweb lets you reorder and (the real win) reuse snippets of code, which I don't think javac would understand.

I'd agree that since most people expect that you'll use javadoc, you're probably swimming against the stream to use noweb.

Jason Catena
  • 567
  • 4
  • 7
3

Literate Programming works its best if the generated intermediate code can point back to the original source file to allow debugging, and analyzing compiler errors. This usually means pre processor support, which Java doesn't support.

Additionally Literate Programming is really not necessary for Java, as the original need for a strict sequential order - which was what prompted Knuth to write a tool to put snippets together in the appropriate sequence - is not present. The final benefit of literate programming, namely being able to write prose about the code, is also available as Javadoc which allow you to put everything in as comments.

To me, there is no benefit in literate programming for Java, and only troubles (just imagine getting IDE support).

Any particular reason you are considering it?

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • 1
    For downvoters: I _have_ actually created real programs with noweb. – Thorbjørn Ravn Andersen Jan 25 '12 at 02:48
  • Note however, that noweb could be enhanced to utilize the same mechanism as the JSP-compiler uses (described in JSR-45 - https://jcp.org/en/jsr/detail?id=45) which would give the same behavior as the preprocessor give in C. Also the annotation processor added in Java 6 may also help. – Thorbjørn Ravn Andersen Apr 11 '17 at 21:07