I like literate programming in theory but the most common response I see to it is that writing self documenting code is better because as you are working on a code base with many people, it is unlikely they will keep your prose up to date as the code is changed.
Literate programming is much more than just commenting code
61–70 of 112 posts
Re: Literate programming is much more than just commenting code
#62Unfortunately, machines have a different way of understanding code than humans.
Re: Literate programming is much more than just commenting code
#63It would be great if IDEs supported literate programming; the tangle/weave commands, simple as they are, create many possible points for navigation. An IDE would be ideal to go back and forth from the prose to the code.
If you are wanting to just do cweb, then the debugging symbols already let you step through the source line by line without having to look at the tangled source.
Re: Literate programming is much more than just commenting code
#64I have always felt a literate program is probably for many of us, a future deliverable on the hack we've implemented up front. Very very few people can start from the abstraction and get TO a literate outcome without a lot of false steps along the way. Or, as an alternative, the LOC of a literate program has to include the 100x cost of exploring how to carve it out of the block of mud we start from, including making…
>Very very few people can start from the abstraction and get TO a literate outcome without a lot of false steps along the way. But don't writers face the same issue with their text? Am I the only one who writes more code than what ends up in a PR? Isn't that exactly what the Git history is for?
Re: Literate programming is much more than just commenting code
#65First, in a printed book, it is easier to find a previous page and compare a fragment on it with the current fragment. Second, a printed book has no links tempting you with the words "CLICK ME" to disrupt the flow so you can read it from cover to cover with fewer distractions. Third, anecdotally, I can see flaws much easier on a printout than on screen, both in programs and in texts.
Re: Literate programming is much more than just commenting code
#66The problems one will run into with literate programming: 1. Lack of tooling. 2. Refactoring becomes nontrivial 3. How one would write a program in literate style will vary widely from person to person. If you write your code in literate style, it may be easy for you to follow it years later and modify it, but it likely will not be the case for a coworker. If they have to modify the code, the cognitive load will not…
Problems 1 and 3 I could imagine. I would need to learn how to be a better writer to share a literate program. As someone experienced in the topic, What's the biggest hurdle when trying to refactor the code?
It's simply more work - but that "more work" is vitally important, tedious, and resistant to any kind of automated help.
Re: Literate programming is much more than just commenting code
#67Sometimes when you are writing an article it may make sense to write LP-like snippets of code like
int my_function() {
// Initialize variables
return 0;
}
but you don't really need to invent the whole "literate programming" concept to do this and you don't need to write all of your code like that.Re: Literate programming is much more than just commenting code
#68I like literate programming in theory but the most common response I see to it is that writing self documenting code is better because as you are working on a code base with many people, it is unlikely they will keep your prose up to date as the code is changed.
The problem with self documenting code is that it doesn't help justify all of the parts into the whole. This is particularly troublesome in code where a refactor effectively isolated entire sections of the code, but the person that did the refactor didn't realize it, and now you have code that exists only for the sake of existing tests.
My role of thumb is that if it's not obvious why that particular line is there and removing it would break functionality, add a comment.
Re: Literate programming is much more than just commenting code
#69Re: Literate programming is much more than just commenting code
#70IMHO, attempts to show literate programming on screen are doomed to meet with mediocre success. DEK invented literate programming with printed books in mind. I dare say that the only successful literate programs are books printed on paper. First, in a printed book, it is easier to find a previous page and compare a fragment on it with the current fragment. Second, a printed book has no links tempting you with the wor…
This is why I like plain text for everything (or Emacs Org Mode) because then I can have multiple frames showing different parts of the same buffer in Emacs.