Live data from Hacker News

Programs to Read

wiki.c2.com

51–60 of 60 posts

Re: Programs to Read

#51
post #50

Earlier quoted context omitted.

Reading TeX original source is easier said than done... I think I managed to get PDF some time ago but took me like 30 minutes of browsing. Not talk about running it...

It's available as a book ( TeX: The Program , volume B of Computers and Typesetting ), and Knuth considers the book as the canonical thing to read. You almost surely don't have a PDF of the entire book, but it's easily available in good libraries: http://www.worldcat.org/title/tex-the-program/oclc/826569131 (or you can buy it: as I was typing this comment I just finally bought a used copy from Amazon for $9 which is…

Cool, very informative!

The bad thing about a print book is that you would have to type the code to run it... How would you go about running TeX? I find the most effective way to read source code is to run it (to answer questions like: "what's the output if the input is this thing", etc.)

I wish someone who's familiar with the moving pieces would put together a version that runs on a browser.

Re: Programs to Read

#52
post #50

Earlier quoted context omitted.

It's available as a book ( TeX: The Program , volume B of Computers and Typesetting ), and Knuth considers the book as the canonical thing to read. You almost surely don't have a PDF of the entire book, but it's easily available in good libraries: http://www.worldcat.org/title/tex-the-program/oclc/826569131 (or you can buy it: as I was typing this comment I just finally bought a used copy from Amazon for $9 which is…

Cool, very informative! The bad thing about a print book is that you would have to type the code to run it... How would you go about running TeX? I find the most effective way to read source code is to run it (to answer questions like: "what's the output if the input is this thing", etc.) I wish someone who's familiar with the moving pieces would put together a version that runs on a browser.

TeX is written in a literate programming system called WEB, that Knuth developed especially for (re-)writing TeX and METAFONT, and knowing that the source code was going to be published as print books (people had asked for it, so he kept this in mind when rewriting them). To overcome the limitations of Pascal (which was the most widely available language at the time at the places where TeX was being used: universities and the like), the WEB system adds quite a few features as a preprocessing step.

So, in WEB, the programmer types into a .web file, which runs through a program called TANGLE to produce a .pas Pascal file, and independently through another program called WEAVE to produce a .tex file (which is typeset into what you read). See Figure 1 here: http://www.literateprogramming.com/knuthweb.pdf#page=2

