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.

Code is not Literature

240 pointsby antifuchsover 11 years ago

33 comments

ef4over 11 years ago
Asking people what they&#x27;ve read &quot;just for the heck of it&quot; is the wrong question, because <i>code is not linear</i>, so it&#x27;s extremely ungainly to read without purpose.<p>But as soon as the skilled code reader has a purpose in mind -- a question to answer -- he or she can rapidly find a meaningful narrative. Put into that context, programmers read code constantly, and the more they read the better they get.<p>So I don&#x27;t like the &quot;nobody actually reads code&quot; claim. It&#x27;s a strawman. When I tell people to read code, it&#x27;s always in the context of &quot;pick something you want to understand or fix, and read with that purpose in mind.&quot; Not &quot;the Linux kernel is like Moby Dick, you should really read it all.&quot;
评论 #7093865 未加载
评论 #7093831 未加载
评论 #7092652 未加载
评论 #7092753 未加载
评论 #7095722 未加载
评论 #7093038 未加载
评论 #7092305 未加载
jacobolusover 11 years ago
I think the author has a somewhat limited definition of “literature”, though he ultimately comes to the right conclusion that code must be “studied”, not “read”. It’s true, code is typically less linear than a pulp novel, but other types of literature are also involved, with layered meanings, which must be examined carefully, with reference material handy, and lots of flipping back and forth between sections. For instance, poems, philosophical treatises, historical analyses, and math textbooks must all typically be read this way.
评论 #7095892 未加载
评论 #7094333 未加载
评论 #7092614 未加载
评论 #7094132 未加载
评论 #7093145 未加载
评论 #7096702 未加载
bgilroy26over 11 years ago
&gt;It was just basically the way you solve some kind of an unknown puzzle—make tables and charts and get a little more information here and make a hypothesis. In general when I’m reading a technical paper, it’s the same challenge. I’m trying to get into the author’s mind, trying to figure out what the concept is. The more you learn to read other people’s stuff, the more able you are to invent your own in the future, it seems to me.<p>I really enjoyed reading this article, but I would argue with its headline. Based on the author&#x27;s experience and the example from Donald Knuth, it seems like the best way to read code is to go through it multiple times to the point where you could reimplement it or provide complete documentation for it.<p>The literary analog for code reading might be a writing a scholarly reader&#x27;s companion to a book.<p>You can&#x27;t write a secondary source for a work of literature by reading it once through like a drugstore thriller or romance. A literary analyst would read the book through completely &gt;3 times and spend hours on certain key passages. They would take extensive notes reconstructing the innerworkings of the characters, the relationships between them, and key themes. Once the work has been comprehensively understood, the scholar can write out in an expository manner what is going on in the piece of literature, the same way that a thoroughly digested piece of software can be rewritten based on the mental model that develops as you read.<p>Obviously software and novels do not map completely one onto the other. I think the key similarity is that they both can be created with sufficient complexity to require taking multiple passes and following along with the author, building something similar yourself in order to truly understand them.
thangalinover 11 years ago
Why do we still embed natural language descriptions of source code (i.e., the reason why a line of code was written) within the source code to the exclusion of intrinsically linked separate documents?<p><a href="http://i.stack.imgur.com/JlUiE.png" rel="nofollow">http:&#x2F;&#x2F;i.stack.imgur.com&#x2F;JlUiE.png</a><p>The potential advantages include:<p>- More source code and more documentation on the screen(s) at once<p>- Ability to edit documentation independently of source code (regardless of language?)<p>- Write documentation and source code in parallel without merge conflicts<p>- Real-time hyperlinked documentation with superior text formatting<p>- Quasi-real-time machine translation into different natural languages<p>- Every line of code can be clearly linked to a task, business requirement, etc.<p>- Documentation could automatically timestamp when each line of code was written (metrics)<p>- Dynamic inclusion of architecture diagrams, images to explain relations, call-graph hierarchies, etc.<p>- Single-source documentation (e.g., tag code snippets for user inclusion in manual[s]).
评论 #7092038 未加载
评论 #7092051 未加载
评论 #7096733 未加载
评论 #7092117 未加载
mbrockover 11 years ago
Christopher Alexander, the architect who introduced the theory of &quot;pattern languages,&quot; wrote the introduction to Richard P. Gabriel&#x27;s &quot;Patterns of Software.&quot; He says:<p>&quot;In my life as an architect, I find that the single thing which inhibits young professionals, new students most severely, is their acceptance of standards that are too low. If I ask a student whether her design is as good as Chartres, she often smiles tolerantly at me as if to say, &#x27;Of course not, that isn&#x27;t what I am trying to do. I could never do that.&#x27;&quot;<p>Then: &quot;That standard must be our standard. If you are going to be a builder, no other standard is worthwhile.&quot;<p>And so he asks the same thing about programming.<p>&quot;But at once I run into a problem. For a programmer, what is a comparable goal? What is the Chartres of programming? What task is at a high enough level to inspire people writing programs, to reach for the stars? Can you write a computer program on the same level as Fermat&#x27;s last theorem? Can you write a program which has the enabling power of Dr. Johnson&#x27;s dictionary? Can you write a program which has the productive power of Watt&#x27;s steam engine? Can you write a program which overcomes the gulf between the technical culture of our civilization, and which inserts itself into our human life as deeply as Eliot&#x27;s poems of the wasteland or Virginia Woolf&#x27;s The Waves?&quot;<p>Maybe code is just <i>bad</i> literature?
greenyodaover 11 years ago
&quot;<i>Once I’ve completely rewritten the thing I usually understand it pretty well and can even go back to the original and understand it too. I have always felt kind of bad about this approach to code reading but it&#x27;s the only thing that&#x27;s ever worked for me.</i>&quot;<p>This strategy may work for small programs, but it doesn&#x27;t scale to large programs. For example, most people aren&#x27;t going to have the time to refactor Firefox or the Linux kernel to figure out how they work.<p>Also, it&#x27;s hard to tell a lot about a large program just by reading a listing of the source code. Certain things about the code become much more obvious if you step through the running code with a debugger. To extend the author&#x27;s analogy of a program being a scientific specimen: the code is a <i>living</i> specimen whose <i>behavior</i> can be studied, not just a dead specimen that can be stained and looked at under a microscope.
评论 #7092628 未加载
scott_sover 11 years ago
Every time I have a serious question about how something works in the Linux kernel, I use it as an excuse to do a dive into the code: <a href="http://lxr.free-electrons.com/" rel="nofollow">http:&#x2F;&#x2F;lxr.free-electrons.com&#x2F;</a><p>I still look through other sources, including man pages, books and a lot of googling. But sometimes I just want to <i>see</i> what it is I&#x27;m dealing with. I do this with all code bases I deal with. I think it&#x27;s a good practice to get into.
评论 #7092411 未加载
golergkaover 11 years ago
This reminds me of how I listen to music.<p>If I meet a track that I really like, I don&#x27;t just listen to it. I put it on the decks, try to mix it with something else and listen how it interacts with it. I put it on the grid, sample loops, hits and small sounds. If you don&#x27;t understand what I&#x27;m talking about, here&#x27;s a video of Four Tet doing something similar to Jackson&#x27;s Thriller:<p><a href="http://www.youtube.com/watch?v=TUDsVxBtVIg" rel="nofollow">http:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=TUDsVxBtVIg</a><p>Sometimes I analyze it&#x27;s structure, laying empty loops in mute tracks alongside it. Sometimes I try to recreate synths that are used. Sometimes I go to whosampled.com and try to recreate the sampling process.<p>I&#x27;m sure writers do the same with literature they read, too.
thebearover 11 years ago
Perhaps the most important insight to be gained from this article is Abelson&#x27;s statement that &quot;a lot of times you crud up a program to make it finally work and do all of the things that you need it to do, so there’s a lot of extraneous stuff around there that isn’t the core idea.&quot; There is an old blog entry by Joel Spolski that elaborates on this phenomenon:<p><a href="http://www.joelonsoftware.com/articles/fog0000000069.html" rel="nofollow">http:&#x2F;&#x2F;www.joelonsoftware.com&#x2F;articles&#x2F;fog0000000069.html</a>
scottchaover 11 years ago
I agree with the author that code may not be literature. Taken from the opposite line of reasoning there have been movements in the past to make literature more like code. Specifically I thinking of Oulipo (which included Calvino as probably the most famous) on bringing new structures to literature including some generative ones which could be thought of as programming or combinatorics.<p><a href="http://en.wikipedia.org/wiki/Oulipo" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Oulipo</a>
评论 #7092047 未加载
thebearover 11 years ago
I would be interested to know what the OP thinks about stepping through code as opposed to reading it. To me, reading code and stepping through it in a debugger are two complimentary ways of understanding it. I call those the static and the dynamic way of viewing code.
评论 #7093326 未加载
auggieroseover 11 years ago
I try to read as little code as possible. If I have to read the code of somebody else (other than code review) it is usually because the code contains some flaw; only rarely because I genuinely don&#x27;t know how the code does what it claims to do.<p>Don&#x27;t read code. Read papers. Build a model of your algorithms etc. in your mind. Describe this model in a wiki. Translate the model into interfaces. Then write the code that implements those interfaces.
taericover 11 years ago
Of course, the whole point of &quot;literate programming&quot; is to provide hints and structure for the human reader. This is done not by creating some structure in the code that makes sense to the compiler and a human, but by breaking up a program into pieces that are put together later.<p>I feel that this is really nothing that a good compiler couldn&#x27;t do with a higher level language today. However, in doing so I would wind up with a heavily polluted namespace of helper methods and such that really don&#x27;t help me understand what I was trying to do.<p>So, in the vein of reading code. I&#x27;ve only read a few sections of &quot;The Stanford Graphbase,&quot; as I just got it a couple of weeks ago, but I can already tell this would have been a much better introduction to a few graph algorithms than I had in my undergrad.<p>Further, all of the &quot;literate&quot; programs I have written have been much easier for me to jump back into. Precisely because I have much of my &quot;decoding&quot; notes. So, code isn&#x27;t literature, because we don&#x27;t write it with a narrative for humans in mind. But, there is no real reason we couldn&#x27;t.
jackfoxyover 11 years ago
I like the OP&#x27;s summation that we should approach code reading as code decoding. My interest in literate code and readable code has recently accelerated in conjunction with my interest in code correctness. I think the way forward in both these contexts is through functional programming.<p>In particular I, and the IT shop at Tachyus, have chosen F# as the way to go forward for a number of reasons. Sticking to readability, F# (and other FPs to a greater or lesser extent) allow production code that &quot;reads&quot; more expressively in terms of conveying what the code is actually accomplishing to the reader (and to the compiler) rather than the frequently tangled instructions to the compiler on <i>how</i> to accomplish the task coming from traditional imperative and OO languages. F# also has some very useful tools to emit a form of literate code that produces publication ready HTML or MD, <a href="http://tpetricek.github.io/FSharp.Formatting/" rel="nofollow">http:&#x2F;&#x2F;tpetricek.github.io&#x2F;FSharp.Formatting&#x2F;</a> (This project will soon be accepted as a top-tier project by the F# Software Foundation, <a href="http://fsharp.org/" rel="nofollow">http:&#x2F;&#x2F;fsharp.org&#x2F;</a>) It may not be <i>to the letter</i> of Knuth&#x27;s idea of literate programming, but certainly in the spirit.<p>I did <i>read</i> some code lately. Actually I had to go so far as stepping through it in the debugger to properly <i>decode</i> it, <a href="http://jackfoxy.com/transparent-heterogeneous-parallel-async-with-fsharp/" rel="nofollow">http:&#x2F;&#x2F;jackfoxy.com&#x2F;transparent-heterogeneous-parallel-async...</a> (the code snippets here have tool-tips in my article, just one of the features available with FSharp.Formatting), but this is really the exception in F#. The vast majority of code is easily accessible to any programmer of reasonable quality (with proper introduction to FP) in any IT shop. The deeper functional stuff like Continuation Passing Style and Applicative Functors (e.g. heterogeneous parallel async) in most cases is already available in core libraries. And when not a literature search and&#x2F;or getting in touch with the FP community helps.
pjmorrisover 11 years ago
I think code is sort of a combination of literature, ToDO and shopping lists, and directions to somebody&#x27;s house, written from your own perspective. There are recurring themes and characters, but it can get lost in a sea of detail.
yareallyover 11 years ago
Code can be literature in specific cases, such as the Shakespeare programming language. It&#x27;s just a whimsical, esoteric language, like lolcode, but it reads like the Immortal Bard himself was an early adopter of learning to program.<p>Example of a conditional statement:<p><pre><code> Juliet: Am I better than you? Hamlet: If so, let us proceed to scene III. </code></pre> <a href="http://en.wikipedia.org/wiki/Shakespeare_(programming_language)" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Shakespeare_(programming_langua...</a>
评论 #7092422 未加载
freshhawkover 11 years ago
Seems like a worse metaphor to me, naturalists don&#x27;t examine specimens in order to learn how to make better animals but that&#x27;s precisely the reason coders are expected to improve by reading code (although I always assumed that &quot;reading code&quot; meant reading it over and over to get a detailed understanding but apparently that was just me?).<p>What is the goal of reading literature we&#x27;re talking about? We&#x27;re mixing up reading a book for pleasure and gaining a deep understanding of a piece of literature to become a better writer.<p>Reading a piece of code or a book once is not going to do anything to your skillset as a producer, at least books are specifically written to be read once for pleasure. The equivalent for code would be using a piece of software, not reading the code once.<p>If you want to be a better writer then you get a deep understanding of a piece of literature, the same applies to code. I have recently read a lot of code, because I was debugging&#x2F;modifying a library I was using (the Requests lib in Python). It&#x27;s very nicely written and I did get some good ideas from it, but it was work.<p>I don&#x27;t think the metaphor is flawed at all. I think that this was a result of coders thinking that people would get better at writing by reading literature or that this was the point of literature seminars. I guess a lesson in understanding other disciplines at least a little bit before trying to take lessons from them?
jeffdavisover 11 years ago
It&#x27;s a cultural, psychological, linguistic mixup more than anything else. People do read code all the time, they just hesitate to respond to a question like &quot;what code have you read recently&quot;. It&#x27;s hard to answer that question in english without implying that you have completely read a program (rare) that was completely written (in other words, &quot;finished&quot;, which is even more rare).<p>If you asked a different question, like &quot;explain how you read code in the course of a typical project or experiment&quot; you will get a ton of examples. They might describe how they look to understand the basic data structures, and then imagine some sample data flowing through the algorithm to understand the purpose, and then examine the details, edge cases, and interactions to see why some non-obvious choices were made. Then they might describe how they use this to find what parts of the code should be generalized, specialized, or extended to fit new functionality.<p>It might be interesting to incorporate code reading into an interview to see the strategies that people use. It would be quite difficult to make it a fair question, though, because patterns vary widely and it often takes more than an hour or so to adapt.
评论 #7094020 未加载
0xdeadbeefbabeover 11 years ago
Having just implemented a specification where the spec was less useful than some source, I&#x27;d say that literature is not code for sure. And as someone who has read literature, though I wasn&#x27;t an english major like the author--you know it seems like they encourage english majors to treat writing as a specimen--it seems true that code is not literature either, it doesn&#x27;t even compare for entertainment value for example.
评论 #7092016 未加载
jdnierover 11 years ago
Great quote from the article: &quot;But then it hit me. Code is not literature and we are not readers. Rather, interesting pieces of code are specimens and we are naturalists. So instead of trying to pick out a piece of code and reading it and then discussing it like a bunch of Comp Lit. grad students, I think a better model is for one of us to play the role of a 19th century naturalist returning from a trip to some exotic island to present to the local scientific society a discussion of the crazy beetles they found: &#x27;Look at the antenna on this monster! They look incredibly ungainly but the male of the species can use these to kill small frogs in whose carcass the females lay their eggs.&#x27;&quot;
m0nasticover 11 years ago
I imagine getting a bunch of people to sit around and project a cookbook recipe up on a screen.
amasadover 11 years ago
As someone who also tried to hold code reading groups I agree 100% with the conclusion.<p>The first code reading session I held, I chose underscore.js and it was a successful code reading session, because -- unlike most libraries and programs -- a functional utility library was a nice linear read with mostly self-contained functions. However, when we got to more complex programs and libraries with more code to handle accidental complexity (e.g. handle browser and DOM inconsistencies, or UNIX fragmentation etc) it was considerably harder to read and the presenter found themselves jumping between different code paths and functions like they were debugging the program.
markm208over 11 years ago
The main problem I see is that code is read left to right, top to bottom (for the most part) but it is rarely, if ever, written that way. The order that decisions are made is almost as important as the decisions themselves. But, we lose almost all of that order or &#x27;context&#x27;. Worse, although we can place comments in the code, we cannot attach comments to the evolution of code. Evolutional comments could describe why things are changing in the proper context and make reading code a lot easier.
评论 #7094357 未加载
snorkelover 11 years ago
Code is not literature because literature only contains the highlights worth knowing where code has to provide the comprehensive instructions for everything to operate.<p>A good code reader should be like a tour guide, and a good tour guide doesn&#x27;t visit every single building and street in a neighborhood but rather describes the historical context of the neighborhood and then visits a few interesting places.
famousactressover 11 years ago
<i>&quot;The point of such a presentation is to take a piece of code that the presenter has understood deeply and for them to help the audience understand the core ideas...&quot;</i><p>I do get lots of value out of that. My favorite example is Beazley&#x27;s GIL talk: <a href="http://www.youtube.com/watch?v=Obt-vMVdM8s" rel="nofollow">http:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=Obt-vMVdM8s</a>
henrik_wover 11 years ago
For me, the fastest way of understanding code is a mix (back and forth) of <i>reading</i> it and <i>running</i> it. Some questions on how it works are more easily answered by running it and seeing what happens, while other questions are better answered by reading (e.g. what are all the possible cases here?).
vorgover 11 years ago
At the very least, when we program we&#x27;re writing a story to whoever might need to understand it later on.
dspillettover 11 years ago
Oh, but it could be: <a href="http://en.wikipedia.org/wiki/Shakespeare_(programming_language)" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Shakespeare_(programming_langua...</a>
NAFV_Pover 11 years ago
May I bring up that whether or not you read code, you ain&#x27;t gonna read it literally. Imagine following all jump statements with out fail. That&#x27;s the machine&#x27;s job, not yours.
ktfover 11 years ago
Some literature really does need to be &quot;decoded&quot; in a similar way, however. (Speaking as someone who recently finished <i>Ulysses</i>...)
n1ghtmare_over 11 years ago
Emmm, so there are now &quot;Code reading groups&quot; ? I need to get with the times. Is this a new thing ?
fredgrottover 11 years ago
Oh my effing hell<p>This is how I code and read code..damn and I thought I never would see the day where someone finally got it..
dschiptsovover 11 years ago
I am not English major, but I am pretty sure that the idea of becoming a writer by reading pieces of other people&#x27;s texts is wrong. This is simply not enough. There is a &quot;second component&quot; in good writing, and it is not just about language usage.<p>One could read Selinger or Pamuk or Sartre or Hesse, to realize that this second component is much more important, while masters like Nabokov whose speciality is playing with words might show you that wording is also important.)<p>The transition from reading to writing ones own texts, not imitating or copy pasting is also not clear, and, of course, one never could become a good writer only by excessive reading. Writing and speaking are different cognitive tasks from reading or listening.<p>So what? Reading of good code is important, it teaches style, how to be brief, concise, precise. But where to find the good code? Well, the recursive list functions in Scheme are worth reading. Some parts of Haskell Prelude are worth reading, some macros of Common Lisp, etc.<p>The code of &quot;the top writers&quot; are worth reading. Code from PAIP or On Lisp or SICP are obvious examples, while some code, like from Practical CL which is mostly a mechanical translation of OO stuff only adds more confusion.<p>So, reading &quot;good&quot; code is still the must, the same way that reading Catcher In The Rye or Zen And Art Of Motorcycle Maintenance or Atlas Shrugged is still the must.<p>But programming is about writing, which means expressing ones own ideas and realizations and understanding, so one must have these in the first place.<p>In this sense programming is like writing a poetry - it must emerge and form in ones mind before it could be written down. The best poetry is written exactly like this - committed to the paper suddenly as it emerges, without any later changes.<p>This reflects the process of &quot;emergence&quot; of ideas or profs in a mind of scientists who are continuing to persue a problem for years - suddenly it is here, as if it came from subconscious. It seems that the best code, like these classic Lisp procedures or parts of Prelude has been written this way.<p>Of course, reading Java is as meaningless as reading graphomans or some lame and lenthy political pamphlet in a third-rate newspaper.)
评论 #7094938 未加载