Literate Programming is based on three simple statements:
- Programmers must write code, which the computer can understand
- Programmers should write documentation, which people can understand
- If these are separate documents it is inevitable that they will be out-of-sync
Indeed, in my experience, #2 usually gets short shrift. I've lost count of how many times QA has told me "the doc says this, but the code does THAT; is the code incorrect or is the doc out-of-date?" I don't expect my workplace is out of the ordinary, in that respect. Additionally, in one of my early projects, I was trying to keep the docs up-to-date as the back-and-forth with the stakeholders resulted in changing requirements. This was sufficiently time-consuming that I was told, by management, to stop messing with the docs and just get the project working. We've gone to less-tedious documentation processes, since then (thank heavens!).
We have code review tools where, when we make a change to the code, multiple people can see the changes, clearly delineated, and comments can be made, asking questions, explaining stuff, offering improvements. If the code was written with Literate Programming techniques, much of this question/answer would be superflous because the explanation would be included.
Much of the mindset of modern programming is that your code should be its own documentation. Many pundits argue that, if you find yourself needing to explain your code in comments, you should probably reformat the code (changing variable/function names, etc.) such that the comments are unneeded. I find this to be great in theory, less practical in reality. I mean, when I'm using libraries created/maintained by someone else, their choice of method/function names isn't always intuitive to me. For example:
Set<String> statesWeCareABout = new HashSet<String>(Arrays.asList(new String[] { "one", "two", "three" }));
Set<String> statesWeFound = <some function>;
statesWeFound.retainAll(statesWeCareAbout);
If you aren't familiar with Set<> or HashSet<>, you may not know that .retainAll() means give me the intersection of the two, with the result in the modified Set<>.
Finally, Literate Programming usually lets you break things down so that you can explain this piece of code in isolation, then in-line it into this other piece of code. This is more in-line with how human comprehension works. Explain to me how this works, then build on that understanding to explain the larger picture. Computers don't really care; you can write a single function with 1,000 lines of code and it has no problem comprehending the whole thing. God help you if you, as a developer, have to maintain that.
And that, really, is the reasoning behind Literate Programming. Code will need to be maintained, whether it's bugs being fixed or features being added. And if it can't be comprehended by someone else, later on, in an efficient fashion, it will be replaced. There is way to much "write only" code in this world. Literate Programming makes it easier to read and comprehend, which makes it more likely to be kept and used, long-term.
And do we really have time to keep re-inventing the wheel?