So to run TeX, the idea was that you have to pass the code through TANGLE, then run the resulting Pascal code through a Pascal compiler to get a binary, that you run. Of course Pascal compilers are less common today (and in any case Knuth was writing in the dialect of Pascal available to him at the time, and the language has diverged since) so in practice most TeX distributions pass the WEB (or tangled) code through something that converts (translates) the WEB/Pascal to C, then compiles that C code, etc. So running it is not exactly trivial. (See also: "LuaTeX says goodbye to Pascal" https://www.tug.org/TUGboat/tb30-3/tb96hoekwater-pascal.pdf and the Introduction to Martin Ruckert's "web2w" project: http://mirrors.ctan.org/web/web2w/web2w.pdf#page=13) This also makes running TeX under a debugger quite hard (https://tex.stackexchange.com/a/384881/48 , http://www.readytext.co.uk/?p=3570)

Nevertheless, putting together a version that runs on a browser is precisely one of my dreams :-) Maybe in a few years! (There is already a version that runs in a browser: http://manuels.github.io/texlive.js/ but that's not designed for readability / understandability.)

Note that, even if you had the entire program running in a browser, understanding it interactively would not exactly be trivial. The program itself (if viewed at the "raw" Pascal code level, i.e. without the conveniences afforded by the literate programming system) is rather far from modular; it's monolithic, with lots of global state, lots of data structures with the same fields used for different things in different contexts, abundant goto-s, etc. (All of these were the right choices at the time, given the constraints.) It's described by someone at http://wiki.c2.com/?TexTheProgram as “the last hurrah of procedural/functional structured (read: non-OO) programming. [...] achieved without some of the modern code-structuring tools we have today. I don't think the modern programmer raised in an OO culture could do the same”. But what literate programming gives here is a way to still understand the program despite these impediments -- one could say that, since the 1970s, many programming languages/communities have evolved some solutions for managing complexity, and Knuth's literate programming is an independently evolved different solution to the problem. Of course, one could combine the two...

Re: Programs to Read

#53
The Subversion api should be on this list too. I had occasion to do some development with it before and it's beatifully written.

Re: Programs to Read

#54

Earlier quoted context omitted.

On the one hand, I see your point. But on the other hand, if a master of some skill says "This is how I achieve the results I achieve." — perhaps imitating that might just be valuable. Does a dancer not get better by learning to imitate (at least at first) a master? (Though perhaps eventually, a deeper understanding of the artform might take hold, at which point experimentation and improvisation allow the dancer to e…

No disagreement there! Though you may violently agree or disagree with this thing I wrote a couple of years ago: http://akkartik.name/post/literate-programming I also just looked at your profile, and it resonates a lot. Tell me what you think of mine: http://akkartik.name/post/about

I'm not the person you're replying to, but I think you mean http://akkartik.name/about (and not http://akkartik.name/post/about).

And though you didn't ask me, I read it (having been annoyed by your LP post for a few years now) and it strongly resonates with me — the mission, and everything until the start of the “Constraints on a solution” section. IMO the way to give more people more understanding of programs is not to write an entire new programming language / operating system and hope that enough people switch to it, but to work on delivering that “understanding” for existing programs in existing languages. It may be harder, but is more likely to be useful, and you also get feedback on what kind of understanding people want and lack.

Re: Programs to Read

#55
post #54

Earlier quoted context omitted.

No disagreement there! Though you may violently agree or disagree with this thing I wrote a couple of years ago: http://akkartik.name/post/literate-programming I also just looked at your profile, and it resonates a lot. Tell me what you think of mine: http://akkartik.name/post/about

I'm not the person you're replying to, but I think you mean http://akkartik.name/about (and not http://akkartik.name/post/about ). And though you didn't ask me, I read it (having been annoyed by your LP post for a few years now) and it strongly resonates with me — the mission, and everything until the start of the “Constraints on a solution” section. IMO the way to give more people more understanding of programs is n…

Many thanks for the correction, and for the comment! It is absolutely likely that delivering the understanding for existing programs is the way to go. Unfortunately I just don't know enough for that yet. It's a hard chicken-and-egg problem: to understand the current stack I need precisely the concepts and tools that I'm trying to work out.

Over the last few years I've switched back and forth between the two extremes. I spent a couple of years off and on learning how operating systems (OpenBSD, Sortix, a little bit of Linux) work. I've gained some hard-won facility for poking around inside GNU package sources. So it's yet possible that I'll find a way to make progress on an existing stack.

It also depends what the criterion for 'success' is when we consider this "strike out vs work within" tradeoff. If the goal is some level of adoption then it's a no-brainer that working with existing platforms is the way to go. But I may be content just to figure out the right answer for myself.

Working within an existing platform requires a time commitment to a single (or a tiny subset) of the many projects that our platforms have balkanized into. After all that time commitment, effecting change from within requires a level of politics that is definitely not my strong suit. These projects have real users and justifiably shouldn't be giving me the time of day anytime soon.

One alternative I've considered is forking a mature platform. It remains on my radar, but at the moment I think the drop-off in benefits the instant I hit 'fork' is way too great. Consider a platform like OpenBSD that frankly is created by way smarter people than myself and is way more mature. The level of adoption it gets from being POSIX compliant is so miniscule; would making incompatible changes really be that counter-productive? It's worth asking if you're baiting big to catch small.

On some level my real target is to change the customs that influence how open source projects are governed. Even if I managed to overcome all the previous hurdles, it still seems impossible within the existing framework to do things like encourage more forks in projects, or convince more people to cull their dependencies, or read their sources. There's just too much baggage. Starting afresh may paradoxically make a new way easier to see.

This is the "idea maze" as I see it. I'd love to hear more, what you think of it.

Re: Programs to Read

#56
post #54

Earlier quoted context omitted.

I'm not the person you're replying to, but I think you mean http://akkartik.name/about (and not http://akkartik.name/post/about ). And though you didn't ask me, I read it (having been annoyed by your LP post for a few years now) and it strongly resonates with me — the mission, and everything until the start of the “Constraints on a solution” section. IMO the way to give more people more understanding of programs is n…

Many thanks for the correction, and for the comment! It is absolutely likely that delivering the understanding for existing programs is the way to go. Unfortunately I just don't know enough for that yet. It's a hard chicken-and-egg problem: to understand the current stack I need precisely the concepts and tools that I'm trying to work out. Over the last few years I've switched back and forth between the two extremes.…

Well it's a noble goal and I certainly don't want to discourage you, however you go about it! Perhaps you will learn something new and useful.

But just to make my meaning clear, by “existing programs in existing languages”, I meant doing it in a way that does not require effecting change at all. What understanding is it is possible to deliver for an existing, complicated, messy codebase? For example, you correctly noted that early versions tend to be easier to understand, and code tends to accumulate complexity that makes the global structure less clear. This is true and something I use often: use "blame" to look at where a particular chunk of code was introduced, and look at the corresponding change, along with its description/commit message, which is often simpler. (And I see you've written a tool (http://akkartik.name/post/wart-layers) for those who choose to stay conscious of this and write code in a particular way.) But most software today is available with version history. So, what if this were easier? E.g. imagine if when you view code there's a slider that you can move back and forth to see older or newer versions, while the changes fade out. Or, imagine highlighting the “base” of the code versus the less important changes. Or something; experimentation will reveal what tends to be useful for existing codebases. (And if people find the tools useful, that may even effect change in how code is written, as authors get feedback on what the tool thinks versus their mental understanding, and tweak until there's a match. I've seen Typescript being sold not for some putative benefits of typing on code correctness but simply for enabling IDE autocomplete for instance.)

The broader point is that, to me it seems that your writing and efforts have the implied assumption that understanding of global structure is hard to acquire because everyone is making mistakes, and if everyone is just careful to do things differently, the difficulties will disappear and understandable programs will magically emerge. That is something worth investigating, but I think there's a good chance that perhaps not everyone is making mistakes (as even programs written by the best programmers tends to become hard to understand eventually), and/or that it's not feasible for everyone to be super careful when trying to get things done. (Rather, they're making tradeoffs, and are likely to make similar tradeoffs in future.) Not all the accumulated complexity may be accidental; some is inherent in the fact that the problem in the real world does have messy corner cases (as Spolsky said: https://www.joelonsoftware.com/2000/04/06/things-you-should-...). Similarly most of the causes you identified (backwards compatibility considerations, churn in personnel, vestigial features) (and those identified elsewhere, e.g. in “out of the tar pit”) can be real and unavoidable: there may be features that are needed only for (say) users of old systems but still cannot simply be removed. The best that can be hoped for is to make this fact clearer, not to make them go away.

Finally, there's also the fact that “understanding” is not a property inherent in the system (code, program, whatever) itself, but something that grows in the head of the reader. (Perhaps trying to influence the writer is not the best way...) And different readers come with different questions and goals, and at least as far as the first paragraph of your http://akkartik.name/about goes, may need different sorts of help in different contexts. It's unlikely a fixed organization of the program is going to satisfy everybody.

An example: error handling. We've all seen functions that spend only a few lines doing their “main” job and many more lines checking for errors and dealing with them. This can obscure what the main job of the function is, and make it appear as though error-handling is the main part. (Aside: Knuth observes this causes a psychological barrier against writing too much error handling, while with his literate programming one shunts off the error-handling to a different section/module, and one tends to write better error-handling there.) But consider https://danluu.com/postmortem-lessons/ which says “If you care about building robust systems, the error checking code is the main code!” So depending what kind of understanding a reader is looking for at a certain time, sometimes they may want to understand the “happy” path and sometimes the error handling.

Similarly in general: given a program, sometimes we want to understand roughly how it's organized / what its major components are, sometimes we want to understand the precise boundaries/interfaces between these components, sometimes we want to understand the sequence of operations the program performs and sometimes the frequency, sometimes we want to understand what it does in the “steady state” and sometimes what it does at startup or shutdown or some corner case. And in fact not always the global structure of a program but sometimes only enough to understand how it solves a specific problem — if I want to make a change to (say) Firefox in an afternoon, I may just want to know how it does (say) font fallback.

All that said, yours is an interesting project, and for the reasons you mentioned, and I look forward to what comes out of it. Apologies for a verbose comment; I'll stop here :-)

Re: Programs to Read

#57
post #56

Earlier quoted context omitted.

Many thanks for the correction, and for the comment! It is absolutely likely that delivering the understanding for existing programs is the way to go. Unfortunately I just don't know enough for that yet. It's a hard chicken-and-egg problem: to understand the current stack I need precisely the concepts and tools that I'm trying to work out. Over the last few years I've switched back and forth between the two extremes.…

Well it's a noble goal and I certainly don't want to discourage you, however you go about it! Perhaps you will learn something new and useful. But just to make my meaning clear, by “existing programs in existing languages”, I meant doing it in a way that does not require effecting change at all. What understanding is it is possible to deliver for an existing, complicated, messy codebase? For example, you correctly no…

I really appreciate the detailed comment! I love talking about this stuff.

---

You're absolutely right that code reading is a non-linear activity and that won't ever change.[1] I'm not trying to make all code reading a linear activity; that would be truly quixotic. I want to keep the code organized for the convenience of the writer but still provide an initial orientation for newcomers, when they aren't concerned with error handling or precise interface boundaries.

---

Finding the right version to look at is part of the solution, as you noticed. But there's a second half: making sure the information newcomers need is actually in the repo. Somewhere, anywhere. My sense is that existing codebases don't actually contain all the information needed to truly comprehend them. The context the system runs in, and all the precise issues it guards against. Tests are a huge help here, but I'm constantly making changes to code that I tested in some other terminal or browser window with some complex workflow. Then I often save the code in one window and close the other window. That's a huge loss of information, and it's compounding over and over again in current platforms. All because there are manual tests we can do that aren't easily encoded as automated tests.

It's certainly possible to port my ideas to an existing stack so that more tests can be represented. But how do we recover all the knowledge that has been lost so far?

---

I don't think the problem is that authors make mistakes[2]. They understand the domain far better than an outsider like me. No, the problem is that authors don't capture everything that is in their heads, and that means that I make mistakes when I try to build on their work.

One selfish reason I care about making the global structure of my codebase comprehensible is the very slight hope that others can take it in new directions and add expertise I won't ever gain by myself, in a way that I and others can learn from.

---

"...most of the causes you identified (backwards compatibility considerations, churn in personnel, vestigial features) can be real and unavoidable: there may be features that are needed only for (say) users of old systems but still cannot simply be removed. The best that can be hoped for is to make this fact clearer, not to make them go away."

If the codebase is more comprehensible and captures all compatibility and other concerns as tests, then it becomes easy to fork. Users of old systems could stay on one fork and others could be on a simpler fork that deletes the compatibility tests and the code that implements them. That way they aren't paying a complexity penalty for what they don't use. The tests would make it tractable to exchange code between the two forks, even if they diverge pretty far over time. Or so I hope.

---

Thank you again for your detailed feedback. Now I have a sense of a few more issues to avoid in my writing.

[1] That's partly my complaint with typography in LP: we end up polishing one happy path to death.

[2] If you notice places in my writing that strengthen this impression that I'm trying to reduce mistakes, I'd really appreciate hearing about them. I'm explicitly trying to avoid the failure mode that I think projects like TUNES fall into, of trying to come up with the one perfect architecture.

Re: Programs to Read

#58
post #44

Knuth vs McIlroy's solutions for a Word Frequency programming challenge: http://www.leancrew.com/all-this/2011/12/more-shell-less-egg... Knuth's solution has its own elegance and interest including various efficiencies and from-scratch facilities. McIlroy's will make you wonder how much you're wasting in time and complexity.

Anywhere I can see Knuth's solution online? Can't seem to find the link in there.

Here's the paper:

https://www.cs.tufts.edu/~nr/cs257/archive/don-knuth/pearls-...

(ACM ref, too: https://dl.acm.org/citation.cfm?id=315654 )

Also, I found a blog post which links to a C version of the exercise in the spirit of Knuth's approach, and a Haskell version in the spirit of McIlroy's:

https://franklinchen.com/blog/2011/12/08/revisiting-knuth-an...

Re: Programs to Read

#59
post #47
post #8

Earlier quoted context omitted.

> Ward Cunningham decided to close c2 to new material in part because he got tired of battling a determined vandal who was all bent out of shape over grammer and spailing It's honestly pretty upsetting that one vandal is enough to ruin one of the oldest and most significant institutions on the web for everybody.

I think it has value as a snapshot archive as well. The article on extreme programming would look quite different today.

The reworked version doesn't show the original indentation of discussion trees, making it harder to read. All bullet points have been flattened to one level, compared to the the original, which showed many levels.

Re: Programs to Read

#60
post #29

Earlier quoted context omitted.

Have you actually done this? What was your experience?

Not for Linux, but it's how I approach new programs I have to work on. I can't decipher this 1000-line function, but it came from somewhere. What did it start out as? That's what the author originally intended it to be. What caused it to grow? That's what features someone else thought it needed.

How long does this sort of thing take? Its a really neat approach but seems huge
Post reply on HN