Slashdot Mirror


Code Is Not Literature

An anonymous reader writes "Hacker and author Peter Seibel has done a lot of work to adopt one of the most widely-accepted practices toward becoming a better programmer: reading high quality code. He's set up code-reading groups and interviewed other programmers to see what code they read. But he's come to learn that the overwhelming majority of programmers don't practice what they preach. Why? He says, 'We don't read code, we decode it. We examine it. A piece of code is not literature; it is a specimen.' He relates an anecdote from Donald Knuth about figuring out a Fortran compiler, and indeed, it reads more like a 'scientific investigation' than the process we refer to as 'reading.' Seibel is now changing his code-reading group to account for this: '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.'"

51 of 240 comments (clear)

  1. Music... by Anonymous Coward · · Score: 2, Interesting

    ...works much better as a model. Performing music is analogous to executing code.

    1. Re:Music... by jellomizer · · Score: 4, Funny

      Not as much, it is closer but not really.

      The issue with Literature and Music there is a beginning, a middle and and a end.

      With Software there is a beginning, then the story changes every time the program runs, based on the input at the time. Leading to multiple end points, including a power off.
      Music is closer as it had notation that allows for some loops, however this is mostly to keep shorten the notation process and less about workflow.
      Also a choose your own adventure book, isn't that good analogy, as there are fixed number of stories possible.
      A relatively complex program can have different outcome all the time.

      --
      If something is so important that you feel the need to post it on the internet... It probably isn't that important.
    2. Re:Music... by camperdave · · Score: 2

      Never read a "choose your own adventure" did you?

      --
      When our name is on the back of your car, we're behind you all the way!
    3. Re:Music... by ShanghaiBill · · Score: 2

      Never read a "choose your own adventure" did you?

      "Choose your own plot" books have a very limited number of choices. The number of possible paths through code increases exponentially with the size of the program. Literature usually has the meaning the author intended. If you are reading code, it is usually because it does NOT do what the author intended.

    4. Re:Music... by mcgrew · · Score: 2

      What you guys are missing is that you're decoding the words on the screen right now. Reading just doesn't feel like decoding, especially if you're any good at it at all.

      My daughter is like that with sheet music. Give her a clarinet and sheet music for a song she never heard and she'll just play it. I decode musical notation like a five year old decodes Dr. Suess, she reads music like I read books.

      I use to write software, first as a hobby and later compiled PC databases and NOMAD mainframe coding at work (actually, they gave me training then changed my job, I never wrote any production NOMAD). Now I write books in my spare time (which I'll have more of as I'm retiring soon). Even though dBase and NOMAD are very, very similar in the way they operate (think C and C+), I don't think I read NOMAD code like I did dBase or assembly or BASIC, because reading is different than writing.

      I keep thinking of the Matrix programmers. "I only see blondes, brunettes, redheads..."

    5. Re:Music... by camperdave · · Score: 4, Funny

      BEGIN
      (* I'm dreaming of a white Christmas, *)
      (* Just like the ones I used to know. *)

      IF Christmas [ white ] AND
      ( Christmas [ white ] = Christmas [ known( me ) ] ) THEN
      me := dream( Christmas [ white ] );

      (* I'm dreaming of a white Christmas, *)
      (* with every Christmas card I write. *)

      FOR index := firstcard TO lastcard DO BEGIN
      WITH card [ index ] DO me := dream( Christmas [ white ] );
      END;

      (* When the tree-tops glisten, *)
      (* And children listen, *)
      (* To hear sleighbells in the snow. *)

      REPEAT wait UNTIL stateof ( tree.tops ) = glisten AND
      stateof( children ) = listen( noiseof1in2( bells.sleigh, snow ) ) ;

      (* May your days be merry and bright, *)

      FOR index := firstday TO lastday DO BEGIN
      day.yours[index] := (merry AND bright);
      END;

      (* and may all your Christmases be white. *)

      FOR index := firstxmas TO lastxmas DO
      Christmas.yours[index] := white;

      END.

      --
      When our name is on the back of your car, we're behind you all the way!
    6. Re:Music... by nschubach · · Score: 3, Insightful
      If musicians read sheet music like programmers read code, then why do a lot of programmers insist that everyone else comments their code? Do musicians insist that every other musician make comments on why they chose to raise the octave or what they were thinking when they chose that chord?

      // WTF was Beethoven thinking here...

      // This note wasn't right, I dropped it twice.

      // This part is the chorus, it will be played several times.

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
    7. Re:Music... by u38cg · · Score: 4, Informative

      I suggest you have a look at an orchestral performer's text sometime. More pencil than ink.

      --
      [FUCK BETA]
  2. Similar language, describing different things by hessian · · Score: 2

    Code is very similar to language. How would it not be?

    However, what's being described is entirely different. A narrative relies on both clear expression of the action and a broad context of details to give it resonance.

    Code, on the other hand, operates through loops and definitions independent of timeline, so is a better match for architecture and math than the science of communications.

    1. Re:Similar language, describing different things by JoeMerchant · · Score: 4, Insightful

      I've always been struck by the similarity of code and contracts or laws.

      When written well, they define a set of requirements for specific actions to take place, leaving no ambiguity.

      When written poorly, you need to know the version of system they are running under, starting circumstances, state of concurrently running processes, etc.

    2. Re:Similar language, describing different things by Marxist+Hacker+42 · · Score: 4, Insightful

      Correct. And just like laws- if regular people can't read what you have written, then likely you are doing it wrong.

      Bad law is always overly complex. The more complex it is, the more likely somebody has introduced some ambiguity.

      Bad code is also always overly complex. The more complex it is, the more likely it will take a week to do a job that should take an hour when maintaining it.

      --
      SJW: a person who perceives an injustice, and while correcting it, commits a greater injustice.
    3. Re:Similar language, describing different things by Anonymous Coward · · Score: 2, Interesting

      if regular people can't read what you have written, then likely you are doing it wrong.

      That seems like a stupid standard. What if that "regular" person simply has no experience in what you wrote? If I write perfectly good SIMD assembly and this mythical "regular" person can't read and follow it because they are unfamiliar with x86 MMX/SSE/AVX how is that my fault and why would that me my code bad?

    4. Re:Similar language, describing different things by Stormy+Dragon · · Score: 4, Interesting

      Please demonstrate a basic sorting algorithm that a non-programmer can understand that doesn't perform terribly on large lists. You might be able to write a bubble or insertion sort that makes sense to a layman, but for the majority of the population something like mergesort, quicksort, or heapsort is going to seem like voodoo no matter how elegantly it is coded.

    5. Re:Similar language, describing different things by wisnoskij · · Score: 2

      "Well written" and "law" is a contradiction in terms.

      --
      Troll is not a replacement for I disagree.
    6. Re:Similar language, describing different things by JoeMerchant · · Score: 3, Insightful

      If you are writing assembler, you _should_ be including a human readable commentary at some level.

      If you have put 5000 assembly instructions under a heading titled "object rotation and zoom", with no other commentary, your code _should_ be expelled from the system, regardless of how well it works on the test cases you made up for it.

    7. Re:Similar language, describing different things by JoeMerchant · · Score: 2

      When I use voodoo, I usually include hyperlinks to Wikipedia or similar sources explaining what's going on. Even when the links die, you can usually search on the algorithm names to come up with an explanation.

      More often, I let the library deal in the voodoo and my code reads like: while ( input ) { insert } sort.

    8. Re:Similar language, describing different things by Anonymous Coward · · Score: 2, Informative

      How about sorting a deck of cards using two of the algorithms you mentioned, quicksort and mergesort.

      Quicksort: Take a deck of cards, and pick a random card. Form two new decks by placing all cards smaller than it to the left deck and the larger or equal ones to the right deck. Repeat this for both decks, so you get more decks. Never move a deck over another. At the end just combine the decks from left to right in increasing order.

      Mergesort: 1. Place all cards on the table, each on its own slot. If there's not enough space, form decks of five cards each and sort them manually. 2. Take the two piles with the least cards in them (or close enough, doesn't matter). Find the smallest card in the two piles, and put it on the table. Put the next smallest table on top of the previous one, and so on, until there are no cards left. Leave the resulting pile on the table and continue from 2.

      Of course, a non-organized person might mess the decks, but others should be able to understand these. These instructions should give the correct asymptotic running times, assuming for example that the person realizes finding the minimum is quite simple when the decks are sorted.

    9. Re:Similar language, describing different things by Stormy+Dragon · · Score: 3, Insightful

      1. My point is not about how to teach someone how quicksort. It was refuting the commenters assertion that any code not understandble to regular people is bad code. Your quicksort.c file is not going to pick up a deck of cards and demonstrate what it's doing.

      2. I'm betting that for 60% of the population out there, they still would not understand how quicksort works after your card demonstration.

    10. Re:Similar language, describing different things by Sique · · Score: 2

      Bad laws don't need to be overly complex. Bad laws are just that: bad. You can have very simple laws which in general create a bad outcome.

      --
      .sig: Sique *sigh*
    11. Re:Similar language, describing different things by hamster_nz · · Score: 4, Informative

      but for the majority of the population something like mergesort, quicksort, or heapsort is going to seem like voodoo no matter how elegantly it is coded.

      Explaining quicksort to the layman.

      Here's a 1000 names on little cards. Pick one at random and look at the name.

      Sort the names into three piles - those that come earlier in the list, those that are the same as the name, and those that come later than the randomly selected name name.

      Put the "earlier" pile to the left of the "same" pile, and then put the "later" pile to the right of these two.

      Great? Done that?

      Now repeat on the process on each "earlier" and "later" piles, Do this over and over again, giving you smaller and smaller piles. It doesn't really matter which pile you split first, just as long as you don't mix up the relative left/right ordering.

      Eventually you will end up with lots of small piles of cards that contain all the entries of the same name.

      And then, as if by Voodoo., all your names are now in order from left to right.

      This can be parallelised - if you want, you can out-source some of the work to friends and family, to speed things up.

    12. Re:Similar language, describing different things by Marxist+Hacker+42 · · Score: 2

      Quicksort is just a double direction bubble sort. Mergesort, I'd agree, might seem like voodoo. Heapsort? That's just a filing cabinet.

      --
      SJW: a person who perceives an injustice, and while correcting it, commits a greater injustice.
    13. Re:Similar language, describing different things by Marxist+Hacker+42 · · Score: 4, Informative

      And yet, once again, I used to teach quicksort to 4th graders- when I was only an 8th grader myself. While it is possible that the general population has gotten significantly less intelligent in the intervening 30 years, it isn't very likely.

      If you can't comment in plain english, then your code is not maintainable.

      --
      SJW: a person who perceives an injustice, and while correcting it, commits a greater injustice.
    14. Re:Similar language, describing different things by Anonymous Coward · · Score: 3, Insightful

      Bullshit. Learning about the field of DSP alone takes years of study and books that are 100s of pages long of mathematical background. Code comments are never going to be able to teach someone an entire language and field to someone who doesn't know it. So, again, the fault is not with me or my code if Joe Schmoe doesn't know anything about the language or the problems my code solves.

  3. Code as a tool of thought? by DavidHumus · · Score: 2

    There is a (rather small) minority view that code can actually improve our ability to think - http://www.jsoftware.com/jwiki... . However, the bulk of opinion sees code as an obstacle to be overcome - rightly so, given the sloppy, ad-hoc construction of most programming languages.

  4. Consider your Audience when writing code by DickBreath · · Score: 4, Insightful

    When writing code, your audience is not the compiler.

    Your audience is another human being who will be maintaining that code a few years later.

    If your audience were the compiler, then your code would just need to compile and run. It could be ugly. Unreadable. Unmaintainable. Uncommented. Have meaningless identifiers. Poor organization. Follow worst practices. Etc. In short, the kind of code you get from an outsourced contractor.

    Consider that another human is your audience. Choose identifiers such that a comment is unnecessary. Comments should not say what is obvious. (This assigns foo to x.) Comments should say what is not obvious and cannot be made obvious by the code itself.

    Write your code almost as if you are writing literature.

    --

    I'll see your senator, and I'll raise you two judges.
    1. Re:Consider your Audience when writing code by Cro+Magnon · · Score: 2

      Consider that another human is your audience. Choose identifiers such that a comment is unnecessary. Comments should not say what is obvious. (This assigns foo to x.) Comments should say what is not obvious and cannot be made obvious by the code itself.

      That's one of my peeves. When I see a comment like that, I scream (usually silently) that I know you're assigning foo to x. I want to know WHY you're assigning foo to x!

      --
      Slow down, cowboy! It has been 4 hours since you last posted. You must wait another few hours.
    2. Re:Consider your Audience when writing code by DickBreath · · Score: 3, Insightful

      The programming language is irrelevant. Bad code can be written in any language. Really good code is an art in any language.

      The compiler is not an audience at all. The compiler is the first part of running the code. As far as the compiler is concerned, the code could be obfuscated.

      That fact that the code performs it's function is the first economic value of the code. But an equally large, and perhaps greater economic value (or cost) is how well another human can read and comprehend that code later on when managers decide to add pointless features or remove useful features.

      Most code is written for economic reasons of some type. Writing code for another human to easily comprehend later increases the economic value of that code -- possibly greatly.

      --

      I'll see your senator, and I'll raise you two judges.
    3. Re:Consider your Audience when writing code by HeckRuler · · Score: 4, Insightful

      Your audience is another human being who will be maintaining that code a few years later.

      And he's a violent psychopath who knows where you sleep at night.

    4. Re:Consider your Audience when writing code by DickBreath · · Score: 3, Funny

      > That's one of my peeves. When I see a comment like that, I scream . . .

      When someone does it, then put the following optimizations into their header files somewhere. Be sure to include the useful comments that explain their purpose.

      #define struct union // optimization to use less memory
      #define while if // optimization to make code run faster

      It's the thought that counts.

      --

      I'll see your senator, and I'll raise you two judges.
    5. Re:Consider your Audience when writing code by Ichijo · · Score: 3, Insightful

      Your audience is another human being who will be maintaining that code a few years later.

      Or yourself a few weeks later, if you're getting old like me and can't remember why you did what you did. This is also why I make an extra effort to ensure the code works the first time, with the fewest possible side effects, so I don't have to maintain it later.

      --
      Any sufficiently unpopular but cohesive argument is indistinguishable from trolling.
  5. That's interestingly backwards by kruach+aum · · Score: 2

    Code itself is simply a set of rules tying words and symbols to operations on a system. Learning those rules won't make you better at anything but learning rules. What will help you develop as a thinker is learning the underlying theory and ideas of a closely related field -- computer science. Thinking up your own solution to the dining philosophers problem, the knapsack problem or even understanding how you can describe the solution to the towers of Hanoi as an iterative process all help you develop problem solving skills and grant deeper insight into solving other problems. Simply learning a new coding language (unless that language is interestingly 'conceptually' (for lack of a better word) different from one you already know, like learning LISP when all you know is BASIC) won't improve much.

    1. Re:That's interestingly backwards by darkwing_bmf · · Score: 2

      Hogwash. One of the fundamentals of programming is understanding the machine or system and the "rules" for controlling it. How are you to develop an algorithm for solving the towers of Hanoi on a specific system if you don't know whether or not that system is capable of recursion (or perhaps even requires it)? How are you going to handle input and output without knowing the "rules" for the interfaces? High level algorithms can be solved by mathematicians but computer scientists use "rules" to make the machines do what they want. There is no computer science without the "rules".

  6. Re:What were they doing before? by bob_super · · Score: 4, Funny

    By the time some of my literature teachers are done, I'm sure the Hello World would be a subtle and poignant take on the overbearing consumerism as well as taking us to the depths of despair in search of the hero's hidden personality fractures.

  7. Re:What? by Dan+East · · Score: 4, Insightful

    The must instructive, enlightening thing I did in college while majoring in CS was to take a part time job grading Pascal assignments for an instructor. Of course my programming experience was significantly above that of the class being taught, but it was still very worthwhile to see how different minds went about solving a specific problem. There were a few students who I could immediately identify (by their code) who had the proper thought process (whether learned or innate - most likely the latter) for software development. I could easily recognize a few groups of 2-3 students who had obviously collaborated on the assignment (it was supposed to be an individual assignment). Students who only knew the most rudimentary constructs of the language were obvious - for example relying on huge sets of if / else statements instead of a simple case statement. There's just something about "reading" and critiquing code that makes you more self aware of the code you produce. Whether we're talking about code efficiency, style, organization or conciseness - I found myself writing better code (again, and not even necessarily through example or having seen something new) after having spent time grading and critiquing others' source code.

    --
    Better known as 318230.
  8. Re:tool, not primarily communication by DickBreath · · Score: 2

    If that tool you speak of is static and unchanging, like a wrench, then I could agree with you. Even if it were a moderately complex but extremely common machine with standardized parts, like a car, I could agree.

    But if that tool is a complex machine, even a software machine, then communication is an important goal. Software inevitably requires maintenance and will be changed and improved over time. Pointless features will be added. Useful features removed. Since this machine is not an off the shelf machine, like a car, it is important that all of the information that the maintainers and improvers need are somewhere. The best place is probably in the source code itself.

    --

    I'll see your senator, and I'll raise you two judges.
  9. Re:What were they doing before? by Anonymous Coward · · Score: 5, Funny

    It's more about the metatextual narrative. What does this say about the author? This GOTO implies that the author does not want to be where he is. He is desperate to break out; to be anywhere other than where he is now. He's backed himself into this corner, bound in a loop of his own devising, and yet unable to meet the conditions necessary to move forward. "GOTO!" he cries out, "For the love of God, take me away from the endless DO and WHILE!"

    Here we see laid out the mind of a soul utterly broken. Can you not feel his burning shame? From the time he first took his toddling steps into the Hello, World! his teachers have admonished him "GOTO statement considered harmful". Yet desperate times call for desperate measures. He casts the thread of his execution into the void*.

    Where will he land? We scan the page with increasing alarm. Can you feel your heart quicken? Where is the label? Where are we GOing TO? Now the reader is caught up in the narrative as well as the author. Does the label exist at all? How did this thing ever compile? Until finally, we see it. Safe at last! Our execution can continue, and yet we are forever changed by the experience. Have we exited the loop in the correct condition? Will there be enduring side effects? Read on to find out...

    * The void, that is, not a pointer to an unknown type, I just mean to clarify that as a footnote**.

    ** A footnote, that is, not a pointer to a pointer to a footnote.

  10. Yeah I Could See That by Greyfox · · Score: 4, Interesting
    I've read a lot of code over the years and thinking back on it, I do kind of approach it that way. What I'm doing feels more akin to taking a machine apart to see how it works rather than reading it as I would a book. I often feel, when I'm interrupted, like I'm ass-deep in wires that are going every-which-way.

    It is still a method of communication, though. You can often tell a lot about the programmer and his state of mind at the time by reading his code. It's very easy to tell when they were confused about what they were trying to accomplish, how comfortable they were with the language they were using and whether or not they were in a hurry.

    Early on in my career, I started with the assumption that the original programmer knew what he was doing. The more code I read, the more I realized that this is almost never the case. From my observations, it takes about a year for someone to come up to speed with a project, the business process for the company they're working at, and any code base that was already there. Longer if the company's business processes suck. Until then they're mildly to severely confused, and this is reflected in their code. Since a lot of programmers don't hang around at one company for much longer than that, most of the code that I've run across has been crap. The first inclination might be to rewrite it, but as you're starting on a new project you're also mildly to severely confused, so it's best just to study the crap closely and make minor improvements as the opportunities arise. A crap in the hand is worth two in the bush. Or something. Most of the time. I've run across a couple of what had to have been bottom-ten-percent programmers whose crap did end up requiring full rewrites. Coming into a C project where the programmer didn't realize strings are null terminated is a huge warning. C++ or Java code where everything inherits from everything else is also a warning.

    --

    I'm trying to teach myself to set people on fire with my mind... Is it hot in here?

  11. Well parts are like literature by HeckRuler · · Score: 3, Interesting

    No no, certain parts of coding is very much like literature. The style of how you... branch based on a string, or how you implement event-driven coding, or how you distribute computing power.
    There are a TON of ways to skin those cats and which way you do it is a matter of stylistic preference. It's fashion. The exact sort of subjective shindig that lit major whittle away their time with. It's like the difference between writing in first person or third person. And in certain places one way is very much better than the other.

    But who the hell reads code for the stylistic appreciation? We read code because it's broken, we want to steal part of it, or we need it to do something else. That's not a stylistic issue, that's a mechanic wrenching on a car. Figuring out just what the hell it's doing is a different act than bickering how it could have been done better. Doing the first part pays a lot better than the second.

    This guy has noticed that most people that read things are reading restaurant menus, technical documents, text books, grocery lists, and not novels. The writers of said material are doing it to get shit done rather than fretting about how they do it.

    1. Re:Well parts are like literature by Greyfox · · Score: 4, Interesting
      But but but! A mechanical object can be beautiful, and so can code! Often I've seen brilliant and occasionally sadistic approaches to the problem that I can definitely appreciate at an artistic level. Something like Duff's Device requires both technical brilliance and a good amount of creativity. I have to read and analyze code for my job on a regular basis.

      A mechanic must know his way around a car to know how to repair it, and I must know my way around the code base if I am to diagnose problems. I can't just focus on the broken parts of it, or changes I make will likely introduce side effects. On most of my projects I didn't even have a requirements document, just a big pile of usually-poorly-written code. Each program is a unique individual machine, as if every single car were built dramatically differently. How much harder would it be for a mechanic if they had to go hunting for the spark plugs before they could even get started?

      --

      I'm trying to teach myself to set people on fire with my mind... Is it hot in here?

    2. Re:Well parts are like literature by iluvcapra · · Score: 2

      Duff's device always struck me as sort of a crank idea, it's more of a trick than a clever algorithm. The fact that you can stick some case labels inside a do/while and some outside would be considered totally breaking if you were to do it under any other circumstance, you're effectively using a label to jump into a scope (even though in this case it's harmless). Also, this is the 21st century: if you find yourself actually pasting Duff's device into your project, you're probably haven't read about all of the very nice, hand optimized inline blitting functions your platform makes available to you.

      I remember something Linus Torvalds wrote a while back that stuck me as somewhat more useful, he pointed out that people deleted nodes from a linked list:

      list_entry *entry = head; /* assuming head exists and is the first entry of the list */
      list_entry *prev = NULL;

      while (entry) {
      if (entry->val == to_remove) /* this is the one to remove */
      if (prev)
      prev->next = entry->next; /* remove the entry */
      else
      head = entry->next; /* special case - first entry */

      /* move on to the next entry */
      prev = entry;
      entry = entry->next;
      }

      The test for the head node runs for every element on the list, and it's only going to be true under very particular circumstances. Linus said it should look like this:

      list_entry **pp = &head; /* pointer to a pointer */
      list_entry *entry = head;

      while (entry) {
      if (entry->val == to_remove)
      *pp = entry->next;

      pp = &entry->next;
      entry = entry->next;
      }

      He used a pointer to a pointer as a cursor, and a dereference of the cursor to edit the list, instead of using entry->next to tell him where he was. It also kinda drives home how you should always set the initial conditions of your loop in such a way that you'll get the most out of it, and not pass a lot of stuff in as NULL to tell the loop its in its first iteration.

      --
      Don't blame me, I voted for Baltar.
  12. Re:What? by Anonymous Coward · · Score: 5, Insightful

    Reading other people's code is a great way to learn better ways of doing things you thought you already knew how to do. ;)

  13. Re:What were they doing before? by gstoddart · · Score: 5, Funny

    Discussing the meta-narrative implied by errant GOTO statements?

    The GOTO statement is reflective of the existential malaise experienced by programmers, and typified in post-modern society.

    It shows that the programmer in the code, as in life, feels they have reached a dead-end from which there is no escape, and reflective of a desire to escape the mundane and return to the optimism of youth.

    The GOTO becomes a metaphor for man's desire for a quick solution to our problems, and a naive belief we can make the problems go away, and thus becomes symbolic of wish-fulfillment and fantasy to offset the feelings of stagnation and dread so often described in post-modernism.

    In stack based languages, the GOTO becomes a surrogate for a strong father figure, and metaphorically kills the mother in frustration. It's also convenient for breaking out of nested logic to an error handler, which gives us feelings of going back to the womb, and indulging in self-infantilism in order to achieve a more expedient resolution of the dichotomy between self and other.

    Thematically, the GOTO is both liberation, and the source of our own slavery; it simultaneously demonstrates our desire for freedom, as well as showing the futility of such a quest and how we re-enslave ourselves through our actions.

    Because it highlights the existential question of "how do you implement an IF statement without a GOTO in Assembler?", it forces us to acknowledge that, as much as man tries to escape his primitive roots, there persist behavior which is neither rational nor defensible, but which we nonetheless cannot do without from an evolutionary perspective.

    The GOTO defines for us the boundary between man as thinking entity, and non-thinking animal. And, as in Conrad's Heart of Darkness, forces us to look within ourselves, and confront the things we see but cannot fully understand or control.

    --
    Lost at C:>. Found at C.
  14. Re:What? by cold+fjord · · Score: 4, Interesting

    Your comment reminds me of this bit about the code for what became Adobe Photoshop. The code is available for download from a link on the page linked to below.

    Adobe Photoshop Source Code

    Thomas Knoll, a PhD student in computer vision at the University of Michigan, had written a program in 1987 to display and modify digital images. His brother John, working at the movie visual effects company Industrial Light & Magic, found it useful for editing photos, but it wasn’t intended to be a product. Thomas said, “We developed it originally for our own personal useit was a lot a fun to do.” Gradually the program, called “Display”, became more sophisticated. In the summer of 1988 they realized that it indeed could be a credible commercial product. They renamed it “Photoshop” and began to search for a company to distribute it. ... The fate of Photoshop was sealed when Adobe ... decided to buy a license to distribute an enhanced version of Photoshop. ....

    Commentary on the source code
    Software architect Grady Booch is the Chief Scientist for Software Engineering at IBM Research Almaden and a trustee of the Computer History Museum. He offers the following observations about the Photoshop source code:

    “Opening the files that constituted the source code for Photoshop 1.0, I felt a bit like Howard Carter as he first breached the tomb of King Tutankhamen. What wonders awaited me? I was not disappointed by what I found. Indeed, it was a marvelous journey to open up the cunning machinery of an application I’d first used over 20 years ago. Architecturally, this is a very well-structured system. There’s a consistent separation of interface and abstraction, and the design decisions made to componentize those abstractions – with generally one major type for each combination of interface and implementation — were easy to follow. The abstractions are quite mature. The consistent naming, the granularity of methods, the almost breathtaking simplicity of the implementations because each type was so well abstracted, all combine to make it easy to discern the texture of the system. . . .

    This is the kind of code I aspire to write.”

    Good examples can provide powerful learning experiences. They can crystalize the intangible aspects of description and discussion.

    --
    much of left-wing thought is a kind of playing with fire by people who don't even know that fire is hot - George Orwell
  15. I don't see how any programmer would think that by istartedi · · Score: 3, Interesting

    I don't see how any programmer would think code was literature, except perhaps highly technical literature. You read novels from beginning to end. You read code on an as-needed basis. You might only read the header of a library. In fact I've seen good libraries where the only docs I read were long comments in the header file. If you want to understand a system you might start with main() or your language's equivalent and find some kind of dispatch function with calls to things like ResizeWindow which is *boring* and calls to things like DetectThief which is *interesting* so you drill down into the DetectThief function and find out where it gets the data and how it decides the user might be a thief. That might only be a few thousands lines that you've looked at. The other 30k lines of GUI or sorting, or options of writing PDF reports... blah, it might not be interesting to you... unless you're a font and layout geek and the reports did something interesting with fonts and/or layouts. Then you might only read that part.

    Likewise, if it crashes you'll pull it up in the debugger and read parts of the functions on the stack that lead to the crash. Aha! The contract called for the caller to not pass any NULL pointers, and they passed one. Fix. Commit. You had a *reason* for reading that code.

    --
    For all intensive purposes, "whom" is no longer a word. That begs the question, "who cares"?
  16. Knuth disagrees by phantomfive · · Score: 4, Interesting

    Knuth disagrees, which is why he created Literate Programming. If you aren't familiar with it, you should make yourself familiar. He suggests eventually someone might win a prize for literature from their code.

    If you haven't seen it, you should check it out. His code has a table of contents, and could definitely be considered literature. His Tex code is so well organized, that you can find what you are looking for within 15 minutes, even if you're not really familiar with it. That's how code should be: written so other people can read it.

    That's not what the author is talking about, though. He's talking about crappy code that wasn't written in a way that was easy to understand (I read the article; this is my understanding of it). So yeah, crappy code is not literature, or easy to 'decode.' Tautological.

    --
    "First they came for the slanderers and i said nothing."
    1. Re:Knuth disagrees by phantomfive · · Score: 3, Interesting

      to successfully create a code reading culture you must acknowledge that in practice examining most code is not at all like reading literature and instead needs to be approached more like a scientific investigation

      OK, so that's an interesting hypothesis, what evidence do you have to support your hypothesis? Doesn't it make more sense that if you want people to read your code, you should make it easy to read (that is, make it literate)?

      Knuth actually provided an anecdote that reinforces this point so I very much doubt he disagrees with it.

      I read Knuth's Literate Programming, and I would say I accurately portrayed his viewpoint. Would you like to read the book and tell me how you think I misunderstood it? To restate, Knuth doesn't think all code is literature, he thinks code can be literature, and he taught how to get there.

      --
      "First they came for the slanderers and i said nothing."
  17. Other people's code? I can't even figure out mine! by digitalhermit · · Score: 4, Funny

    Perl jokes aside, I have some old code written in everything from bash to C to R to Java. The common theme among these absolutely stunning pieces of literature is how incomprehensible some of it can be just a few months later. Sure, good code is self documenting, good code reads like a sentence, a proper module fits on one page of screen (I have a 24" display with better than 1920x1080 resolution, btw) but if my code were indeed prose, it would cause eyes to bleed, to hemorrhage, to explode in a fantastic fountain of blood and aqueous fluid.

    Sometimes I wrote bits of code without knowing that there were easier ways. I may do a "for item in $(ls *.csv)" instead of the proper "for item in *.csv" or some furious hackery to manually rotate 20x10 matrix into a 10x20 (single command in several languages), or try to parse an XML file by regex'ing and other madness... Sometimes I was drunk. There was one class where the instructor didn't like "showoffs" so code had to be written using only the commands that were covered in the lecture. The resulting code from that class was horrid. One of my earliest bits of code from the 80s sent escape sequences to a printer and there are several strings with non-ASCII characters. There is no way to understand the code without knowing the printer. I have similar code for an Atari that stored music in a BASIC string. That might be possible to decode only if one understood how the Atari made sound.

  18. Re:Slashdot is for niggers by Anonymous Coward · · Score: 2, Funny

    obviously white-only

  19. We don't read poetry... by j33px0r · · Score: 2

    We don't read poetry, we decode it. Or maybe you would say that we interpret it? Depends upon your point of view. We don't read the original article, we skim it.

    The original author is romanticizing the term literature, not that there is anything wrong with that of course, but literature is a term applied to everything from Dostoevsky to instructions for assembling a toy. Beautifully/Dreadfully written code could be labeled as art, poetry, literature, garbage, puzzling, cryptography, and a whole variety of other terms.

    With all that being said and putting aside that I do not agree with the original author's definition of literature, I do appreciate their perspective.

  20. Re:What? by RabidReindeer · · Score: 3, Funny

    Reading other people's code is a great way to learn better ways of doing things you thought you already knew how to do. ;)

    Reading the source code to the OS and compilers used at my school probably taught me more than the classes themselves.

    It was good code. Most of the business code I've seen is more like pornography than great literature, though.

  21. How about Architecture by T.E.D. · · Score: 3, Insightful

    Probably the best analogy is Architecture. There is a discipline that necessarily has a functional purpose, but still can (and often is) viewed and appreciated as art. A large part of the appreciation of architecture is appreciation of how it went about achieving its functional purpose, and there's a large body of theory build up around this. For example, its is a controversial but generally accepted architectural principle that form should follow function. An implication of this is that unnecessary architectural features are frowned upon. In SW Engineering we call non-functional code "dead code" if it flat out can't be used, and "inelegant" if it is simply more than necessary. Both are generally frowned on.

    So if you want to spend time systematically analyzing software as art, perhaps the Right way to go about it would be the way architectural reviewers do, not the way literature or "high art" reviewers do it.