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.'"

240 comments

  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 Anonymous Coward · · Score: 0

      enumerable possibilities, indeed.

    3. 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!
    4. 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.

    5. Re:Music... by Anonymous Coward · · Score: 0

      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.

      Jazz works similarly throwing in different key changes and the ability to solo or repeat part on the spot and improvise with the form of the song. Still not perfect but closer.

    6. Re:Music... by Anonymous Coward · · Score: 0

      >Literature usually has the meaning the author intended.

      This is appallingly naive. http://en.wikipedia.org/wiki/Death_of_the_Author
      As for that matter is the original summary that human language texts are "plain" to read, see Hermeneutics on that point.

    7. 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..."

    8. Re:Music... by turp182 · · Score: 1

      So code is jazz?

      --
      BlameBillCosby.com
    9. Re:Music... by Anonymous Coward · · Score: 0
    10. 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!
    11. Re:Music... by Anonymous Coward · · Score: 0

      FOR index := firstxmas TO lastxmas DO
      Christmas.yours[index] := white;
      if index == lastxmas THEN me,give(your_heart)
      END.

      little geo michael remix there. we could go on, this is fun.

    12. Re:Music... by Anonymous Coward · · Score: 0

      >>Literature usually has the meaning the author intended.

      > This is appallingly naive. http://en.wikipedia.org/wiki/D...

      Please! Keep your postmodernist pseudophilosophy away from my literature.

      The only good thing about "postmodernism" is that it will eventually go away.

    13. Re:Music... by NicholasRezmerski · · Score: 1

      if ((u == BLUE) && (!knows_where_to_goto(u))
            goto fashion; // why not?

      fashion: put_on(the_Ritz);

    14. Re: Music... by Anonymous Coward · · Score: 0

      Unfortunately your Christmas cards are still blank, soi I guess you get to dream some more while you actually write them this time.

    15. Re:Music... by Anonymous Coward · · Score: 0

      So code is jazz?

      It's not just jazz, it's Jaaaazzzzzzz, baby!

    16. Re:Music... by iluvcapra · · Score: 1

      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.

      Right, but decoding is just the translation from one symbology into another, it doesn't create a semantic relationship, decoding can't create meaning, not in the sense we mean here. I can read your for loop, I can tell you it'll run node->count times, but you are the only one that actually can relate node->count to something in the real world, or to the abstract concept, and only humans will be able to give the effect of the loop final meaning. All the program can do is keep juggling symbols back and forth according to what can be reduced to automatic production rules.

      Kurzweil's last book was basically premised on the idea that human mind is nothing but an iterative pattern recognition machine, decoding stimuli, and the problem is that this account is totally incomplete and he has to constantly smuggle in consciousness without arguing that it exists, because positing it completely breaks his mechanistic conceit, the idea that the brain is a discrete computing machine and thoughts are symbols and operations on symbols.

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

      It was a movie, written by two guys who learned everything they know about computers from AKIRA and 2001 A Space Odyssey...

      --
      Don't blame me, I voted for Baltar.
    17. 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.
    18. Re:Music... by Anonymous Coward · · Score: 0

      It's bio-digital jazz, man!

    19. Re:Music... by coolmadsi · · Score: 1

      If musicians read sheet music like programmers read code, then why do a lot of programmers insist that everyone else comments their code?

      If you're reading sheet music just to play it, then you wouldn't need comments (like a computer doesn't need comments to execute code). I would be surprised if music composition is done exclusively in notation without some text alongside it, particularly if there are a number of composers collaborating (disclaimer: I'm not a composer).

      If people could write perfect software first time (and software requirements never changed), code probably wouldn't need comments.

    20. Re:Music... by bwcbwc · · Score: 1

      Actually, music has a couple of loop structures (D.C. al fine/D.S. al fine), and although they aren't traditionally interpreted to cause infinite loops or even n loops, there's no reason they couldn't be expanded upon.

      --
      We are the 198 proof..
    21. 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]
    22. Re:Music... by Anonymous Coward · · Score: 0

      Right, but decoding is just the translation from one symbology into another, it doesn't create a semantic relationship, decoding can't create meaning, not in the sense we mean here.

      Trying to decode what you wrote here is making my head asplode.

    23. Re:Music... by mcgrew · · Score: 1

      Right, but decoding is just the translation from one symbology into another, it doesn't create a semantic relationship

      When I read a novel I don't hear the words in my head or even notice them on the paper. I see, hear, and feel the characters and what they do and say. The abstract symbols on the paper are decoded to concrete events and ideas.

      only humans will be able to give the effect of the loop final meaning. All the program can do is keep juggling symbols back and forth according to what can be reduced to automatic production rules.

      That's because humans can read and computers can't. Even a text to speech program can't read, it can only juggle the written symbols and the auditory symbols. A human can not only read the code, a human can understand out what that code does when it runs. A computer can't.

      Kurzweil is a damned fine engineer, but he doesn't have a clue about the brain. He's obviously never heard of the Chinese Room (it appears you in fact have).

      People like him who think computers will be sentient are dangerous.

      It was a movie, written by two guys who learned everything they know about computers from AKIRA and 2001 A Space Odyssey

      True, it was only an illustration. But think of an incredibly simple program, like an analog clock on your computer screen. Depending on the language and your expertise you could little more than glance at it and imagine the clock it would draw. When you write a program you certainly have to envision what the output will be.

      And HAL is bothersome because HAL isn't, in fact, any more sentient than Watson. It's just a Chinese room that does a good job of fooling a sentient being that it is, when it isn't. People are going to push for equal rights for computers... Frank Herbert touched on this in Dune, when "intelligent machines" were used by unscrupulous men to enslave others (leading to the jihad and outlawing of intelligent machines).

      They were calling computers "electronic brains" when a building-sized machine was less powerful than a musical Hallmark card. It worries me, because they're not brains. They're tools and toys.

    24. Re:Music... by phantomfive · · Score: 1

      // WTF was Beethoven thinking here...

      I really, really wish Beethoven had given more explanations here. Occasionally he did give short ones, like on "La Melancolia" quartet, or on the sixth symphony. Those are much appreciated when he actually did it.

      --
      "First they came for the slanderers and i said nothing."
    25. Re:Music... by bbsalem · · Score: 1

      Are you talking about the last movement of Op 18 #6 by Beethoven, the B-Flat String Quartet? I think it is, like the fugue of Op 110, A-Flat Piano Sonata, either a self portrait of Bipolar disorder or an artistic exploration of what that is like, whether or not there is any evidence that Beethoven had the disorder.

      One can analyze the form in Op 18 #6 iv, as Adagio, followed by the Allegro with its almost manic joy. Similarly the Adagio in Op 110 is followed by a fugue followed by a return of the Adagio and repeat of the fugue but inverted and then inverted and diminished (Cunterpuntally), followed by a coda. The sadness of the Adagio, I think F-minor, is unmatched, and is somewhat like the Adagio (F# Minor) of Op 106, but the Hammerklavier ends in its fugue without the repeat. The affect of the last two movement of Op 106 is different, more like a ternary form slow movement followed by a separate finale, albeit a fugue. The last movement also has a long introduction, somewhat like the Ritternello of the Ode to Joy movement in the Ninth Symphony, Op 125, and works like the last two movements of Op 132 which is related to the Ninth Symphony in Beethoven's sketch books.

    26. Re:Music... by phantomfive · · Score: 1

      Are you talking about the last movement of Op 18 #6 by Beethoven, the B-Flat String Quartet?

      Yes, I'm glad you know it.

      I think it is, like the fugue of Op 110, A-Flat Piano Sonata, either a self portrait of Bipolar disorder or an artistic exploration of what that is like, whether or not there is any evidence that Beethoven had the disorder.

      I'm not sure it's necessary to analyze it as a bipolar disorder, it's fairly common for someone who is feeling depressed all day to see some small thing that brings him cheer for a bit (a famous example, Proust's Medeleine. Maybe we can call this movement, "Beethoven's Madeleine?") Thus I don't think there's any reason to go beyond Beethoven's own description that he was portraying melancholy.

      Vaguely related, the second movement of Dvorak's New World Symphony has a similar change in mood after the funeral scene.

      --
      "First they came for the slanderers and i said nothing."
    27. Re:Music... by iluvcapra · · Score: 1

      When I read a novel I don't hear the words in my head or even notice them on the paper. I see, hear, and feel the characters and what they do and say.

      The specification of a "character" is not in the book, you're bringing it in from context; further, you don't just experience the events of the book by proxy, you reflect on them and have novel thoughts contingent on the words. I don't think its clear we can distinguish between the "decoding" of the words in your brain and the act of understanding. We can name them, we can make abstract assertions about the two acts as if they were severable, but we have no empirical evidence that they're discrete phenomena.

      I don't accept the Chinese Room argument, mainly because it's not realistic. You can open the door to the Chinese Room and discover the guy who can't speak Chinese; you can never truly "open" a computational oracle, or a mind. If something quacks like an intelligence it is, insofar as we don't know how it works -- the only useful definition of "intelligence: is "that which behaves rationally but we don't know how." The moment we discover how something works, it ceases to be conscious, so it was when "God" became "the laws of nature."

      What's hilarious about the Chinese Room is the idea that we're supposed to judge the oracle by how smart the guy applying the rules in the room is, when clearly the intelligence is in the guy who wrote him the rules. It's a bait and switch.

      --
      Don't blame me, I voted for Baltar.
    28. Re:Music... by iluvcapra · · Score: 1

      Think of the Chinese Room this way: let's say there's two guys who don't speak Chinese, and they work no the rules together. Doesn't change things, right? Now lets say there's a billion people in the Chinese room. None of them speak Chinese, so by Searle's standards the Chinese Room isn't "intelligent," but what's the difference between a billion people in a room working out an algorithm for a language they don't understand, and a billion neurons? Neurons don't know Chinese, but we unquestionably consider a billion neurons intelligent, when they're operating in the skull of an ape descendent.

      --
      Don't blame me, I voted for Baltar.
    29. Re:Music... by mcgrew · · Score: 1

      A person isn't a neuron and a billion people are not a billion neurons any more than a billion mechanical calculators are neurons. Two or a billion, if they don't know Chinese the symbols are manipulated mechanically; there is no thought.

    30. Re:Music... by mcgrew · · Score: 1

      You seem to be arguing in favor of the Chinese room.

      You can open the door to the Chinese Room and discover the guy who can't speak Chinese; you can never truly "open" a computational oracle, or a mind. If something quacks like an intelligence it is, insofar as we don't know how it works -- the only useful definition of "intelligence: is "that which behaves rationally but we don't know how."

      But I do know how a computer works. I wrote a fake AI program in 1982 in a 1 mHz Z-80 16K RAM computer that did fool people who didn't know how computers work into thinking it was sentient.

      There is no such thing as a "computational oracle". You cannot build a thing that nobody understands. Without knowledge of how a radio works you can't build a radio without detailed instructions from someone who does know.

      The moment we discover how something works, it ceases to be conscious.

      I don't buy that. When we discover all the brain's secrets we stop being conscious? It makes no sense to me.

      clearly the intelligence is in the guy who wrote him the rules.

      Bingo. The machine possesses no intelligence, the illusion of intelligence is simply the programmer's cleverness.

    31. Re:Music... by bbsalem · · Score: 1

      I have been meaning to research the point about depression, whether there is any real evidence for it and if biographers and others have shed any light on it. The contrasts in music may be simply devices, except the intensity of the "dark" passages do point to something experienced I think. Maybe more than Op 18 #6 the Adagio in Op 110 points to that. The evident struggle is pretty obvious as is the possibility that the loud chords at the end before the Fugue and its rhyme seem to indicate how deaf the composer was. I am reminded of this by how Alfred Brendel approaches those chords.

    32. Re:Music... by phantomfive · · Score: 1

      I have been meaning to research the point about depression, whether there is any real evidence for it and if biographers and others have shed any light on it.

      I suggest reading this book, it addresses the topic. You should be able to get it at a library.

      The contrasts in music may be simply devices, except the intensity of the "dark" passages do point to something experienced I think.

      That's always a possibility, but then you run into the question, why did he name it "melancholy" if the music has nothing to do with "melancholy"? So many, if not all, of Beethoven's works incorporate emotions........

      --
      "First they came for the slanderers and i said nothing."
    33. Re:Music... by bbsalem · · Score: 1

      Thanks for the pointer to the book. I did not know the title. I am well aware of the history and difficulties associated with the Grosse Fuga and having seen it performed, the awe and mystery of it are deserved. If I can get the book you mentioned it will be interesting to read what is said about the possibility of Beethoven's depression.

      I have learned about the GF, that it can be approached formally as a Braoque Suite, if not a modified sonata form. The opening in G-minor with its trials of the theme for the fugue is reminiscant of the riternello with bass recitative from the "Ode to Joy" movement of the Ninth Symphony, itself a composite form variations, and sonata-altegro form but owing much to opera.

      The exposition of the GF is the standard working out of a fugue with several countersubjects, but unlike Bach, it is not given a final cadence and ending right there. It modulates from G-minor to B-Flat, but is followed immediately by a modulation to G-flat, like the attach to adagio or ternary form show movements in other String Quartets.

      The G-flat section with its use of the fugue subject over a simple counterpoint acts like a slow movement in a sonata. Beethoven had marked the separation by a double bar as he does for the following section, a Gigue, quickly exposed, followed by another double bar and modulation to A-Flat where the gigue therme is worked out as a double fugue. It is a diminished (in duration) version of the fugue these worked out against a white note, or augmented version of the fugue theme.

      Get the score, public domain, and compare the note values of the opening with these and you will see that this lengthy section, which is also the point furthest removed harmonically and functions like the development section of the sonata form, is a complex double fugue. At the next double bar is a working out of the augmented version of the theme in rectus and inversion against a species counterpoint. This is actually a rhyme of the texture in the G-flat section, whose contrapuntal significance is revealed. This is followed by a rhyme of the Gigue theme, at a double bar, a brief fantasia with trills in the theme and the coda, which also has a rhyme with the introduction section. The introductory bars and its rhyme sound very much like the "Mus es sein?" device in Op 135.

      In key area form the last three sections rhyme with the first three, and harmonically suggest a sonata form, but they could also suggest the arch form used by Bartok and we know that he was heavily influeinced by Beethoven.

      Lastly recall the history of this work. It was originally the last movement of Op 130 and following immediately the touching Cavatina, but it was separated out, given Op 133 and a replacement Rondo, that is itself a great work, was substituted. I have a pocket score that is old enough to show the GF as an appendix to Op 130, and you can get recordings of the original so-called Galitzin version with the GF followed by the Rondo.

    34. Re:Music... by phantomfive · · Score: 1

      We should have conversations like this more often.

      --
      "First they came for the slanderers and i said nothing."
    35. Re:Music... by cyberhooligan77 · · Score: 1

      Programs cannot be read as music sheets.

      Example 1: // this one can be read as music sheet

      int main ()
      {
          if (State == States::Texas)
              Total *= 1.05;

          return 0;
      }

      Example 2: // this one CANNOT be read as music sheet

      int main ()
      {
          if (S == 32)
              X *= 1.05;

          return 0;
      }

      Example 3: // this one MAYBE be read as music sheet

      int main ()
      { // if (State == States::Texas)
          if (S == 32) // Total *= 1.05;
              X *= 1.05;

          return 0;
      }

      I think it's a good idea that programmers:
      - should code their programs as if comments were not required
      - and comment their code, as if their program was not readable

      And, when those 2 options are applied, then, their programs, can be readed as music sheets...

      Cheers.

    36. Re:Music... by nschubach · · Score: 1

      If I have to comment, that means I didn't write the code clear enough or didn't use the proper names. For me, comments are smell to tell me where I need to clarify code.

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
  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 Anonymous Coward · · Score: 0, Troll

      This is just a pathetic attempt to address the fact that boring, drab Computer Science-studying robo-humans devoid of personality still cannot complete against the broke poets and other Liberal Arts majors for female attention.

      *Comes running up* ...hey Lisa *wheeze* Look at this, code I wrote, look how "deep" it is! I can do art too! I will write poetry for a living!

      -- Ethanol-fueled

    2. Re:Similar language, describing different things by Anonymous Coward · · Score: 1, Funny

      This is just a pathetic attempt to address the fact that boring, drab Computer Science-studying robo-humans devoid of personality still cannot complete against the broke poets and other Liberal Arts majors for female attention.

      You're doing it wrong. Just open up your wallet. The art women appreciate most is green ink on a cotton paper with a portrait of Benjamin Franklin.

    3. 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.

    4. 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.
    5. 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?

    6. 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.

    7. 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.
    8. Re:Similar language, describing different things by ElectricTurtle · · Score: 1

      As somebody who has detested Ethanol-Fueled since the time when he posted under his actual account before becoming afraid of his bad karma, I thank you AC.

      --
      I support the Slashcott and will not be reading or commenting from 2/10/14 to 2/17/14. Beta is steaming pile of dog shit
    9. 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.

    10. 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.

    11. Re:Similar language, describing different things by buchner.johannes · · Score: 1

      So Gamebooks are not literature then?

      --
      NB: The message above might reflect my opinion right now, but not necessarily tomorrow or next year.
    12. Re:Similar language, describing different things by MetalOne · · Score: 1

      quicksort [] = [] quicksort (x:xs) = quicksort [y | y x]

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

      Same could be said for non-trivial code.

    14. Re:Similar language, describing different things by MetalOne · · Score: 1

      Should have paid attention to the preview, dang it.
      quicksort [] = []
      quicksort (x:xs) = quicksort [y | y x]

    15. Re:Similar language, describing different things by MetalOne · · Score: 1

      Slashdot messed up my post. Well, it was meant to be the 2 liner Haskell quicksort.

    16. 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.

    17. 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.

    18. 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*
    19. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

      If you were reading a pick-a-path book with an eye towards determining why opening the door should take us to page 32 instead of 33, 34 or 89, then you'd appreciate the literary content less.

    20. Re:Similar language, describing different things by Anonymous Coward · · Score: 1

      Define "regular person". If you're referring to the same general crowd that doesn't know how to make Windows prompt them for updates instead of auto-rebooting, you're asking far, far too much.

    21. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

      Sure and it would be, but it's still likely it would be very hard to understand by a "regular" person with no previous experience in either the language or in DSP. So, again, how is their lack of understanding mean that my code is bad?

    22. Re:Similar language, describing different things by Anonymous Coward · · Score: 1

      * that doesn't perform terribly on large lists *
      This is shit code and will perform like utter shit in the real world because of all the copying and strict, forward-only iteration. It's also misnamed. If you weren't an idiot, you'd know that quicksort is an in-place sort and the garbage you just posted isn't. May as well fucking insertion sort; it'd be faster.

      This is why no one takes anyone who advocates Haskell seriously.

    23. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

      And how exactly does being only two lines long make something understandable to a layman?

    24. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

      Human readable commentary is helpful but only if the assembler programmer wasn't a fucken idiot.
      Small sample of actual comments I've seen:
      1. If you don't know what this does then fuck-off
      2. Bla bla bal, what more do you want to know?
      3. My boss is a ass-hole!
      4. If you are reading this then get a life
      5. Got C ?

    25. 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.

    26. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

      Assembly was just used as a backdrop. It could have been any language or concept that the "regular" person has no experience. POSIX threading would be highly complex for a "regular" person but the code I write using it is not bad just because Joe Blow can't understand semaphores and mutexes.

    27. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

      Yeah, you're really missing the point here. Not only was it super hard to get it written out correctly, but that MAKES ZERO SENSE to a layperson.

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

      At one time, we used to teach fourth graders to code in BASIC in the United States.

      If your routine is too complex, add comments.

      --
      SJW: a person who perceives an injustice, and while correcting it, commits a greater injustice.
    29. 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.
    30. Re:Similar language, describing different things by fisted · · Score: 1

      Put the next smallest table on top of the previous one

      So essentially you build a stack of n*log(n) tables? That sounds fun, but requires quite a high ceiling, for regular decks of cards

    31. 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.
    32. Re:Similar language, describing different things by Marxist+Hacker+42 · · Score: 0

      It means your comments aren't explicit enough.

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

      Comment your code. Done in one.

    34. 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.

    35. Re:Similar language, describing different things by UnknownSoldier · · Score: 1

      > is going to seem like voodoo no matter how elegantly it is coded.

      Mostly true, however, beautiful and simple code makes it a helluva lot easier to understand ! Quicksort isn't _that_ difficult to write from the ground up if you understand the i) the theory, and ii) can apply it.

      * Three Beautiful Quicksorts -- The most beautiful code I never wrote.
      http://www.youtube.com/watch?v...

      From

      * Beautiful Code: Leading Programmers Explain How They Think (Theory in Practice (O'Reilly)) [Kindle Edition]
      http://www.amazon.com/dp/B0026...

    36. Re:Similar language, describing different things by RabidReindeer · · Score: 1

      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.

      I did one once. It was a Shell-Metzner sort.

      The list was large, but almost completely ordered. In other words, a pathological worst case for the heaping sorts. Also a bad choice for basic bubble, but a Shell sort does a binary bubbling that was optimal for the data in question. And very welcome, since one of the main systems in our shop had to do this about 150 times a day.

      "Efficient" means different things, depending on context.

    37. Re:Similar language, describing different things by Splab · · Score: 1

      I usually leave links to youtube like this one:
      http://www.youtube.com/watch?v...

      (Not rick roll)

      Might not help, but at least the programmer knows that the guy who wrote this is sorry (and that he is aware of how bad that piece of code is).

    38. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

      Actually you can explain mergesort and heapsort using similar concepts, if you task it out to a group of people like a bucket brigade (but in a binary tree formation of people) and tell each person that their task is to simply look at two cards and pass the lower valued card along the chain before the higher valued card.

      The main difference between the two is just in how cards get distributed into the brigade: mergesort distributes an arbitrary pair of cards to each leaf person in the brigade, while mergesort performs a slightly more complex process to distribute them out through the root, one card at a time, routing cards left or right by value and keeping one card with each non-leaf person as well.

    39. Re:Similar language, describing different things by JesseMcDonald · · Score: 1

      Mergesort isn't all that difficult to explain either. Take your unsorted list and divide it into a bunch of single-element (trivially sorted) sublists. Divide the sublists into pairs, and merge each pair of sorted sublists into a new sorted sublist; to merge two sorted lists, repeatedly take one element from whichever list starts with the lowest value until both lists are empty. If you happen to end up with an odd number of sublists, hold the extra one for the next round. Repeat the pairing and merging until you're left with just one list.

      In somewhat verbose Haskell:

      mergesort :: Ord a => [a] -> [a]
      mergesort = head . merge_pairs . map singleton

      -- Merge pairs of lists until less than two lists remain.
      merge_pairs :: Ord a => [[a]] -> [[a]]
      merge_pairs xs@(_:_:_) = let (ps, ys) = pairs xs in merge_pairs (map merge ps ++ ys)
      merge_pairs [xs] = [xs]
      merge_pairs [] = [[]]

      -- Divide a list into pairs, with zero or one elements left over.
      pairs :: [a] -> ([(a, a)], [a])
      pairs (x:y:xs) = let (ps, ys) = pairs xs in ((x,y):ps, ys)
      pairs [x] = ([], [x])
      pairs [] = ([], [])

      -- Merge two sorted lists into a single sorted list.
      merge :: Ord a => ([a], [a]) -> [a]
      merge (xs, []) = xs
      merge ([], ys) = ys
      merge (xs@(x:_), (y:ys')) | y < x = y : merge (xs, ys')
      merge ((x:xs'), ys) = x : merge (xs', ys)

      -- Create a single-element list from a value.
      singleton :: a -> [a]
      singleton x = [x]

      --
      "The state is that great fiction by which everyone tries to live at the expense of everyone else." - Bastiat
    40. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

      A filing cabinet if fully sorted and uses a table of key ranges on the fronts of the drawers to accelerate search. A filing cabinet is most equivalent to a btree, which can be used to sort, of course (note that btree is not the same thing as binary tree). A heap is contiguous in memory and you move O(log n) entries around in the heap with each insertion. There is no analogous circumstance in common experience. Most good programmers would be able to give correct rules for updating a heap for insertion and removal in an interview, but only because they are able to derive the rules based upon the invariant of the data structure which is common knowledge to good programmers. A non programmer might have a hard time following the explanation. Of the three I think merge sort is probably the easiest to conceptualize and explain, it is just collating. It is how we sort stacks of paper after we give up on trying to lay them all out on the floor in sorted order and do insertion sort.

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

      DSP is also single use. Next processor revision is going to be incompatible with it anyway.

      --
      SJW: a person who perceives an injustice, and while correcting it, commits a greater injustice.
    42. Re:Similar language, describing different things by Nemyst · · Score: 1

      The problem with that criterion is when your code depends on an API which would never ever be understood by a regular human being. Sometimes you just can't avoid it.

    43. Re:Similar language, describing different things by turp182 · · Score: 1

      Great analogy, it could be extended such that code faults leading to things like buffer overflows or SQL injection are "loopholes", basically unexpected consequences.

      And patching the law is far more difficult than patching software.

      --
      BlameBillCosby.com
    44. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

      This looks stupid and inefficient. I'd simply split them in piles by first letter and then sort those smaller piles in similar way (except I wouldn't need to put them in a lot of one card "piles").

      Is that what you programmers do, think up silly over-complicated ways to do simple things? No wonder everything runs so slow. Why the hell do you guys even get paid so much for wasting time with this voodoo?

      </layman>

      Good, you explained what you do, more or less. Now try explaining why you do that, otherwise this explanation is simply glorified "x = 42; // Assign 42 to x", like mentioned in comments elsewhere on this page.

      Human brain usually sorts by a mix of radix/bucket sort and insertion sort with a pinch of heuristics. "Quick" in quicksort is completely counterintuitive - even that memory hungry out-of-place version you describe, not to speak about usual explicitly or implicitly recursive in-place quicksort.

    45. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

      Except SQL injections appear when laymen write simple, laymen-readable code like "SELECT * FROM posts WHERE user_id=$user" (and $user is actually '1;drop table users;--')

      Do you consider parametrized queries laymen-accessible? Would you require an explanation of "parametrized query" concept and how it's better than plain string concatenation in every program? Would you require a polymorphic wrapper for parametrized queries included into every program, and only explain concept of parametrized queries (and polymorphic wrappers) there?

    46. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

      Mergesort for teachers with large classes: To alphabetic the large stack of exams you just graded, separate into 2-3 smaller stacks you can fit in your hand. Alphabetize these separately, and merge together in a natural way. This last "merge" step you just discovered is basically how merge sort works.

    47. Re:Similar language, describing different things by ndykman · · Score: 1

      Take a stack of cards with a word on them. Split them in half. Continue to do so until you have a lot of piles with two cards.

      Starting at the first two piles, make sure both the piles are in order, by switching the cards if needed.

      Now, merge the first two piles. To do this, look at each card in the second piles. Insert the card into the first pile so the pile is still ordered. This will give a new pile of three or four cards.

      Do this for the next two piles of two cards. When you reach the end of the two card piles, start at the beginning and do the same thing with the bigger piles. Continue until you get one pile.

    48. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

      While this is a good natural language explanation of the algorithm, it doesn't address the point that the code for the algorithm is going to look like voodoo. No computer would compile your explanation. Once it is in a langauge that can be compiled, it is more opaque. Once it is in a language and made efficient and optimized it will be even harder for a lay person to read. For example in golang (rough, aiming for equivalent to text description, not optimal behavior)

      func Quicksort(list []int) []int {
              if len(list) 2 {
                      return list
              }
              picked := list[len(list)/2]
              earlierPile, samePile, laterPile := SortPile(picked, list)
              earlierPile = Quicksort(earlierPile)
              laterPile = Quicksort(laterPile)
              result := append(earlierPile, samePile...)
              return append(result, laterPile...)
      }

      func SortPile(picked int, list []int) (earlierPile []int, samePile []int, laterPile []int) {
              for _, current := range list {
                      switch {
                      case current picked:
                              earlierPile = append(earlierPile, current)
                      case picked current:
                              laterPile = append(laterPile, current)
                      default:
                              samePile = append(samePile, current)
                      }
              }
              return earlierPile, samePile, laterPile
      }

    49. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

      argh, it dropped all my <, but I'm sure people can work out where they are meant to go.

    50. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

      Are you bullshitting me? That's one of better algorithms? What a waste of time and floor space. Don't your computers have "memory" or "RAM" or whatchamacallit to put "John Smith" right after "Jane Smith" right when it sees those while shuffling through that stack, without playing some silly solitaire. You know, like I would do?

      PS: Go on. Treat me like a layman you've got to explain merge sort to, and explain not just the rules of your silly card shuffle, but the reason you shuffle them that way. IOW, explain at least that "all bodies attract to each other, with force of attraction depending on masses of those bodies, but quickly dropping as distance grows", not just that "Well, here we multiply mass of one body by mass of another, then divide it by square of distance and multiply it all by a magic number - and that's what gravitational force is!"

    51. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

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

      Programs and laws are written in a context. Interpretation is derived from the context. Context is changing as time goes on, requiring new laws and software to be written. Like a purely functional program which can't operate meaningfully with it's context without side-effects, so can't an effective law be ignorant of it's context. Side-effects create coupling, which leads to buggy software and obsolete, dysfunctional and anti-constitutional laws.

    52. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

      FYI, counting sorts can be implemented more efficiently than comparison sorts. Even kids know how to do a radix sort on cards! :)

      Sort by suits:
      Alocate four piles, one for each suit.
      Iterate through the cards and place each card in the pile corresponding to its suit.
      Merge the piles in order.

      Sort by values:
      Allocate 13 piles, one for each card value.
      Iterate through the cards a second time and place each card in the pile corresponding to its number.
      Merge the piles in order.

      If you sort by suits and then by values, you'll get 2-clubs, 2-diamonds, ... 3-clubs, 3-diamonds, ...
      If you sort by values and then by suits, you'll get 2-clubs, 3-clubs, ... 2-diamonds, 3-diamonds, ...

      p.s. This assumes you immediately know where order of the values, so that you can place a card in the appropriate pile in O(1).

    53. Re:Similar language, describing different things by MetalOne · · Score: 1

      Without any added explanation it is of course gibberish. However, I think with an additional fairly brief explanation of symbols in the example, it would be quite clear to somebody with decent mathematical/logical thinking skills. And if the person doesn't poses those skills, then there is really no point in trying. It is certainly a nice addition to a description in English as it removes any ambiguity. Conciseness is often nice, because it doesn't allow any room for extraneous stuff. Of course, sometimes very concise code can still be difficult to understand.

    54. Re:Similar language, describing different things by MetalOne · · Score: 0

      It is still n(log n) average case. I'll grant you that if speed is super critical, that you're going to want an in place algorithm, in a language like C++.

    55. Re:Similar language, describing different things by ATMAvatar · · Score: 1

      Also: there's a large group of people constantly looking for and exploiting holes, and sometimes holes are intentionally added.

      --
      "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety."
    56. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

      This is pretty much the opposite of true. Complexity in law is usually due to lawmakers attempting to be precise. That doesn't mean it's necessarily good (or bad), but that's the reason the complexity exists. "Simple" laws are generally ambiguous.

    57. Re:Similar language, describing different things by stepho-wrs · · Score: 1

      Are you advocating a return to COBOL ?

    58. Re:Similar language, describing different things by Anonymuous+Coward · · Score: 1

      Explaining quicksort to the layman.

      [...]

      Sort the names into three piles

      That is dumb.

      The big advantage of quicksort is that is able to quickly sort in place.

      Now try to convey that with your piss-poor piles and cards examples.

      Anything but mergesort (including bubbesort) looks contrived with physical objects.

    59. Re:Similar language, describing different things by hamster_nz · · Score: 1

      That is dumb.

      The big advantage of quicksort is that is able to quickly sort in place.

      Now try to convey that with your piss-poor piles and cards examples.

      Anything but mergesort (including bubbesort) looks contrived with physical objects.

      Whoosh!

      The cards are 'pointers' to the actual people - so now you have a list of people in order, without actually getting all the people to stand in lines and run around.

    60. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

      What "whoosh"? You're trying to find extra metaphors where there are none. Even sorting 'pointers' instead of 'actual people' doesn't change the out-of-place nature of description, you're still creating temporary extra piles of 'pointers' and joining them. You can replace "cards" in that description with "bingo tokens" or "a bunch of different sized marbles". What are marbles pointing to?

      Actual usable implementations of quicksort look nothing like this simple overall description.

    61. Re:Similar language, describing different things by nschubach · · Score: 1

      Too complex for who?

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
    62. Re:Similar language, describing different things by KramberryKoncerto · · Score: 1

      Time complexity aside, insertion sort makes sense to laymen, bubble sort not so much. At least not that much easier than mergesort, quicksort and heapsort. There are ways to organize code that make those slightly more advanced algorithms easier to read.

      Bubble sort has a problem that it is not painfully obvious you'll end up with a sorted list; a layman only sees a lot of swaps and it takes a little bit of non-layman thinking to believe in it.

      With heapsort you first use function names like InsertValue and RetrieveMinimumValue to encapsulate the voodoo, and if the reader believes in these functions he'll understand the purpose. The voodoo part is less straightforward, but it still can be organized in certain ways that's easier to understand. You can name operations with the proper level of abstraction and granularity: RemoveMinimum, FindNewMinimum, SwapParentChild etc. A layman would most likely get stuck only at the lowest levels, that is understanding how FindNewMinimum works, and I don't think that part is harder than bubble sort.

      Mergesort and quicksort are more easily understood by laymen iteratively, when you go bottom-up, rather than top-down by recursion. With similar abstraction like above you can reduce both of them to a structure that makes sense to the laymen except possibly at the bottom level; I personally think for mergesort even the bottom level is quite straight forward (merging lists), while with quicksort the proof lies slightly more outside the scope of the code.

      These, of course, are not the most desirable codes for professional programmers.

    63. Re:Similar language, describing different things by Anonymous Coward · · Score: 0

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

      I have seen well written laws. Mostly they were traffic laws written when the writers and lawmakers took pride in their work.
      The main reason they are still good is that there haven't been a reason to change them.
      Current copyright law is pretty bad. It has been revised many times the recent years and much of it is arbitrary and ambiguous.

    64. Re:Similar language, describing different things by bwcbwc · · Score: 1

      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.

      Another way the law is like code is that legacy code and legal systems both grow more complex over time as new "features" are added, bugs are fixed, etc.

      For example, compare the commandment "Thou shalt not kill" with the exceptions and mitigations that have been added over time: self defense, soldiers in war, accident and so on. The law gets complex because simple laws don't cover all the possible extenuating circumstances.

      Another reason the law gets complex is because criminals are always coming up with new scams, exploiting loopholes and using the law against each other as a weapon. It's a lot like fighting malware on the internet or new requirements being generated for a program after it is released.

      --
      We are the 198 proof..
    65. Re:Similar language, describing different things by Marxist+Hacker+42 · · Score: 1

      Too complex to be easily understood by the programmer who will follow you.

      As was pointed out elsewhere, sometimes it is reasonable (such as with DSP microcode assembly language) to assume that your code will never be maintained or read by a human being.

      But for anything that contains a user interface, I'd say you need to use comments in your code. I know this goes against the Agile manifesto (which always struck me as silly that a methodology intended to make maintenance easier, actually makes it harder in real life- I guess it was never beta tested), but it is the truth. No matter what they tell you about the lifespan of your code, quadruple it. No matter what another programmer gives you for a time estimate to complete code, quadruple it. And six months down the road, your brilliant routine won't even be understandable to yourself without comments.

      --
      SJW: a person who perceives an injustice, and while correcting it, commits a greater injustice.
    66. Re:Similar language, describing different things by david_thornley · · Score: 1

      Okay, now try heapsort*. Try to convince them that exchanging the card in position 23 with the card in position 47 is a basic maneuver. You aren't going to be able to differentiate between sorts that use O(1) additional space and sorts that use O(n) additional space.

      Once you've done that, why don't you take a really big deck of cards and demonstrate JPEG encoding and decoding. Or convince them that they really don't need to use JPEGs. Face it, much of what we do can't be explained to the average person.

      *Offers guaranteed O(n log n) performance, no matter what, and is very useful for priority queues.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    67. Re:Similar language, describing different things by david_thornley · · Score: 1

      It's possible to write bad law that is simple. How about "All wives are the chattel property of their husbands, so husbands may do whatever they want to their wives."? How about "All people in public must dress reasonably modestly."? One is simply a horrifying law, and one is really ambiguous.

      A complex law may be complex simply because what it's covering is complex (a very common reason for complex code) or to avoid ambiguity. When dealing with human language, it can be difficult to avoid ambiguity, and that can lead to painstaking descriptions of what is and is not legal, adding complexity.

      Ever noticed that example code in programming textbooks nearly always ignores error handling, except in chapters on handling errors? That's because it makes the code more complex and harder to read. It's not because code without error handling is better.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    68. Re:Similar language, describing different things by hamster_nz · · Score: 1

      I'll pass on that - the reply was to the question "Please demonstrate a basic sorting algorithm that a non-programmer can understand that doesn't perform terribly on large lists". Job done, I'm moving on.

      But I agree, if any area of expertise didn't require a lot of learning to understand, then it would no longer be an area of expertise as most people could do it!

    69. Re:Similar language, describing different things by ahabswhale · · Score: 1

      Maybe 1% of the population of non-programmers would even understand a bubble or insertion sort.

      --
      Are agnostics skeptical of unicorns too?
  3. What? by TechyImmigrant · · Score: 1

    Since when was I required to do code reading as an exercise? I've never heard of such a thing.

    Can people stop inventing stupid new things I must do to be the perfect programmer?

    Do not invite me to your code reading club. I'll decline the invitation.

    --
    I should use this sig to advertise my book ISBN-13 : 978-1501515132.
    1. 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.
    2. Re:What? by Anonymous Coward · · Score: 1

      You're not required to do anything. On the other hand, refusing to be open to learning something new (in this case, how other people solve problems) is close to willful ignorance.

    3. Re:What? by JoeMerchant · · Score: 1

      Since you ever found employment at a firm which has existing code that they want to continue to use and evolve?

    4. Re:What? by Anonymous Coward · · Score: 0

      Code reading is part of one of my University modules. The module is 3 years old and close to being it's final.

      It's not a new skill and it's very useful.

    5. 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. ;)

    6. Re:What? by Anonymous Coward · · Score: 0

      Not to worry, you're name was never mentioned for any of the invite lists... :)

    7. 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
    8. Re:What? by Anonymous Coward · · Score: 1

      Oh Dear, "TechyImmigrant" is proving that outsourcing is still a terrible idea.

    9. 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.

    10. Re:What? by Anonymous Coward · · Score: 0

      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).

      I noticed that the first time I graded assignments. I learned my lesson and never noticed people cheating again although the stories of why they cheated were very interesting. None of them collaborated. Unless you count copying as a form of collaboration.

    11. Re:What? by TechyImmigrant · · Score: 1

      Insourcing, not outsourcing.

      --
      I should use this sig to advertise my book ISBN-13 : 978-1501515132.
    12. Re:What? by Anonymous Coward · · Score: 0

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

      Meaning you wanted to read it more and more. ;)

  4. Re:Slashdot is for niggers by Anonymous Coward · · Score: 0

    Welcome back. Have you been on vacation or in the slammer?

  5. What were they doing before? by kruach+aum · · Score: 1

    Discussing the meta-narrative implied by errant GOTO statements? Considering the motivations of while loops? Debating the thematic development in variable naming schemes?

    Learning from anything means analyzing it, knowing what goes where for what reason, and then thinking about if there are other ways to do it, better ways to do it, if it needs to be done at all, etc. When you're reading with the intent to understand and you're doing something that's not appreciably different from simply 'viewing words' you're doing something wrong.

    1. 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.

    2. 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.

    3. Re:What were they doing before? by kruach+aum · · Score: 1

      If I hadn't already taken part in this discussion I would upvote you. ""GOTO!" he cries out," is a brilliant line and should really be the opening of 'Waiting for GOTO'

    4. 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.
    5. Re:What were they doing before? by Anonymous Coward · · Score: 0

      That was beautiful.

    6. Re:What were they doing before? by Anonymous Coward · · Score: 0

      Incomplete and inadequate.

      Please define the implementation of the penis, vagina, and breasts. Also your proto-programmer has issues with Mommy but where is Daddy? Or, by needing a Daddy surrogate, do you mean that Daddy was absent and therefore our neo-programmer is guilt-laden and angry?

      Freud needs more!

    7. Re:What were they doing before? by gstoddart · · Score: 1

      Also your proto-programmer has issues with Mommy but where is Daddy? Or, by needing a Daddy surrogate, do you mean that Daddy was absent and therefore our neo-programmer is guilt-laden and angry?

      How does that make you feel? Do you still resent him?

      --
      Lost at C:>. Found at C.
  6. 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.

  7. Re:The real problem is... by Sarten-X · · Score: 0

    The code is not a dump truck. The code is a series of tubes...

    --
    You do not have a moral or legal right to do absolutely anything you want.
  8. Re:Slashdot is for niggers by Anonymous Coward · · Score: 0

    smit is that you?

  9. 80/20 rule by SQLGuru · · Score: 1

    80% of the code of a program is uninteresting and mundane. As a programmer, you want to get to the core nugget of a problem, suss it out and solve it. "Reading" code is the same thing. You want to decode the structure, find the interesting 20% and move on to gleaning whatever you can from it. It's in our nature.

  10. 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 Alomex · · Score: 1

      When writing code, your audience is not the compiler. When writing code, your audience is not the compiler.

      Sir, I'm a member of the language police and I just pulled you over for a stupid over generalization for effect infraction.

      Your audience is of course both the compiler and the other human being maintaining the code after you. A good programming language walks this fine line. Prolog was too much on the human side, Perl is too much on the interpreter side.

    2. 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.
    3. 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.
    4. 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.

    5. 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.
    6. 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.
    7. Re:Consider your Audience when writing code by Alomex · · Score: 1

      Bad code can be written in any language.

      And this in no way contradicts that some languages are better than others for that purpose. For a simple example consider the original COBOL syntax of

      ADD 1, N GIVING N

      This is sucky, harder to read code than n := n+1 or n++

      As far as the compiler is concerned, the code could be obfuscated.

      You have no idea how compilers operate if you believe this. The compiler is interested for example, in teasing apart dependencies so it can apply optimizations. Here's an example of badly written code in terms of the compiler:

      If Test(Water, Wet) then
        blah

      the compiler will be unable to see that the first call always succeeds and pipeline its execution.

      Another example, things such as side-effects are bad for the programmer and are bad for the compiler so just clarifying them for the programmer is not enough, e.g.


      x = f(object y) // function f touches variable z deep inside the methods of object y
      print z

      So the comment makes this perfectly clear to the programmer but not to the compiler.

    8. Re:Consider your Audience when writing code by gstoddart · · Score: 1

      When writing code, your audience is not the compiler. When writing code, your audience is not the compiler.

      Sir, I'm a member of the language police and I just pulled you over for a stupid over generalization for effect infraction.

      Well, as another member of the language police I'm required to remind you that including the quote twice for effect is a breach of hyperbole rule #17-c, and is, in effect, an equivalent infraction.

      Your section chief has been notified, and you will be required to take language remediation module 763.3.a. ;-)

      --
      Lost at C:>. Found at C.
    9. Re:Consider your Audience when writing code by phantomfive · · Score: 1

      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

      This quote is currently on our whiteboard at work right now.

      --
      "First they came for the slanderers and i said nothing."
    10. Re:Consider your Audience when writing code by phantomfive · · Score: 1

      . 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!

      Sometimes I mischievously add comments like that to the code, just because I know how happy it will make some people. //explain why I add comments like that to code

      --
      "First they came for the slanderers and i said nothing."
    11. Re:Consider your Audience when writing code by Obfuscant · · Score: 1

      And this in no way contradicts that some languages are better than others for that purpose. For a simple example consider the original COBOL syntax of ADD 1, N GIVING N This is sucky, harder to read code than n := n+1 or n++

      Algebraic notation is easier if you know algebra and that it really isn't algebra despite the similar appearance. "n++" in particular requires knowledge of pre and post increment ops. The COBOL, on the other hand, is almost English. If English isn't your language COBOL is hard.

      And I still remember the elegance of the:

      MOVE CORRESPONDING A TO B.

      COBOL syntax. It was a very fresh alternative to other early languages where you had to do this operation one field at a time. And if you modified the struct but forgot to add the copy of the new field every place you copied the old, you made bugs.

      x = f(object y) // function f touches variable z deep inside the methods of object y
      print z

      If you have made z a global so that it is in scope for function f as well as the main code the compiler will know this, as will the programmer.

    12. Re:Consider your Audience when writing code by Alomex · · Score: 1

      Not sure what to make of your post. It is universally agreed that ADD 1, N GIVING N was a mistake.

      The fact that COBOL has some other constructs that are nice (and indeed it does) in no way disprove my statement that a language can make a statement inherently easier to understand.

      Another simple example Algol/Pascal's n := n+1 is preferable to C/C++/Java's n=n+1 because this last can be confused with an equality test.

      If you have made z a global so that it is in scope for function f as well as the main code the compiler will know this, as will the programmer.

      I don't see what your comment has to do with my statement that the compiler cares about clarity beyond simply parsing syntactically valid code.

    13. Re:Consider your Audience when writing code by khr · · Score: 1

      When writing code, your audience is not the compiler.

      If you're primary audience is not the compiler why are you writing code at all? If the compiler isn't your primary audience, just tell another person what you want done...

    14. Re:Consider your Audience when writing code by Rockoon · · Score: 1

      "n++" in particular requires knowledge of pre and post increment ops.

      No it doesn't. Nothing about it requires knowledge of pre-increment or post-increment since their is no dependency on either. All you need to know is that it increments, and thats all the compiler needs to know too.

      --
      "His name was James Damore."
    15. Re:Consider your Audience when writing code by maxwell+demon · · Score: 1

      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!

      x = foo; // assign foo to x in order to make x equal to foo.

      Happy now? ;-)

      --
      The Tao of math: The numbers you can count are not the real numbers.
    16. Re:Consider your Audience when writing code by Common+Joe · · Score: 1

      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.

      Or even worse... that human being who reads your code a few years later might be a violent psychopath who sleeps in your bed, wears your clothes, and stares at you in the mirror while you shave.

      [Shivering] Damn. That does it. I'm never coding again.

    17. Re:Consider your Audience when writing code by david_thornley · · Score: 1

      Not that I want to defend COBOL, but I would never have written the increment as you do. I would have written ADD 1 TO N., which is easier to understand in general than your modern equivalents. (This is fairly old COBOL syntax, as the first COBOL compiler I used was based on COBOL 1966.) There's plenty to complain about in the earlier COBOLs, but you got that one wrong. There are good uses for almost all programming languages you've heard of (except perhaps the joke ones); it's just that I don't want to be involved in a situation where COBOL is the right choice.

      In your second example, the compiler may well be able to figure that "Test(Water, Wet)" is always true. It may even be able to prove that X is always water at a particular statement, so "Test(X, Wet)" is treated as "true" in a specific context. Humans are less likely to be able to do that. Note also that humans are likely to have problems if a bug somewhere means that "Test(Water, Wet)" is false.

      Similarly, the compiler is going to know if z can be affected by f(), which is more useful than some lame comment that could easily be wrong or become wrong with a slight change.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    18. Re:Consider your Audience when writing code by Alomex · · Score: 1

      I would have written ADD 1 TO N

      Point taken. I should have used as an example

      ADD 1, N GIVING M

      the compiler may well be able to figure that "Test(Water, Wet)"

      Yes, it may, and this depends on how well it can understand the code, which reinforces my point. The compiler needs to understand the code just as much as the maintainer five years down the road.

      the compiler is going to know if z can be affected by f(),

      In this case, I don't agree at all. It is not hard to write code where the compiler gives up and says "I can't tell if there is a dependency there or not" and does not pipeline the code. In fact you can find examples in textbooks with semantically equivalent snippets of code but one can easily be optimized by the compiler while the other can't.

    19. Re:Consider your Audience when writing code by Anonymous Coward · · Score: 0

      I write code as if I'm going to be reading it in 6 months. Isn't that good enough?

  11. tool, not primarily communication by Anonymous Coward · · Score: 0

    Code is a tool someone has built. It is not an attempt at communication. It is a language in a similar sense that mathematics is a language.It has more in common with a building or a car than a work of literature.

    1. 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.
    2. Re:tool, not primarily communication by phantomfive · · Score: 1

      Code is a tool someone has built. It is not an attempt at communication.

      If code were not an attempt at communication, we wouldn't care about readable variable names. A lot of the advances in programming language technology are there, not for the benefit of the computer, but for the benefit of the person who will come after you. They will need to read your code.

      --
      "First they came for the slanderers and i said nothing."
    3. Re:tool, not primarily communication by Anonymous Coward · · Score: 0

      > It is a language in a similar sense that mathematics is a language.It has more in common with a building or a car than a work of literature.

      Uh, are you completely unaware of the history of mathematic notation?
      It is very specifically a language and communication tool, specifically one that was introduced because human language just didn't cut it.
      Not because like in computer science we need a compiler to understand it, but because they needed a language _better_ than English (or German or French) for their purposes.
      What certainly may differ from a work of literature is that the purpose is to simplify communication / to communicate facts, whereas in some areas of literature using the most obscure words and complex way to say things is considered essential or being right out incomprehensible is a good thing.

    4. Re:tool, not primarily communication by maxwell+demon · · Score: 1

      Meaningful names are like labels on buttons. You'd certainly prefer a TV remote where the buttons have text or symbols telling you (or at least giving a hint about) what functionality they provide to a remote where the buttons are labelled with letters from A to Z, and a documentation that (hopefully) tells you that button X increases the volume.

      --
      The Tao of math: The numbers you can count are not the real numbers.
  12. 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".

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

      This is an extremely blinkered view of code that probably well-represents the majority opinion, given that that's the genesis of most programming languages.

      However, there is a small group of languages that aspires to represent computational concepts at an abstract level in a clear, consistent, and logical manner. These languages, like APL and J, are based on a regularization of mathematical notation.

  13. Re:Slashdot is for niggers by Anonymous Coward · · Score: 0

    welcome to /chan .... *facepalm*
    the support group for in-bread neo nazi survivors of horse rape is over at stromfront , here is where the adults are talking so stfu and go back to your google image searches for BBC ....

  14. 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?

    1. Re:Yeah I Could See That by Bite+The+Pillow · · Score: 1

      Most code is not in a style we recognize, so it requires decoding. Some code is recognizable, and it is read like literature, no decoding.
      Java or .net where most of the code is calling the framework, can be read if it is not overly clever. STL or rigorous C++ can be read.
      Any major shift from the expected paradigm requires parsing, of course.
      Being familiar with design patterns and best practice means you can read more and decode less, and have more to draw on.
      So yeah, it is both reading or decoding, depending on your skill level. If you decode more than read, you need more practice or exposure.

  15. Re:Slashdot is for niggers by Desler · · Score: 1

    Neo Nazis are in bread now? White, wheat or whole-wheat white?

  16. Code is like literature by Walter+White · · Score: 1

    I disagree completely. A program resembles literature on two levels.

    First, the code itself uses an extremely rigid grammar to express the requirements of the program. This expression can be simple or complex; clear or muddled. The extent to which the author (in every sense of the term) expresses these clearly and elegantly determines how likely the code is to succeed at its original purpose as well as how easy it will be to maintain.

    Secondly, the UI (if present) is also a realization of the ideas behind the program. The clarity with which the ideas are expressed in the UI will have a major impact on the usefulness of the program.

    I do not see a fundamental distinction between decoding code and written language. Both are abstract symbols assembled to form constructs and actions according to a set of more or less flexible rules. Many of the higher parts of language such as metaphor also have corresponding aspects in coding. (e.g. patterns.)

    And much like with literature which can be written in a multitude of languages, code can likewise be written in a multitude of languages. I think there are more similarities than differences.

  17. Crazy beetle ecosystem by Chemisor · · Score: 1

    Complex code is not just a specimen. It is an ecosystem, where your crazy beetle consumes crazy aphids and evades crazy ants, while simultaneously trying to reproduce itself and the entire ecosystem to the best of its ability. A crazy beetle would not eat anything standard, like say make or autoconf. No, his refined palate requires a more sofisticated tool like imake, cmake, or even an internally grown food made of ground up pythons. Eating and reproduction habits may also be equally crazy all on their own. For example, crazy beetle firefox can only reproduce when confined in a clean chroot with every consumable painstakingly arrange exactly like he wants it. Other crazy beetles sometimes refuse to eat when certain other crazy beetles are present. When let loose in an unfamiliar environment, crazy beetles sometimes quietly die for no apparent reason and intensive investigation may be required to uncover the cause of their demise. A biology degree may be helpful in such circumstances.

    1. Re:Crazy beetle ecosystem by Anonymous Coward · · Score: 0

      It's funny that you mention autoconf, which was one of the first crazy beetles.

      Use make *without* autoconf. Have a config.h file or ${platform}/{Makefile,config.h,platform_feature_foo.c} files if your code has legitimate porting issues. Don't attempt to anticipate portability problems, just deal with them if they arise, because more often than not, they don't. When you go chasing "ghosts of Ultrix past" you invite in all sorts of portability problems that have long since been evaporated.

      "'Portable' programs tend to be the most difficult programs to port."

      -puddingpimp

    2. Re:Crazy beetle ecosystem by Chemisor · · Score: 1

      > Use make *without* autoconf.

      Don't use make without autoconf.

      When a packager builds your project, the very minimum that needs to happen is installation to a fakeroot prefix to subsequently create a package from it. If there is no ./configure --prefix=/pkgroot equivalent, the poor packager will have to comb your whole damn tree to find out where you put your configuration options. If he's lucky, you have put them on top of the Makefile.

      The second reason is to turn features on and off. At the very minimum, ./configure --with-debug needs to be present to allow building a debuggable executable in case of problems.

      If you don't like autoconf, fine. Just write your own script to do these tasks. It can be done in 10k of bash code or less. Actual portability takes a little more, but is quite doable, considering how few platforms there are used today. Supporting only four - Linux, Windows, MacOS, and BSD - is more than enough for pretty much every project.

  18. 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.
  19. As a Literature Major/Programmmer ... by machineghost · · Score: 1

    As a Literature Major/Programmer, let me start by admitting the obvious: of course code is not literature, it's code. That being said, there is far more in common between the two than most programmers realize. Just as you can write an essay that's easy to understand and follow, or hard, regardless of the topic of the essay, so can you write code that easy/hard to grok regardless of what it actually does.

    In both cases a good writer tries to make the subject matter accessible to the reader, precisely so that they *don't* have to go on a scientific expedition just to grok it.

    1. Re:As a Literature Major/Programmmer ... by Anonymous Coward · · Score: 0

      Essays are not literature. Literature is (a certain hifalutin variety of) fiction.

    2. Re:As a Literature Major/Programmmer ... by Anonymous Coward · · Score: 0

      And both can be explored on superficial and deeper levels.

      Well written things should be grok'able at the top layers, but both are likely to require study/analysis to understand fully what they say.
      The more effort put in to the writing, the more that can be gotten on the early passes.

      Still code is code and requires a different set of skills to read than literature.
          The same could be said for English versus Russian literature.
              Both because of the language and cultural nuances.

      The article focused on the differences, but didn't acknowledge the similarities.
            This perhaps falsely made the conclusion seem stronger than it was.
           

    3. Re:As a Literature Major/Programmmer ... by maxwell+demon · · Score: 1

      Wikipedia disagrees:
      Literature is commonly classified as having two major forms—fiction and non-fiction—and two major techniques—poetry and prose.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    4. Re:As a Literature Major/Programmmer ... by Anonymous Coward · · Score: 0

      And some code is easier to read than some literature.

  20. An unusual exercise ... by Grindalf · · Score: 1

    No one, but NO ONE likes to work with someone else's code. It's bad news when you have to do this at work. It's much more effective to rewrite the job from scratch after planning the functionality, encapsulation etc. etc. again. So to most people this type of job (whether it's like a line by line dissemination of a machine code tome or whether it's like an insectoidal dissection) is an unusual and unpracticed chore.

    --
    The purpose of existence is to make money.
    1. Re:An unusual exercise ... by Anonymous Coward · · Score: 0

      No one, but NO ONE likes to work with someone else's code.

      The success of open source development seems to indicate otherwise.

  21. Code Tactics by Anonymous Coward · · Score: 0

    I examine code much like I study chess tactics. When should I use pointers, smart pointers, or garbage collectors? What are the methods and advantages of using different paradigms? When I read other people's code I'm constantly examining and criticizing their choices and implementations. If I find something that works better than what I'm doing I change my habits. It's not like sitting down and reading a book; its more like trying to solve a chess puzzle.

    Clean code is another matter entirely. All code should be written for the next programmer to be able to easily digest its intent and function, but making code easy to read over its functionality should be a programming sin. Not using threads because its harder for the next guy to debug is not an acceptable practice. If the code is not cleanly and clearly written it is very difficult to divine its true purpose.

  22. Re:The real problem is... by Anonymous Coward · · Score: 0

    I've imagined converting the text to something we can all naturally understand like sewer pipes and flows of water (data) in the third dimension.

    You and many others. But people keep reinventing Labview, and it's always a bit of a mess. Not to mention change review and source control!

    If you're really interested in that kind of abstraction you might want to take a look at Haskell with arrows and monads.

  23. Wrong model by gweihir · · Score: 1

    Unlike literature, Art, music, etc., code has very little redundancy. In fact, low redundancy is a quality measure for code. Hence "reading" is an entirely unsuitable approach, as "reading" relies on relatively high redundancy on all layers.

    IMO somebody that does not understand this beforehand does not have any real understanding of what code is.

    --
    Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
  24. Re: comments by Anonymous Coward · · Score: 0

    "Comments should say what is not obvious and cannot be made obvious by the code itself."

    Comments should explain the WHY, not the WHAT.

    e.g. /* cannot do <obvious first choice> because <explanation> */ or /* X can never be Y because <proof> */

  25. you don't read it? maybe by Anonymous Coward · · Score: 0

    Plain English (a movement by the osmosian order) is a selfcompiling programming language composed of literally plain english

  26. 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"?
    1. Re:I don't see how any programmer would think that by maxwell+demon · · Score: 1

      I don't see how any programmer would think code was literature, except perhaps highly technical literature.

      Maybe because he does literate programming.

      You read novels from beginning to end.

      Novels are by far not the only type of literature. I don't know about you, but I rarely read a textbook from beginning to end.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    2. Re:I don't see how any programmer would think that by Anonymous Coward · · Score: 0

      Looking for a job....?

      Jeeze I wish someone like you would walk into one of my interviews.....

  27. 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 RedWizzard · · Score: 1

      Knuth disagrees...

      Knuth (and many others) think code should be more like literature, but 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. Knuth actually provided an anecdote that reinforces this point so I very much doubt he disagrees with it.

    2. 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."
    3. Re:Knuth disagrees by hibiki_r · · Score: 1

      Code should be easy to read, and it should be easy to find what you want. Therefore, while it might resemble a book, it will not look at all like literature.

      The best code out there deals with extremely complex problems, and turns them into something so simple, anyone that approaches the problem by reading the code must think that the problem was trivial. So trivial that most simple enhancements pretty much write themselves. Only after maintaining a codebase like that for a while, or seeing the same developer do this over an over again, your typical reader realizes how much skill was put into making the extraordinary look ordinary. If anything, this is the opposite of literature.

    4. Re:Knuth disagrees by phantomfive · · Score: 1

      If anything, this is the opposite of literature.

      Good literature conveys complex ideas and feelings and images simply and in a way the reader understands and appreciates. The number of ideas a good writer can fit into a few words is startling. Think of Kafka's excruciating violin scene in Metamorphosis and the death of love, of Victor Hugo's portrayal of the complex goodness of Bienvenu, of Fitzgerald's scene in Great Gatsby where the narrator takes his love in his arms and kisses her.

      Now, a lot of the modern unreadable literature and has a different parallel in the code world: the IOCCC. The best of it is like a puzzle for the reader to figure out and dig into (I'm talking about Ulysses here, not

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

      The best code out there deals with extremely complex problems, and turns them into something so simple, anyone that approaches the problem by reading the code must think that the problem was trivial. So trivial that most simple enhancements pretty much write themselves. Only after maintaining a codebase like that for a while, or seeing the same developer do this over an over again, your typical reader realizes how much skill was put into making the extraordinary look ordinary.

      Also, if you know of any open source code that is like this, I would love to see it.

      --
      "First they came for the slanderers and i said nothing."
    6. Re:Knuth disagrees by david_thornley · · Score: 1

      My thoughts on Literate Programming, somewhat edited and really condensed:

      Hey, this looks neat! I'll try writing a program with it. Let's see, I need to get the tangle and weave programs, I'm sure I can do that. Now, how do I write something like that? Huh? There's markup there that I don't recognize, so I'd have to learn markup in addition to Pascal. I'd have to divide the program into logical chunks that include the whole program and figure out how to present each one, and in what order. You know, presenting code out of order could cover up a lot of bugs. I could look at the stuff that goes into the compiler, but it's got all the comments removed, so it'll be harder to read. Is presenting a program like this really worth all the extra effort?

      That's when I lost all enthusiasm for it. I may be completely off-base on this, but nobody's given me reason to believe that.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    7. Re:Knuth disagrees by phantomfive · · Score: 1

      so I'd have to learn markup in addition to Pascal.

      Use cweb if you prefer C.

      You know, presenting code out of order could cover up a lot of bugs.

      Do it in a way that doesn't cover up a lot of bugs. This actually doesn't seem to be a problem: at least, the largest program I know have that was written with web has the reputation of being extraordinarily bug free (Tex).

      --
      "First they came for the slanderers and i said nothing."
    8. Re:Knuth disagrees by RedWizzard · · Score: 1

      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)?

      Evidence? Did you RTFA? I've just given you a one line synopsis, if you want evidence you'll find it there.

      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.

      We're not talking about Knuth's book. We're talking about the article, which you apparently didn't bother to read. In it Knuth provides an anecdote that supports the author's contention. Please, go and RTFA.

    9. Re:Knuth disagrees by phantomfive · · Score: 1

      ) Evidence? Did you RTFA? I've just given you a one line synopsis, if you want evidence you'll find it there.

      Please do, because it's apparent you misunderstood it. Knuth was trying to decode a language he has never seen before. It's not how he thinks reading code should be, really.

      We're not talking about Knuth's book.

      We're talking about Knuth's opinion.

      --
      "First they came for the slanderers and i said nothing."
    10. Re:Knuth disagrees by RedWizzard · · Score: 1

      We're talking about Knuth's opinion.

      The whole point behind Literate Programming is that you can't read non-literate code as literature, and Knuth believes being able to read code as literature makes it easier to understand. If you could read any sort of code as literature then why would we need literate programming? So given that virtual all code in existence is non-literate it's pretty obvious that trying to promote code reading as literature reading is not going to work that well. The point of this article is that the author tried it both ways (code reading groups reading code as literature and treating it as an investigation) and found the investigative approach worked better. He's not expressing an opinion or proposing a hypothesis, he's simply reporting what worked and what did not.

  28. A better analogy by shilly · · Score: 1

    Sounds like he needs to read "The Chosen" by Chaim Potok, where he'd find another analogy. Then he could try the chevruta model.

  29. Code isn't literature by Anonymous Coward · · Score: 0

    Most of the code I see is spaghetti!

  30. Its all mathematics. by Anonymous Coward · · Score: 0

    Reading a program is more like reading a mathematical proof.

    It shows what the author understood as the problem, and the approach to a solution.

    Thus it is much more like a "peer review" of a mathematical proof prior publication.

  31. The only surprising thing by DerekLyons · · Score: 1

    The only surprising thing is that it's taken this long for him to figure this out.

  32. 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.

  33. So this is why I can't get Outline View? by Tsu+Dho+Nimh · · Score: 1

    This may explain why the incredibly ancient feature request for an "Outline View" in OpenOffice has gone over a decade (Reported: 2002-04-10) with no resolution.

    https://issues.apache.org/ooo/...

    The mental mapping of code for programmers and the mental mapping of text to those of us who write literature and non-fiction is totally different. They can't visualize how an outline and headings and the cues fonts give readers differs from all the "mind maps", "document navigators", and other inadequate replacements they keep suggesting will fill the need.

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

    obviously white-only

  35. 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.

    1. Re:We don't read poetry... by Craig+Milo+Rogers · · Score: 1

      We parse poetry.

      --
      Craig Milo Rogers
  36. Math or Poetry by dcollins · · Score: 1

    Just reading the summary, but this guy sounds off-base. There are different "densities" of writing, ranging from children's books and newspapers on one end, to stuff like academic journals, math, and poetry on the other end. Those latter types expect a much slower rate of progress, and more questioning-probing-ruminating on the text as you go. As usual, computer code is a lot like math. The author need not go so far afield for a good analogy.

    --
    We know where leadership by an anti-intellectual "strongman" who scapegoats minorities and likes boisterous rallies goes
  37. On the other hand by tpstigers · · Score: 1

    we could just treat code as though it were code.

  38. Code is not Literature. by Dishevel · · Score: 1
    In other news ...

    Oil is not Tea.

    No more to ad.

    --
    Why is it so hard to only have politicians for a few years, then have them go away?
    1. Re:Code is not Literature. by Anonymous Coward · · Score: 0

      "No more to ad." You mean "No more two add."

  39. Re:Other people's code? I can't even figure out mi by Anonymous Coward · · Score: 0

    Heh. My favorite bit of code written for 1st-year C class was a simple function to convert grades from a numeric percentage to a character representing the letter grade. (Breaks were inclusive and at 10% increments, so 90-100%=A,80-89%=B, etc.) This problem was of course assigned at the end of the lecture introducing switch/case.

    char grade(int percent) {
      if(percent < 50) percent=50;
      return 'A' + (99 - percent)/10*5/4;
    }

  40. Black Perl by Anonymous Coward · · Score: 1

    Obligatory http://en.wikipedia.org/wiki/Black_Perl

  41. Re:Other people's code? I can't even figure out mi by Impy+the+Impiuos+Imp · · Score: 1

    Good code is never nearly as self-documenting as people think. I have re-written stuff just giving variables and functions more accurate names, and you still should have comments saying what is going on and why.

    --
    (-1: Post disagrees with my already-settled worldview) is not a valid mod option.
  42. Exactly right by SuperKendall · · Score: 1

    When he said " A piece of code is not literature; it is a specimen.'" I was thinking that might apply to HIS code but that does not describe the code that good coders are trying to produce.

    Also "specimen" implies the code is dead, when most code is very much alive and in flux...

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  43. Re:Other people's code? I can't even figure out mi by foobar+bazbot · · Score: 1

    Oops, hit submit instead of preview, and forgot to log in... Take 2:

    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.

    Heh. My favorite bit of code written for 1st-year C class was a simple function to convert grades from a numeric percentage to a character representing the letter grade. (Breaks were inclusive and at 10% increments, so 90-100%=A,80-89%=B, etc.) This problem was of course assigned at the end of the lecture introducing switch/case.

    My code was something like:

    char grade(int percent) {
      if(percent < 50) percent=50;
      return 'A' + (99 - percent)/10*5/4;
    }

    (I'm sure it's obvious enough, but integer division does the magic; multiplying by 5, then dividing by 4, maps 0-3 to 0-3, but maps 4 to 5; this skips E to give the proper sequence of ABCDF.)
    Actually, I may have handled the <50 case inline with the conditional operator instead (e.g. percent>50?percent:50), not sure. (I went through a conditional-operator-happy phase in school, having not yet realized how frequently it just makes code harder to read.)

    Anyway, my instructor fortunately didn't have a policy like that, and knew me enough to know I grokked switch/case anyway. He told me later that he enjoyed showoffs, because grading normal solutions was tiresome, and a few minutes examining some other approach was a welcome break.

  44. 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.

    1. Re:How about Architecture by DerekLyons · · Score: 1

      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.

      The problem is... so long as the building doesn't fall down, architectural reviewers review architecture in exactly the same way that literature and "high art" reviewers review their field. It's all about buzzwords and status and soft theory. The engineering is left "as an exercise for the student" and treated as mere mechanics.

  45. Perhaps off-topic... by mariox19 · · Score: 1

    I just realized that, if I follow the author's argument about decoding rather than reading, James Joyce's two major works don't qualify as literature.

    --

    quiquid id est, timeo puellas et oscula dantes.

  46. A discussion is a discussion by Anonymous Coward · · Score: 0
    What's the difference?

    '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.'"

  47. Re:Other people's code? I can't even figure out mi by maxwell+demon · · Score: 1

    (I'm sure it's obvious enough, [...])

    For anyone sufficiently familiar with the (American?) grading system, possibly. All others are left puzzling until they get to the end of that parenthetical remark.

    --
    The Tao of math: The numbers you can count are not the real numbers.
  48. Programmer Archaeologists by Anonymous Coward · · Score: 0

    Pham Nuwen would understand.

  49. Re:Other people's code? I can't even figure out mi by Anonymous Coward · · Score: 0

    What is going on is documented by the code itself. Why is another matter - comment on the why!

  50. Re:Other people's code? I can't even figure out mi by mdielmann · · Score: 1

    Translation:

    1: Don't code drunk.
    2: Self documenting code isn't actually self documenting.
    3: Non-self documenting code (hardware-specific strings/code) is also not self documenting.

    Therefore, don't code while drunk, and comment your code. Even if it seems obvious, summarize any block of code, so when you come back to it months (or years!) later you'll have a clue of what it was supposed to do, and then maybe you'll be able to figure out what you were trying to do in the first place.

    This is based on my experience of looking at code I wrote six months or more ago that worked perfectly fine but needed some new feature included. My rule of thumb nowadays is, "If a block of code is more than three lines long, it should be commented. If it's three lines or less long, it might need commenting, too.

    --
    Sure I'm paranoid, but am I paranoid enough?
  51. Mod Parent up by Anonymous Coward · · Score: 0

    Thank you for your comment this is why I come to /. still

  52. Read vs decode by Anonymous Coward · · Score: 0

    Good code is code you can read; code should be good code, but often isn't; code that is not good does not appeal to our lingustic intuition, or its associated aesthetics; most code must be decided, and that is because of the poor quality of authorship that results when people believe that it only matters if the program makes sense to the programmer, appears to behave correctly now, and is sufficient to get paid. We set an overly low bar for ourselves, despite lessons of eg Knuth and Moore, and we reap the consequences: bugs and bad design.

    1. Re: Read vs decode by Anonymous Coward · · Score: 0

      And I should add that much of the current scientific and philosophical literature should be seen in the needToDecode category. As are many badly written books. Proper writing is dying now that media is so cheap.

  53. Re:Other people's code? I can't even figure out mi by Anonymous Coward · · Score: 0

    Code drunk, but keep git handy. For hangover, take one git reset --hard HEAD.

  54. Re:Other people's code? I can't even figure out mi by Anonymous Coward · · Score: 0

    Sad to say, but this is not always possible in the real world. At work, I have a task queue about 30 deep. I.e., on any given day, there are 30 different tasks to complete before they reach SLA. On some days the deadline is just a few hours away so these tasks, regardless of complexity, get hammered on. They can be simple bug fixes ("menu not selectable when in Chrome"), complex bug fixes ("New version of Chrome changes test case render"), performance fixes both simple and complex, and the dumb ("marketing wants snowflakes to fall; blizzard effect follows mouse"). So I hammer those out at a furious clip, fixing them all then signing into Remedy to mark them as completed before they hit SLA because my performance review is tied to it. I don't bother so much with comments and beautiful code.

    Beautiful code I reserve for hacking on Linux and obscure libraries to calculate poker odds.

  55. Thanks for that by Anonymous Coward · · Score: 0

    Thanks for the article /. All these years I've been developing code thinking I was writing a book for people to read, thanks for setting me straight and not wasting a minute of my life reading this crap

  56. Phillip Spring by Anonymous Coward · · Score: 0

    He did interviews with programmers to figure out that? He isn't a hacker! He is a psychiatrist!

    I'm a good programmer because I did it to myself, I didn't just read high quality code! Most of the technicians who quit programming do it because they face unreadable source code.

    Hate me, but.. If someone wants to be the best programmer of the galaxy, just wish for it. Don't copy code: Learn how a system works.

  57. Nick Montfort by Anonymous Coward · · Score: 0

    Oh crap, that pretentious oaf Nick Montfort is going to get involved at some point isn't he? He'll probably just copy and past the comments into his word processor and produce a new "insightful best-seller".... Submitted as an AC due to moderation points....

  58. not Joe Schmoe by Chirs · · Score: 1

    The problem is when you move on and your replacement needs to get up to speed, or you need to go back two years later to fix a corner case.

    Assembly code in particular can be hard to follow. Among other things, if I'm writing assembly that ties into higher-level language code I find it helpful to include human-readable descriptions of what the various registers are on entry and on exit. I'll also break up the code into logical blocks and include a comment describing at a high level what is happening in each block.

  59. art work by raorajesh · · Score: 1

    In India, software code is copyrighted as "art work". Indeed it is. Quoting someone familiar to us all - "In the work of art the truth of an entity has set itself to work."