What is literate programming?
Tags: programming, literateprogramming, softwareengineering, blog
Published: 2023-01-03 11:35:19

Hey there, developers!

So we already wrote about developer <a href="https://helloacm.com/characteristic-attributes-essential-for-successful-software-engineers/" rel="noopener" target="_blank">productivity</a>, how to measure and increase it, and what to avoid while doing this.

But what to do when you are already productive and with a memory like a sieve?

Let's dive in and find out!

<h3>Terrible short-term memory?</h3>
<a href="https://codingforspeed.com/do-you-have-poor-short-term-memory/" title="Do you have poor short-term memory?">Short-term memory</a>, also known as primary or active memory, is the capacity to store a small amount of information in the mind for a short period of time.

If not rehearsed or maintained, these short periods of time last only 20 to 30 seconds, maybe even less. And we are limited to storing only seven items in our short-term memory, plus or minus two.

To retain information, it needs to be transferred from short-term to long-term memory. This includes several helpful techniques, such as:

<ul>
<li>Maintenance rehearsal which includes repeating and going over something several times until information is stored in long-term memory</li>
<li>Chunking includes organizing information into groups, numbers, words, phrases, and anything that helps with remembering</li>
<li>Mnemonics are simple phrases, rhymes or abbreviations which make remembering easier</li>
<li>These methods can be quite helpful to anyone, but some more developer-friendly methods exist.</li>
</ul>

<h4>What is literate programming?</h4>
In the programming paradigm known as "literate <a href="https://codingforspeed.com/finding-that-perfect-code/" title="Finding That Perfect Code">programming</a>," created by Donald Knuth, a computer program's logic is explained in bits of traditional source code and natural language, such as English, from which compilable source code can be built.

<blockquote>
"Literate programming: Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do." - Donald Knuth (1984)
</blockquote>

Some developers write the comments first and then start writing the code. This way, comments serve as a reminder and additional information for a part of the code or a detail you can always get back to.

Any language that supports comments can be used for literate <a href="https://helloacm.com/teaching-kids-programming-check-if-there-is-a-path-with-equal-number-of-0s-and-1s-maze-recursion-dynamic-programming/" rel="noopener" target="_blank">programming</a> as long as the comments dominate the structure of the code.

There is a case to be made for smaller components, such as libraries, even if writing large codebases in this manner would be extremely painful. For instance, you can benefit from literate programming if you're a web developer designing a React component.

For example, a form of literate <a href="https://codingforspeed.com/accessing-multi-dimensional-array-in-row-column-sequence-cc/" title="Accessing Multi-Dimensional Array in Row-Column Sequence (C/C++)">programming</a> can be seen in Jupyter notebooks. As in them, the language or narrative is more important. You can share concepts that incorporate code, data, and visualizations. And typically literate part goes first, which is then augmented by code.

What do you think?

Reposted to [Blog](https://codingforspeed.com/what-is-literate-programming/)