Key Moments
Human Readable Code - Computerphile
Want to know something specific about what's covered?
We've already dissected every moment. Ask and we will deliver (with timestamps).
Key Moments
Conversational coding, where programmers and clients co-create code in plain English, can reduce misinterpretations but requires extensive upfront effort to define shared vocabularies.
Key Insights
Literate programming, proposed over 40 years ago by Knuth, emphasizes making code readable for humans, not just computers.
Traditional software development involves interpretation gaps between client requirements and programmer implementation, often discovered late.
Domain-specific languages (DSLs) offer tailored programming for specific problems but are resource-intensive to create.
By prioritizing human readability, a domain-specific language can be emulated within a mainstream language like Java, facilitating shared understanding.
The creation process involves collaboratively defining terms (e.g., 'choice', 'action', 'selection') to build a shared vocabulary, crucial for bridging the gap between business and technical domains.
This approach is particularly beneficial for writing software tests, as comprehensible tests can be validated by clients, increasing confidence in the software's correctness.
The challenge of traditional code translation
The core problem addressed is the disconnect between what a client needs and what a programmer builds. Clients understand their business needs but not programming, while programmers understand code but not necessarily the client's specific domain. This gap leads to misinterpretations, with errors often only discovered after significant time has elapsed. Traditional methods involve writing extensive documents and then translating them into code, with the sole validation being the running application, which occurs much later in the development cycle. The video suggests that ideal scenario would allow both parties to review and agree upon the code itself while it's being written, catching discrepancies early.
The promise of literate programming and DSLs
Donald Knuth's concept of 'Literate Programming' advocates for code that prioritizes human understanding. A more specialized approach is the creation of Domain-Specific Languages (DSLs), which are custom-built programming languages tailored to a particular problem domain. While effective, developing a DSL is a significant undertaking, not typically feasible for every project or developer. This video explores whether a similar level of human readability can be achieved by consciously structuring code within a mainstream programming language, making it accessible and verifiable by non-programmers.
Emulating a DSL within a mainstream language
The demonstration uses Java to illustrate how a readable, sentence-like structure can be built. Instead of the programmer deciding the code structure first and then fitting the requirements in, the process starts with the desired human-readable expression. For example, a requirement like 'find all the cards that are spades less than five and print them' is treated as a blueprint. The goal is to define functions and structures that mirror this English sentence as closely as possible. This involves creating abstract concepts like 'choice' (for suits like 'spades') and 'action' (like 'print them'), and then implementing the underlying logic—the 'plumbing'—that makes these high-level expressions functional.
Collaborative terminology and fluent APIs
A key aspect of this approach is the collaborative development of terminology. During the process of designing the code, the programmer and the client (or a proxy) discuss and agree upon specific words and phrases to represent concepts. For instance, deciding whether to call a selection criterion a 'constraint,' 'filter,' or 'choice' solidifies a shared vocabulary. This effort builds what's known as a fluent Application Programming Interface (API). The code reads like a continuous sentence or a series of connected clauses, rather than discrete, disconnected statements. This makes the code easier to follow and allows for early validation by the non-programmer.
Building the 'plumbing' behind readable code
While the user-facing code aims for maximum readability, the underlying implementation—the 'plumbing'—can be complex and is hidden from the client. The example shows how errors like a 'null' return value are debugged. The goal is to build the necessary functions and methods (e.g., `find_all_cards`, `that_return`, `less_than`, `and`, `then`, `print_them`) that support the fluent API. Once these components are built, new functionalities can be added by composing existing readable elements, reducing the effort for future changes and additions.
The value proposition: Effort vs. reward
The significant upfront effort in defining terminology and building the underlying code structure is weighed against the benefits. This approach is most valuable in domains where a company frequently works with similar problems, such as trading strategies or insurance rates. Having a well-defined 'language' for these operations can significantly speed up future development. It's less practical for one-off, unique projects. The process itself also yields insights into the problem domain and the precise meaning of concepts.
Application in software testing
This methodology is particularly powerful when applied to writing software tests. If tests are written in a comprehensible, human-readable format, the client can directly validate whether the tests accurately reflect the desired behavior. When a test passes, and it's understood by both parties, it provides strong confidence that the software is being built correctly. Conversely, passing tests that are not understood offer little assurance. Investing effort in readable tests can therefore be a very effective way to ensure the core system is meeting requirements.
Portability and future development
The specific 'little language' created within Java is not portable to other programming languages. However, the philosophy behind it is. The same principles of prioritizing human readability and building a fluent API can be applied in languages like Python, JavaScript, or C, though the implementation techniques will differ. The key is to drive development from the desired user-facing expression rather than building up from low-level code details. By creating a shared vocabulary and a readable code structure, subsequent development becomes more efficient, as much of the foundational language work has already been done.
Mentioned in This Episode
●Software & Apps
Making Code Human-Readable
Practical takeaways from this episode
Do This
Avoid This
Common Questions
Human-readable code is crucial for effective collaboration between software engineers and domain experts. It allows non-programmers to validate requirements and understand the software's logic, reducing misinterpretations and ensuring the final product aligns with business needs.
Topics
Mentioned in this video
More from Computerphile
View all 86 summaries
25 minHacking on the PDP1 Raspberry Pi Emulator - Computerphile
23 minHaptic Rendering - Computerphile
23 minTemporal Networks, Where Page Rank meets Lord of the Rings - Computerphile
21 minVector Search with LLMs- Computerphile
Ask anything from this episode.
Save it, chat with it, and connect it to Claude or ChatGPT. Get cited answers from the actual content — and build your own knowledge base of every podcast and video you care about.
Get Started Free