I think code is sort of a combination of literature, ToDO and shopping lists, and directions to somebody's house, written from your own perspective. There are recurring themes and characters, but it can get lost in a sea of detail.
Having just implemented a specification where the spec was less useful than some source, I'd say that literature is not code for sure. And as someone who has read literature, though I wasn'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't even compare for entertainment value for example.
That's an interesting point, that literature can also be approached as a dissection. But I think that Mr. Seibel's observation still holds. Literature is primarily intended to be read and discussed, while code is primarily intended to perform a job. One lends itself to an experiential conversation and the other very contextual explaination.
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?
Because we're stuck in a tyranny of flat text files as a representation of code.
There have been countless proposals over the years for some kind of richer file format for representing code and they have all been busts because so much of our tooling, assumptions, interoperability and culture is centered on flat text code that it's proven impossible thus far to switch.
I try to, but that's beside the point. What passes for 'easy to understand' when you move past 'flat text files as a representation of code' and how is it better?
Good naming practice. Either pull each line of non-trivial code out into it's own method, or assign the output of the code to a variable that tells you what it's doing.
If you find yourself repeating an assignment, pull it out into a function and remove the duplication.
Rinse and repeat until everything in the file is assigned to a descriptive function or variable. Doing this with someone else's code gives you a feel for how to do it with your own.
At the moment I can open up source code in almost any language up in any text editor. It just has to know the encoding and vomit out characters I can comprehend and get the line breaks right. I can print it out and have a hard copy which represents what was written by the programmer. Send it and receive it by email and read it.
Code which can be represented as plaintext is versatile and portable and, more importantly, has its comprehensibility decoupled from any specific company, or project or group providing the necessary tools to make it human-readable. If an alternative file format isn't natively human-readable then it is by my definition less readable regardless of the standards put into writing the code itself.
I am the founder of Crudzilla Software (see profile for link) a web dev platform.
We use jsr-223 which allows scripting engines for other languages to be integrated into the jvm. What we did was create a file format that serves as a meta-wrapper around pieces of code, we call this wrapper a "crud".
This turns out to be quite powerful as it allows the code to have additional instructions associated with it. For instance input validation, security and configuration can be specified along with the code they apply to.
Freeing code from the constraints of text files would allow different ways to interact with it. Visual programming, REPLs, etc, could work more smoothly in the same workflow as a traditional text editor.
- The developer is usually the best person to write down the reasons a line was written.
- It's quicker to add an inline note than to switch context to a documentation panel.
- It's more complex to have to link a line to a documentation blob as in the example.
- A lot of people don't use IDEs; something like that would be necessary given the lower-level work that would need to go on with timestamping and linking code and documentation bits.
"Good enough" principles make inline comments a clear choice, I'd think. Plus, seeing the comment in context may provide cognitive benefits; the comment and code block grouped in the same space helps recognize and associate their linkage in a way cross-highlighting one or the other may not.
The only way I see this getting any traction is if some wildly popular editor (Emacs?) implements it as a built-in, braindead-simple feature. Then users will start to demand it of other editors.
Code can be literature in specific cases, such as the Shakespeare programming language. It's just a whimsical, esoteric language, like lolcode, but it reads like the Immortal Bard himself was an early adopter of learning to program.
Example of a conditional statement:
Juliet:
Am I better than you?
Hamlet:
If so, let us proceed to scene III.
Shakespeare is only superficially readable. In reality, the logic executed by the program is very nearly unrelated to the way the program reads to a human. Essentially it's a cute syntax over the same old FORTRAN, much like lolcode. It was a missed opportunity to represent logic as meaningful literature.
Asking people what they've read "just for the heck of it" is the wrong question, because code is not linear, so it's extremely ungainly to read without purpose.
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.
So I don't like the "nobody actually reads code" claim. It's a strawman. When I tell people to read code, it's always in the context of "pick something you want to understand or fix, and read with that purpose in mind." Not "the Linux kernel is like Moby Dick, you should really read it all."
I think that asking "what repos have you cloned just so that you could look at something, not intending on actually building or using that particular code" is probably roughly analogous to asking "what Wikipedia pages have you read recently" I frequently do both of those for the same reasons.
I might pull up the wikipedia page for the Apollo Lunar Module because I suddenly realize that I don't know how the RCS thrusters on it work, or I might clone git's repo because I suddenly realize that I don't know how git-notes is implemented.
In either case, I don't read the whole thing (and certainly not straight through in a linear manner, like I read Moby Dick), but rather I'm going to grep/ctrl-f to the part that I'm interested in, then probably jump around a dozen or more times until I am satisfied. That's still reading though.
You just made me realize that github needs better search. I like the presentation on github but, without git grep, I just pull it local and read from there.
Yes I agree. But, for myself, even (or especially) with a purpose I mind, I decode, not read per se. I've recently been working through the selfoss source and adding some new features, and this is the tack I've taken through it -- decode the source to find where the feature should be added. So I agree with you, and the OP.
Agreed. It's more like dense technical writing than literature.
That doesn't mean that reading it is any less important, or that writing readable code is any less important, or that code is all an ugly mess not worth reading.
It may mean that the reading pattern for code might not lend itself toward a reading group in the same way that literature does. So we might need to either spend more time reading code in solitude or develop new ways to do reading groups that work for this style of writing.
And it just seems plain ridiculous to say that people don't spend time reading code. People do read code, but they don't think about it as "reading" in the same way as someone reads a book, so they don't have it readily at hand when asked.
>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.
I really enjoyed reading this article, but I would argue with its headline. Based on the author'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.
The literary analog for code reading might be a writing a scholarly reader's companion to a book.
You can'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 >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.
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.
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.
A great group blog that keeps tabs on interactive and generative literature is http://grandtextauto.org/. I highly recommend it.
I wonder how blurred the lines can truly become between code and literature, though. If a piece of code is primarily intended to be read and discussed, does that make it literature?
Reading code is regularly useful for discovering language specific idioms/patterns about efficiencies, safety and clarity. That is why you should try to read well written code for learning. Reading poorly written code for any kind of edification is a waste of time.
In this sense code can be used like a well written novel can be used by an aspiring novelist -- to better learn the craft.
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: http://lxr.free-electrons.com/
I still look through other sources, including man pages, books and a lot of googling. But sometimes I just want to see what it is I'm dealing with. I do this with all code bases I deal with. I think it's a good practice to get into.
I like to read cross-referenced code too. I built "SherlockCode" a while ago as a generic tool to browse code but I haven't done anything with it in a while. Here is a sample of a symbol in a file in jQuery:
Perhaps the most important insight to be gained from this article is Abelson's statement that "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." There is an old blog entry by Joel Spolski that elaborates on this phenomenon:
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.
Interesting. Does something exist where I can visually trace through how my javascript code is being executed? It would be wonderful to have a visual representation.
Most browsers have a "Development Tools" option that provides a number of tools including a step-through debugger similar to those in XCode/Eclipse/Visual Studio.
I personally use the development tools in Safari most of the time.
I tend to use Safari (on Mac OS) as my go to browser, so the simplest answer is probably familiarity as corresponding functionality exists in Chrome and Firefox which I've had no problems using when needed. That said, IE is not so good.
I think Chrome and/or Firefox provide more support for live editing of the current web page, however I've never made much use of that functionality.
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.
You summarize very well exactly what I felt from the article. I sometimes feel the metaphor goes the other way, that is, when I seriously read a literature (in my case, it's often a play) I feel like I'm "decoding" it.
Absofulukingtely. Litterature is like code, can be pretty obvious and linear and you just read it, or it can be deeply intelligent and you decode it, ponder over what it implies and what it assumes.
Have you ever had a reason to read just part of a book? Pages 236-241 of Moby Dick, with no intention to ever read the rest? That seems to be a crucial difference between the two activities.
Moby Dick is probably a poor example. Something like the Iliad or the Bible might be appropriate since extensive studies often focus on a few chapters or verses. Yes, one normally reads the entirety of the work, but studying specific parts seems more apropos.
None of your examples are very good examples of "literature" as it's usually understood - in everyday use, the term by itself denotes prose fiction (and often excepting pulp novels).
Not by coincidence, this is the "limited" definition Seibel uses.
Personally, I have to use the skills I gained learning rhetoric and analyzing literature to make sense of some code bases. I've seen some shocking ball-o-mud code bases, and the only way to make sense of it was to understand the author(s), though never having met them. And to understand the subtext of the syntax, despite inconsistent application (poor naming convention and mixing ladder and structured text is like reading illuminated medieval engravings). There's code smells and slight variation in copy/paste blocks that belie the history of edits. There are threads woven through multiple volumes, where deprecated interlocks and crossed wires lead to bizarre plot twists. It's easy to think of certain machines as having personalities (or mental disorders, as the case may be). And there's never just an atomic dozen lines of code; at best you can reference five subroutines across two PLCs to describe what may be going on. And like good literature, you can't spoil the ending, as the joy is in the retelling of the story (of how you tracked down what was really happening).
It doesn't have to be a fascinating travesty, but I've yet to see a boring, dull, straightforward control system. Perhaps industrial programming logic just naturally turns out that way.
But it sure feels like Moby Dick, both in size, depth, and the unreliable narrator.
Seibel studied English, has written some popular programming books, and has had the experience of trying to set up code-reading seminars at multiple companies.[1] The key points of the article were 1) many programming gurus recommend reading code yet nobody does this; and 2) applying a lit-seminar approach to investigating code doesn't really work. That's all he was saying. There's no need to imply that his understanding of literature is limited to pulp fiction (I highly doubt that it is).
If you go through life looking for opportunities to argue semantics, you won't be disappointed. But you'll also miss most of the meaning.
The author doesn't have a limited definition of literature, he's merely using one. It's pretty clear from context that he's talking about well-regarded prose novels, which is a perfectly cromulent usage of the word.
"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's the only thing that's ever worked for me."
This strategy may work for small programs, but it doesn't scale to large programs. For example, most people aren't going to have the time to refactor Firefox or the Linux kernel to figure out how they work.
Also, it'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's analogy of a program being a scientific specimen: the code is a living specimen whose behavior can be studied, not just a dead specimen that can be stained and looked at under a microscope.
That's a good point about running it in the debugger.
However, even with a large program, sometimes I find it helpful to write a smaller program that does much the same thing as a small part of it. For example, last year I wrote a debugger frontend in Dart, based on the Chrome DevTools debugger. Whenever I wanted to implement something I'd first look at how the Chrome debugger did it.
Currently I'm working on a reimplementation of the React framework, also in Dart.
Seems like a worse metaphor to me, naturalists don't examine specimens in order to learn how to make better animals but that's precisely the reason coders are expected to improve by reading code (although I always assumed that "reading code" meant reading it over and over to get a detailed understanding but apparently that was just me?).
What is the goal of reading literature we're talking about? We're mixing up reading a book for pleasure and gaining a deep understanding of a piece of literature to become a better writer.
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.
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/modifying a library I was using (the Requests lib in Python). It's very nicely written and I did get some good ideas from it, but it was work.
I don'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?
May I bring up that whether or not you read code, you ain't gonna read it literally. Imagine following all jump statements with out fail. That's the machine's job, not yours.
As someone who also tried to hold code reading groups I agree 100% with the conclusion.
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.
Code is not literature because literature only contains the highlights worth knowing where code has to provide the comprehensive instructions for everything to operate.
A good code reader should be like a tour guide, and a good tour guide doesn'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.
"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..."
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 'context'. 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.
> we cannot attach comments to the evolution of code
I guess Google has spoiled me. When reading code, I constantly look at its development history - commit messages, diffs and line-by-line "blame", linked bugs and code review threads. If you have good tools for that, there's much less need for inline comments.
I am not English major, but I am pretty sure that the idea of becoming a writer by reading pieces of other people's texts is wrong. This is simply not enough. There is a "second component" in good writing, and it is not just about language usage.
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.)
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.
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.
The code of "the top writers" 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.
So, reading "good" 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.
But programming is about writing, which means expressing ones own ideas and realizations and understanding, so one must have these in the first place.
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.
This reflects the process of "emergence" 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.
Of course, reading Java is as meaningless as reading graphomans or some lame and lenthy political pamphlet in a third-rate newspaper.)
"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."
Are you sure that's true? Can you cite some examples?
Lisp is famous for its interactivity: the read-eval-print loop, SLIME, Lisp Machines, Emacs, etc. Avid Lisp hackers even edit code inside of running systems. The "bottom-up approach" to programming (as advocated by Paul Graham) is almost the opposite of what you describe, isn't it?
Generally speaking, I think both programmers and poets work in a dynamic way with their texts: moving stuff around, seeing what works, doing experiments, asking others, etc.
That's one reason why Knuth's idea of literate programming seems so academic and remote for most programmers: how are you going to keep all of that text up-to-date when you start refactoring?
I would say that there is no contradiction with bottom-up approach, and it was popularized before PG by SICP lectures with image manipulation DSL for making these beautiful recursive image patterns.
Your each iteration in a bottom-up process could be based on a small insight after thinking about a subproblem. Later one just re-uses ones own realizations and adapts them to new requirements.
Also I think that it should be not just linear bottom-up process, but recursive one, when you regularly "call yourself" with the old problem, but a "new you, evolved with experience". Starting from the bottom, from basic building blocks is crucial. The only "addition" is that nothing will be set in stone and you should come back to "simplify" and refactor even what is at the very bottom.
I also never advocated Knuth's idea or that whole programs should be printed as books (while some procedures such as map or append are worth to be printed and framed).
As for poetry, well, I thing almost every youth wrote some in his late teens or early twenties, and yes, I told it wrong, not a whole poem emerges in ones mind, but a few central passages, the main scheme, to which some ornaments could be added later.
Of course, the whole point of "literate programming" 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.
I feel that this is really nothing that a good compiler couldn'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't help me understand what I was trying to do.
So, in the vein of reading code. I've only read a few sections of "The Stanford Graphbase," 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.
Further, all of the "literate" programs I have written have been much easier for me to jump back into. Precisely because I have much of my "decoding" notes. So, code isn't literature, because we don't write it with a narrative for humans in mind. But, there is no real reason we couldn't.
87 comments
[ 3.1 ms ] story [ 164 ms ] threadhttp://i.stack.imgur.com/JlUiE.png
The potential advantages include:
- More source code and more documentation on the screen(s) at once
- Ability to edit documentation independently of source code (regardless of language?)
- Write documentation and source code in parallel without merge conflicts
- Real-time hyperlinked documentation with superior text formatting
- Quasi-real-time machine translation into different natural languages
- Every line of code can be clearly linked to a task, business requirement, etc.
- Documentation could automatically timestamp when each line of code was written (metrics)
- Dynamic inclusion of architecture diagrams, images to explain relations, call-graph hierarchies, etc.
- Single-source documentation (e.g., tag code snippets for user inclusion in manual[s]).
There have been countless proposals over the years for some kind of richer file format for representing code and they have all been busts because so much of our tooling, assumptions, interoperability and culture is centered on flat text code that it's proven impossible thus far to switch.
If there are other known features that are more important, they would have taken off by now.
If you find yourself repeating an assignment, pull it out into a function and remove the duplication.
Rinse and repeat until everything in the file is assigned to a descriptive function or variable. Doing this with someone else's code gives you a feel for how to do it with your own.
Code which can be represented as plaintext is versatile and portable and, more importantly, has its comprehensibility decoupled from any specific company, or project or group providing the necessary tools to make it human-readable. If an alternative file format isn't natively human-readable then it is by my definition less readable regardless of the standards put into writing the code itself.
I am the founder of Crudzilla Software (see profile for link) a web dev platform.
We use jsr-223 which allows scripting engines for other languages to be integrated into the jvm. What we did was create a file format that serves as a meta-wrapper around pieces of code, we call this wrapper a "crud".
This turns out to be quite powerful as it allows the code to have additional instructions associated with it. For instance input validation, security and configuration can be specified along with the code they apply to.
Their simplicity is also a strength. That richer file format will at some point be written in a text file.
Although Smalltalk imaging systems are an interesting alternative.
Freeing code from the constraints of text files would allow different ways to interact with it. Visual programming, REPLs, etc, could work more smoothly in the same workflow as a traditional text editor.
"Good enough" principles make inline comments a clear choice, I'd think. Plus, seeing the comment in context may provide cognitive benefits; the comment and code block grouped in the same space helps recognize and associate their linkage in a way cross-highlighting one or the other may not.
Example of a conditional statement:
http://en.wikipedia.org/wiki/Shakespeare_(programming_langua...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.
So I don't like the "nobody actually reads code" claim. It's a strawman. When I tell people to read code, it's always in the context of "pick something you want to understand or fix, and read with that purpose in mind." Not "the Linux kernel is like Moby Dick, you should really read it all."
I think that asking "what repos have you cloned just so that you could look at something, not intending on actually building or using that particular code" is probably roughly analogous to asking "what Wikipedia pages have you read recently" I frequently do both of those for the same reasons.
I might pull up the wikipedia page for the Apollo Lunar Module because I suddenly realize that I don't know how the RCS thrusters on it work, or I might clone git's repo because I suddenly realize that I don't know how git-notes is implemented.
In either case, I don't read the whole thing (and certainly not straight through in a linear manner, like I read Moby Dick), but rather I'm going to grep/ctrl-f to the part that I'm interested in, then probably jump around a dozen or more times until I am satisfied. That's still reading though.
I still end up pulling down the repo and using grep 90% of the time. OpenGrok is what I use when I don't even know which repo I'm interested in.
Example: https://github.com/django/django/search?q=modelchoicefield&t...
That doesn't mean that reading it is any less important, or that writing readable code is any less important, or that code is all an ugly mess not worth reading.
It may mean that the reading pattern for code might not lend itself toward a reading group in the same way that literature does. So we might need to either spend more time reading code in solitude or develop new ways to do reading groups that work for this style of writing.
And it just seems plain ridiculous to say that people don't spend time reading code. People do read code, but they don't think about it as "reading" in the same way as someone reads a book, so they don't have it readily at hand when asked.
I really enjoyed reading this article, but I would argue with its headline. Based on the author'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.
The literary analog for code reading might be a writing a scholarly reader's companion to a book.
You can'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 >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.
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.
http://en.wikipedia.org/wiki/Oulipo
I wonder how blurred the lines can truly become between code and literature, though. If a piece of code is primarily intended to be read and discussed, does that make it literature?
In this sense code can be used like a well written novel can be used by an aspiring novelist -- to better learn the craft.
I still look through other sources, including man pages, books and a lot of googling. But sometimes I just want to see what it is I'm dealing with. I do this with all code bases I deal with. I think it's a good practice to get into.
http://sherlockcode.com/demos/jquery/#!/src/attributes.js:pr...
http://www.joelonsoftware.com/articles/fog0000000069.html
I personally use the development tools in Safari most of the time.
I think Chrome and/or Firefox provide more support for live editing of the current web page, however I've never made much use of that functionality.
Of course I have. Any time I've picked up a reference book, textbook, or anthology.
books != novels
Personally, I have to use the skills I gained learning rhetoric and analyzing literature to make sense of some code bases. I've seen some shocking ball-o-mud code bases, and the only way to make sense of it was to understand the author(s), though never having met them. And to understand the subtext of the syntax, despite inconsistent application (poor naming convention and mixing ladder and structured text is like reading illuminated medieval engravings). There's code smells and slight variation in copy/paste blocks that belie the history of edits. There are threads woven through multiple volumes, where deprecated interlocks and crossed wires lead to bizarre plot twists. It's easy to think of certain machines as having personalities (or mental disorders, as the case may be). And there's never just an atomic dozen lines of code; at best you can reference five subroutines across two PLCs to describe what may be going on. And like good literature, you can't spoil the ending, as the joy is in the retelling of the story (of how you tracked down what was really happening).
It doesn't have to be a fascinating travesty, but I've yet to see a boring, dull, straightforward control system. Perhaps industrial programming logic just naturally turns out that way.
But it sure feels like Moby Dick, both in size, depth, and the unreliable narrator.
Seibel studied English, has written some popular programming books, and has had the experience of trying to set up code-reading seminars at multiple companies.[1] The key points of the article were 1) many programming gurus recommend reading code yet nobody does this; and 2) applying a lit-seminar approach to investigating code doesn't really work. That's all he was saying. There's no need to imply that his understanding of literature is limited to pulp fiction (I highly doubt that it is).
If you go through life looking for opportunities to argue semantics, you won't be disappointed. But you'll also miss most of the meaning.
[1] http://www.amazon.com/s/?field-keywords=peter%20seibel
This is how I code and read code..damn and I thought I never would see the day where someone finally got it..
This strategy may work for small programs, but it doesn't scale to large programs. For example, most people aren't going to have the time to refactor Firefox or the Linux kernel to figure out how they work.
Also, it'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's analogy of a program being a scientific specimen: the code is a living specimen whose behavior can be studied, not just a dead specimen that can be stained and looked at under a microscope.
However, even with a large program, sometimes I find it helpful to write a smaller program that does much the same thing as a small part of it. For example, last year I wrote a debugger frontend in Dart, based on the Chrome DevTools debugger. Whenever I wanted to implement something I'd first look at how the Chrome debugger did it.
Currently I'm working on a reimplementation of the React framework, also in Dart.
What is the goal of reading literature we're talking about? We're mixing up reading a book for pleasure and gaining a deep understanding of a piece of literature to become a better writer.
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.
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/modifying a library I was using (the Requests lib in Python). It's very nicely written and I did get some good ideas from it, but it was work.
I don'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?
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.
A good code reader should be like a tour guide, and a good tour guide doesn'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.
I do get lots of value out of that. My favorite example is Beazley's GIL talk: http://www.youtube.com/watch?v=Obt-vMVdM8s
I guess Google has spoiled me. When reading code, I constantly look at its development history - commit messages, diffs and line-by-line "blame", linked bugs and code review threads. If you have good tools for that, there's much less need for inline comments.
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.)
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.
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.
The code of "the top writers" 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.
So, reading "good" 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.
But programming is about writing, which means expressing ones own ideas and realizations and understanding, so one must have these in the first place.
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.
This reflects the process of "emergence" 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.
Of course, reading Java is as meaningless as reading graphomans or some lame and lenthy political pamphlet in a third-rate newspaper.)
Are you sure that's true? Can you cite some examples?
Lisp is famous for its interactivity: the read-eval-print loop, SLIME, Lisp Machines, Emacs, etc. Avid Lisp hackers even edit code inside of running systems. The "bottom-up approach" to programming (as advocated by Paul Graham) is almost the opposite of what you describe, isn't it?
Generally speaking, I think both programmers and poets work in a dynamic way with their texts: moving stuff around, seeing what works, doing experiments, asking others, etc.
That's one reason why Knuth's idea of literate programming seems so academic and remote for most programmers: how are you going to keep all of that text up-to-date when you start refactoring?
Your each iteration in a bottom-up process could be based on a small insight after thinking about a subproblem. Later one just re-uses ones own realizations and adapts them to new requirements.
Also I think that it should be not just linear bottom-up process, but recursive one, when you regularly "call yourself" with the old problem, but a "new you, evolved with experience". Starting from the bottom, from basic building blocks is crucial. The only "addition" is that nothing will be set in stone and you should come back to "simplify" and refactor even what is at the very bottom.
I also never advocated Knuth's idea or that whole programs should be printed as books (while some procedures such as map or append are worth to be printed and framed).
As for poetry, well, I thing almost every youth wrote some in his late teens or early twenties, and yes, I told it wrong, not a whole poem emerges in ones mind, but a few central passages, the main scheme, to which some ornaments could be added later.
I feel that this is really nothing that a good compiler couldn'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't help me understand what I was trying to do.
So, in the vein of reading code. I've only read a few sections of "The Stanford Graphbase," 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.
Further, all of the "literate" programs I have written have been much easier for me to jump back into. Precisely because I have much of my "decoding" notes. So, code isn't literature, because we don't write it with a narrative for humans in mind. But, there is no real reason we couldn't.