TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Literate programming: Knuth is doing it wrong (2014)

132 pointsby surprisetalk4 months ago

27 comments

fanf24 months ago
There are at least two aspects to literate programming.<p>Knuth wrote TeX in Pascal, which has a couple of limitations that annoyed him:<p>- Pascal has no module system: you can’t break a program up into multiple files<p>- The order of presentation of a program is dictated by the needs of a single-pass compiler<p>The tooling that supports literate programming is mostly about overcoming these problems with Pascal. (Knuth also uses it to split up larger procedures in a manner that makes me think of very un-structured C macros.) Most other languages are more flexible so they have much less need for a technology like tangle&#x2F;weave.<p>The opposite extreme is Literate Haskell, which doesn’t need any preprocessor. You just feed your TeX document to ghc and it picks the code out of the \begin{code} blocks. Or instead of Knuth style you can write in Bird style, where the file is a plain text document with code marked by &gt; quote blocks.<p>The other aspect of literate programming is organizing the code like a book. This is very difficult to do well. When I think of how I approach a codebase, it reminds me of textbooks that have a complicated diagram describing multiple suggested orders of reading (a chapter per module?), or the informal introduction to Algol 68 with its orthogonal table of contents. Ideally a program’s commentary should span both the explanatory and reference documentation quadrants.<p>What strikes me about Knuth’s literate programming is how hypertextual it is, albeit using printed cross-references and indexes. It seems to be in desperate need of interactive pixels. And an underlying programming language that has better support for Knuth’s preferred size of code fragment.<p>On balance I think modern tools achieve Knuth’s goals better than tangle&#x2F;weave. Modern languages let you organize code much closer to its narrative structure, without WEB’s unhygienic scoping. Editors and IDEs and documentation browsers give you hyperlinks everywhere.<p>It’s then “just” a matter of writing the exposition. Less literate programming, more literate programmer.
评论 #42684488 未加载
评论 #42686107 未加载
评论 #42686639 未加载
评论 #42685819 未加载
评论 #42685211 未加载
PaulHoule4 months ago
I spent a lot of time thinking about no&#x2F;low code and one conclusion I came to was that there was &quot;the program&quot; and then there was the way it displayed. Consider<p><a href="https:&#x2F;&#x2F;www.knime.com&#x2F;why-visual-workflows" rel="nofollow">https:&#x2F;&#x2F;www.knime.com&#x2F;why-visual-workflows</a><p>the topology of the connection between the blocks is essential to <i>execute</i> the program; that doesn&#x27;t require coordinates for the blocks, but the visual editor does. The ideal tool has a clean separation between these. People are dimly aware of the &quot;hairball&quot; graph problem and looking for a visualization algorithm that banishes them:<p><a href="https:&#x2F;&#x2F;blog.tomsawyer.com&#x2F;untangle-the-hairball-with-bundle-layout" rel="nofollow">https:&#x2F;&#x2F;blog.tomsawyer.com&#x2F;untangle-the-hairball-with-bundle...</a><p>yet the real problem is that if your goal is to communicate you want to tell stories with visualizations and you need a visualization organized around a story -- and for each story you tell you need a different visualization.<p>I see the same thing with literate software. I can think of a number of interesting stories to tell about last month&#x27;s chess program (e.g. &quot;move generation&quot;, &quot;alpha-beta search&quot;, for instance.) For a particular story I want to focus on certain things and completely eliminate other things. The same code might appear in more than one story. To make all this work there has to be a clean separation.
评论 #42683864 未加载
评论 #42684915 未加载
jasonpeacock4 months ago
The problem with literate programming is that most people aren’t good writers, and they aren’t interested in developing their writing skills - they only want to code.<p>Already it’s pulling teeth just to get literate commit messages…
评论 #42683712 未加载
评论 #42683912 未加载
评论 #42684367 未加载
评论 #42684351 未加载
评论 #42686482 未加载
dhosek4 months ago
I used to do everything in WEB&#x2F;CWEB back in the 80s&#x2F;90s. My biggest difference from Knuth was that I always started with an outline of the program as my first section (or perhaps second after an introductory section talking about what the program was meant to do). This made sense both from an expository standpoint and from a development standpoint as I could then assemble the program piecewise by filling in the sections that I had outlined at the beginning and generally each block of code fit on a single page with its documentation.<p>Problems I ran into were (a) for Pascal WEB, it was hard to get away from Knuth’s string pool–based handling of strings which I didn’t especially love and (2) for CWEB, it made sense to have both the .c and .h files specified in the .cweb file, but this meant that a lot of the efficiencies of make, such as they are, would be broken since the .h file would get updated everytime I updated the .c file forcing recompilation of other chunks of the code even though there were no actual changes. Perhaps a more intelligent version of ctangle which could screw with modification dates of files based on whether the code was actually changed would have helped, but…<p>That said, the weave output of TeX and Metafont does provide amazing documentation of the internals of how those programs work and they make for excellent reading. Alas, that sort of thing is hard to justify in contemporary business contexts.
评论 #42687017 未加载
评论 #42685930 未加载
评论 #42700513 未加载
评论 #42685478 未加载
评论 #42687078 未加载
wduquette4 months ago
In my experience, code bases are best structured for navigability, I.e., so that you can find what you’re looking for. Literate programming is about narrative, telling the story of the code in a clear way so that you can build your mental model. These two needs are frequently orthogonal.
评论 #42683658 未加载
评论 #42683606 未加载
d--b4 months ago
What&#x27;s difficult is the tension betwen compact code and verbose code.<p>Compact code makes the higher levels of abstraction easier to read, while more verbose code makes lower levels of abstraction easier to read.<p>In large codebases, if you spend 10 lines describing an optimization for sorting stuff faster, you may lose the overall idea of what the function is doing. But if you don&#x27;t, no one is going to understand that particular optimization. People will say that these should go in subfunctions, but having too many subfunctions is yet another problem that breaks code&#x27;s linearity, making it also harder to read.
评论 #42684162 未加载
评论 #42685528 未加载
alganet4 months ago
For today, I would focus on literate testing. The linear unit test is a better bottle for narrative content than the non-linear code.<p>In a similar line, I believe automatic documentation should be generated from tests, not the implementation. Then it&#x27;s always up to date.<p>Text has many forms. Poems with many kinds of metrics, prose with all kinds of tones. Some forms are atemporal, some get old. None of it is &quot;wrong&quot;, just different bottles to convey different ideas to different audiences.
评论 #42684899 未加载
Sylvain784 months ago
Oscar winning book about rendering accurately 3D scenes, written in literate programming : <a href="https:&#x2F;&#x2F;www.pbrt.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.pbrt.org&#x2F;</a>
评论 #42683587 未加载
评论 #42684041 未加载
评论 #42683676 未加载
fjfaase4 months ago
For &#x27;Advent of Code&#x27; I have been using a kind of literary programming method based on Markdown files. I have written a parser that can read Markdown files with segments of C code and put all the segments in the correct order to be compiled. For an example, see: <a href="https:&#x2F;&#x2F;github.com&#x2F;FransFaase&#x2F;AdventOfCode2023&#x2F;blob&#x2F;main&#x2F;Day03.md">https:&#x2F;&#x2F;github.com&#x2F;FransFaase&#x2F;AdventOfCode2023&#x2F;blob&#x2F;main&#x2F;Day...</a><p>I also used it as a documentation for parser I have been developing, which shows the literary programming style in a better way. The program can combine several Markdown files into a single C program. See: <a href="https:&#x2F;&#x2F;github.com&#x2F;FransFaase&#x2F;RawParser?tab=readme-ov-file#documentation">https:&#x2F;&#x2F;github.com&#x2F;FransFaase&#x2F;RawParser?tab=readme-ov-file#d...</a>
评论 #42685924 未加载
camel-cdr4 months ago
&gt; There&#x27;s a fundamental problem with generating a beautifully typeset document for a codebase: it&#x27;s dead. [...]<p>&gt; You can&#x27;t work with it, you can&#x27;t try to make changes to it to see what happens, and you certainly can&#x27;t run it interactively.<p>I think an aspect where &quot; classical&quot; literate programming excels is in the form of printed educational books.<p>A great example of this is LCC &quot;A Retargetable Compiler for ANSI C&quot; by David R. Hanson.<p>Reading about how to write compilers in theory is fine, but it&#x27;s very nice to learn from a full working example implementation.
评论 #42684029 未加载
评论 #42698917 未加载
评论 #42688503 未加载
taeric4 months ago
I used to agree with this post&#x27;s general premise, but I have come to think it is wrong.<p>The idea seems to be that a literate program would be ordered such that a reader would not need any familiarity with general boilerplate of the language that is being presented. But there is no real benefit for that. Indeed, it makes everything so much harder if you are trying to have meaningfully original narrative for every single line.<p>Instead, people should know roughly what the outline of a C program is if they are going to try and read a C program. Regardless of if it is done literately or not. To that end, having some generic imports at the top of a file that has a scattering of globals the author typically uses makes a ton of sense.<p>The idea, restated, is to allow you to narrate code. So, think of how you would approach reading anyone&#x27;s source code that wasn&#x27;t reformatted in this way. You&#x27;d take a look at the general outline of the file. Probably take a quick peak at the basic imports. If there are a common set of top level variables you expect to see, check for those real quick. Then, start trying to find the narrative of the code.
flerchin4 months ago
It&#x27;s funny the very things the author decries are when IDEs do for us automatically. Hide the imports, expose the abstractions when needed.
jillesvangurp4 months ago
I wrote a small kotlin framework to help me write documentation that has lots of code samples (<a href="https:&#x2F;&#x2F;github.com&#x2F;jillesvangurp&#x2F;kotlin4example">https:&#x2F;&#x2F;github.com&#x2F;jillesvangurp&#x2F;kotlin4example</a>) that might be of interest to people maintaining kotlin libraries.<p>My library tries to enable literal programming in Kotlin via a Kotlin DSL that makes it easy to use markdown in multi line string literals. You use the DSL to write your documentation as a Kotlin file that generates markdown that you can save to a file when you run it (from a test typically).<p>The key feature that enables literal programming is an example lamda function. This makes it easy to embed example kotlin code in the documentation. The library figures out how to extract the code block you pass to this function from the source code and includes it as a markdown source code block in the markdow output. Example blocks are also runnable (optional) and of course have to compile. If you run them, you can optionally capture their output as well and render that in the documentation. Additionally it captures the block return value and allows you to do things with that.<p>Of course you can also include existing markdown files, create links to files in a (public) github repository or pull in source code examples from existing source files.<p>Most of this isn&#x27;t really novel. But I haven&#x27;t really seen anything like the example lamda function in other tools. And this is something that might also work with other languages (Ruby maybe?). Although it does rely a bit on reflection and classloader magic to figure out the source code that corresponds with the .kt file in which the example blocks are located. At runtime it tries to figure out the beginning and end of those blocks and transforms those in markdown source blocks.<p>As far as I know, I&#x27;m the only user of this library so far. But since I think it is kind of nice, I thought I mention it here.<p>It&#x27;s not perfect but I&#x27;ve documented a few of my open source kotlin libraries with this. The most significant one is jillesvangurp&#x2F;kt-search, which has a lot of documentation at this point.
begueradj4 months ago
A couple of months ago, I read a comment here in HN where the OP said that wherever he worked, his colleagues thanked him because he always used the literate programming approach, hence his code is easier to understand and follow. I wish I can find that comment.
评论 #42683571 未加载
quantadev4 months ago
It seems to me like in 20 to 50 years humans <i>will</i> still be writing computer code, but hopefully some IDE-like &#x27;block-based&#x27; editor approach similar to Jupyter Notebooks will have taken over. Block-based editors let you mix in different &quot;types&quot; of artifacts like documentation, code, images, examples, scripts. It will need to be some kind of &#x27;tree-like&#x27; structure with expandable nodes like a file system I think, so that for example underneath every method implementation you can have it&#x27;s test cases right there with it, sort of &#x27;inline&#x27;.<p>I&#x27;ve also thought that eventually even web-browsers will be replaced with some system like this too, where everything is &quot;typed&quot; (like Semantic Web), so that both machine parsers, AI systems, and humans can equally well consume and understand the content.<p>The problem is &#x27;momentum&#x27;. People tend to build new capabilities on top of the old capabilities like layers of an onion rather than rebuilding something new from scratch like a Jupyter Notebook-like &quot;do everything&quot; browser&#x2F;IDE&#x2F;editor.
mtrovo4 months ago
&gt; You can&#x27;t work with it, you can&#x27;t try to make changes to it to see what happens, and you certainly can&#x27;t run it interactively. All you can do, literally, is curl up with it in bed. And promptly fall asleep.<p>I totally agree with this. Generating static typeset docs essentially leaves them &quot;dead&quot; because they can&#x27;t be poked at, run, or updated in real time. That&#x27;s why I&#x27;m a big believer in the value of tests and instrumentation, which stay alive alongside the code. In practice, we don&#x27;t need every aspect of a project ( e.g code, tests, docs, and instrumentation) to be simultaneously visible at all times, and I think part of the complexity of onboarding into a new project is the overwhelming feeling you get the first time you see a piece of code with all its tests, all comments, and all its instrumentation thrown at you like you should pay attention to everything. When we&#x27;re refactoring, we focus on a particular chunk of code and its tests; when we&#x27;re debugging, we need instrumentation. For everything else, we can loop back later.<p>We already have powerful ways to merge issues, commits, and discussions, but we still rely on massive documentation dumps that go stale fast. A more adaptive approach (perhaps using an LLM to generate contextual help from version control) would allow us to focus on the core process of writing and verifying code. I especially like the idea of code that can &quot;talk back&quot; and give just the right amount of detail based on what we&#x27;re trying to accomplish at the moment. Sometimes it suffices to have novice-friendly, high-level explanations; other times, we want to jump in and change the behaviour of a very specific feature across some specific files. Maintaining documentation for every possible scenario is a huge burden, which is why I think flexible, on-demand help could be a game changer.
cbrozefsky4 months ago
Emacs org-mode literate programming allows for re-ordering of code, extracting to multiple files, and if using a suitable language, evaluation of fragments and interactive exploration and rendering of examples.<p>I really enjoy it with a lisp, like clojure.
bluGill4 months ago
Literate programming fails because it I&#x27;m a programmer and so it is telling things I already know. I understand how to read code.<p>Literate programming makes sense if you are writing raw machine code, or assembly where you cannot always name something important. DoSomething() better do what the names says it does so you don&#x27;t need a comment to say anything more about it. Look at all the examples - why are they saying anything about &quot;#include &lt;stdio.h&gt;&quot; - if you don&#x27;t know what that line does then you have no business reading C code - go learn C and then come back. Sure you could read the literate programming comments without knowing C - but I cannot think of any reason anyone would ever do that.<p>Comments that tell me what the code cannot are very helpful. Telling me that this complex sequence of weird code is just the standard AES algorithm is helpful (I haven&#x27;t seen AES code, but I&#x27;ve seen other encryption algorithms that are weird bit manipulations and I assume AES is the same), but even then if I need to touch that code I better refer to the AES documentation so don&#x27;t write how AES works. (If it is a custom algorithm for your company maybe document how it works, but the code is not the place for that). The important part is the code can tell me why is happening but not why it is that way so comments should tell me why you are doing something.
评论 #42685037 未加载
评论 #42684990 未加载
评论 #42685023 未加载
WillAdams4 months ago
Interesting.<p>Surprised I never heard of &quot;Wikilon&quot; (apparently it was an early precursor to Jupyter Notebooks?)<p>I agree with the criticism at the bottom:<p>&gt;There&#x27;s good and bad parts of LP, but it&#x27;s not fair to pick examples of bad LP and use them to criticize all of LP, even if they were written by the guy who invented it. Some of the Wright planes crashed, but that doesn&#x27;t mean airplanes are bad.<p>The mention of Axiom is interesting, since I find that going a step further and integrating Tangle&#x2F;Weave so that both &quot;just happen&quot; is a big reduction in friction, hence my stumping for assistance:<p><a href="https:&#x2F;&#x2F;tex.stackexchange.com&#x2F;questions&#x2F;722886&#x2F;how-to-write-out-multiple-text-files-from-multiple-instances-of-latex-environmen" rel="nofollow">https:&#x2F;&#x2F;tex.stackexchange.com&#x2F;questions&#x2F;722886&#x2F;how-to-write-...</a><p>and working up a package:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;WillAdams&#x2F;gcodepreview&#x2F;blob&#x2F;main&#x2F;literati.sty">https:&#x2F;&#x2F;github.com&#x2F;WillAdams&#x2F;gcodepreview&#x2F;blob&#x2F;main&#x2F;literati...</a><p>(which unfortunately has to be edited to match the files which it outputs, as must the master .tex file)<p>which allows me to typeset a .tex file (which has ``normal&#x27;&#x27; syntax colouring in an editor, no &quot;sea of grey&quot; as .dtx inflicts) and get both the typeset .pdf and the .py and .scad files which are my project:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;WillAdams&#x2F;gcodepreview">https:&#x2F;&#x2F;github.com&#x2F;WillAdams&#x2F;gcodepreview</a><p>(currently deeply into a re-write and hope to have a fully working version up by the end of the week --- see the archived v0.6 .tex&#x2F;.pdf pair: <a href="https:&#x2F;&#x2F;github.com&#x2F;WillAdams&#x2F;gcodepreview&#x2F;blob&#x2F;main&#x2F;gcodepreview-openscad_0_6.pdf">https:&#x2F;&#x2F;github.com&#x2F;WillAdams&#x2F;gcodepreview&#x2F;blob&#x2F;main&#x2F;gcodepre...</a> to see a working state&#x2F;example)
评论 #42684872 未加载
hugetim4 months ago
Curious how folks think this measures up: <a href="https:&#x2F;&#x2F;www.answer.ai&#x2F;posts&#x2F;2024-06-23-claudette-src.html" rel="nofollow">https:&#x2F;&#x2F;www.answer.ai&#x2F;posts&#x2F;2024-06-23-claudette-src.html</a>
评论 #42684110 未加载
evanmoran4 months ago
The best approach I’ve seen in literate programming is when the comments become a webpage of documentation automatically from the source. This can be “&#x2F;&#x2F; comments” or more like markdown indention, but I think the magic comes from the automatic documentation more than the particular literate programming syntax&#x2F;approach. I think it encourages people to write just a bit more clearly, more like how people take more care with a blog post than an email, and that makes a significant difference.
norir4 months ago
I take the author&#x27;s point, but I still prefer languages that can be parsed in a single pass. Most commonly, this means it is written in a top down style where every reference is defined somewhere above the usage. It then naturally falls out that programs can be easily read bottom to top and the presentation will make sense.<p>You can put one intro comment at the top that tells the reader to go to the bottom and read from there. The actual main method code is almost always the most important and reliable information anyway.<p>In vim, I can open the file &#x27;G&#x27; to the bottom, scroll up to the main function and start reading. Any def I want to look up I can select and find with &#x27;?&#x27;. The main catch is you need qualified imports rather than c style to make this work the best.<p>Writing in this style, I find that I don&#x27;t need files. Everything I need for a module is already in a single file. I don&#x27;t even need lsp since I personally don&#x27;t ever use autocomplete in any context, programming or otherwise, and search is trivial when all defs are in a predictable order in a single file.<p>Now if I were writing a book, rather than a program, I would probably use a different format. Generally though, I think we should let programs be programs and books be books.
评论 #42684761 未加载
评论 #42693788 未加载
liontwist4 months ago
Knuth’s is the only literate programming system that emphasizes type setting. That’s because he designed Tex and wrote thousands of pages with it. It’s his local optimum.<p>All the others use markdown, html, eMacs org, etc.
评论 #42694431 未加载
regnull4 months ago
I&#x27;m a little confused about the point the author repeatedly makes in this article, complaining about the #includes on top of the file. Genuinely curious, where does he propose to put the includes?
评论 #42684137 未加载
kazinator4 months ago
Knuth&#x27;s literate programming is completely bonkers from the software engineering perspective. Knuth never worked as a rank-and-file programmer in a corporation.<p>However, Knuth is definitely <i>not</i> doing it wrong from the perspective of Knuth. His approach is workable by someone else who is another Knuth. Such another Knuth would never work in collaboration with Knuth; he or she would have an office at a different institution, working on different research with different programs. Knuth&#x27;s approach does not have to scale to 2 or beyond, or to megaprojects.<p>Knuth&#x27;s approach lets an author write a book or paper, and its accompanying code, as a single document. Knuth tested and refined his approach in the context of this use case, and of course it works.<p>Knuth&#x27;s approach to literate programming chops up the program into arbitrary pieces that don&#x27;t necessarily even follow functional boundaries. The program unit he&#x27;s interested in is any group of lines that deserve commentary. His system is like a macro preprocessor that stitches the program together via text inclusion of arbitrary lines, which are given a name. For instance, a function body might be pieced together from three separately defined texts.<p>It&#x27;s obvious that we can&#x27;t simply cannot write the Linux kernel, MongoDB, Google Chat this way; basically anything that is not a solo effort. Even some solo efforts couldn&#x27;t be done that way. The approach will not only scale to multiple developers, but also to certain project sizes and complexities. Solo projects can go into hundreds of thousands of lines; that&#x27;s far beyond what we would want to develop using chopped up pieces of program text plugged into a book-like document, extracted to make a buildable program.<p>TeX is Knuth&#x27;s most famous program that has been maintained for many decades and used by others, which is also developed with a literate programming system. However, those core programs like tex and metafont are only a small part of an entire TeX distribution. The entire TeX ecosystem contained in a Tex distro is not banged up in that literate programming system! Supposedly, TeX generates out to around 50KLOC of C, and Metafont to around 20KLOC. I would guess that would probably just about start to be straining at the limitations. Knuth&#x27;s intuition for a documentation system to handle about the size of the program he set out to create may have been spot on.<p>Also, what fanf2 said: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=42683602">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=42683602</a><p>&quot;The tooling that supports literate programming is mostly about overcoming these problems with Pascal.&quot;<p>Excerpt from a great comment!
ctrlp4 months ago
Are we not at the point where an LLM could write the literate view of the codebase (updated on changes) putting the human interest stuff forward and providing that view of the code Knuth was always envisioning?
评论 #42691294 未加载
nzach4 months ago
I think the author missed the <i>real</i> point of literate programming - or I may be interpreting literate programming totally wrong.<p>In my opinion literate programming is really about optimizing for &#x27;read&#x2F;understand workflow&#x27; and not the &#x27;execute workflow&#x27;. But I don&#x27;t blame him, programming change quite a lot in the last 10 years.<p>Especially in the past a lot of people thought things like fast inverse square root[0] were the pinnacle of programming. Because they made something possible that was previously impossible. And culturally being &#x27;clever&#x27; was generally used as a compliment. I think a good example would be ESR[1], a <i>really</i> smart individual who always enjoyed to push things to the limit and that would frequently involve quite a lot o hacking(in the original sense).<p>But as complexity grows we started to understand we should not rely too much in clever solutions because its hard and expensive to find someone that is smart. And even when you do, its nice to allow people to take some vacations every so often without creating disruptions in your company.<p>In this context I think literate programming is more about making software anyone can understand and change than it is about having a nicely typeset manual. When literate programming was proposed reading source-code created by someone else wasn&#x27;t as easy as it is today. If you wanted to understand how something worked your best bet would be the manual provided by the author, today with modern LSPs you are generally one shortcut away from the actual source-code.<p>With that said, my personal interpretation is that literate programming is about writing code that doesn&#x27;t need documentation (I think &#x27;self-documenting code&#x27; has a bad reputation, but that is another problem). For a extremely contrived example you could look at the difference between &#x27;x &lt;&lt; 1&#x27;, &#x27;pow(x, 2)&#x27; and &#x27;square(x)&#x27;. All three options should give you the same result. And even knowing that the first would probably always be faster I think &#x27;square(x)&#x27; is generally the best option. Sure, I&#x27;m leaving performance on the table but if my instrumentation is reasonably good it shouldn&#x27;t be too hard to find this line when we really do need this extra performance and then I change back and leave a comment explaining why we had to change to this less clear code.<p>In the end code should mostly be about intent. Just by reading the code I should be able to understand the business need that required this code to be created. DDD has this idea of unified language, that I think is pretty relevant here. In the DDD book there is a quite nice example about modelling a system that handles shipment contracts and needs to work with the concept of overbooking. The naive approach would be having something like &quot;if (alreadyBookedCargo + cargoSize) &gt; maxAllowedSize { return &#x27;cannot book new cargo&quot; } &#x27; but if you change to something like &quot;if !policyAllowed(&#x27;overbooking&#x27;, alreadyBookedCargo, cargoSize) { return &#x27;cannot book new cargo&#x27; } &quot; the code becomes easier to reason about.<p>Most people don&#x27;t do this because this process is essentially &#x27;just&#x27; naming things, and we all know how hard it is.<p>[0] - <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Fast_inverse_square_root" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Fast_inverse_square_root</a> [1] - <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Eric_S._Raymond" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Eric_S._Raymond</a>
评论 #42694474 未加载