Slashdot Mirror


Donald Knuth Rips On Unit Tests and More

eldavojohn writes "You may be familiar with Donald Knuth from his famous Art of Computer Programming books but he's also the father of TeX and, arguably, one of the founders of open source. There's an interesting interview where he says a lot of stuff I wouldn't have predicted. One of the first surprises to me was that he didn't seem to be a huge proponent of unit tests. I use JUnit to test parts of my projects maybe 200 times a day but Knuth calls that kind of practice a 'waste of time' and claims 'nothing needs to be "mocked up."' He also states that methods to write software to take advantage of parallel programming hardware (like multi-core systems that we've discussed) are too difficult for him to tackle due to ever-changing hardware. He even goes so far as to vent about his unhappiness toward chipmakers for forcing us into the multicore realm. He pitches his idea of 'literate programming' which I must admit I've never heard of but find it intriguing. At the end, he even remarks on his adage that young people shouldn't do things just because they're trendy. Whether you love him or hate him, he sure has some interesting/flame-bait things to say."

567 comments

  1. Literate programming... by Gordonjcp · · Score: 3, Insightful

    ... looks like it falls into the same trap as COBOL. The idea that by making programming languages incredibly verbose, they will somehow become easier to use is a fallacy.

    Using "MULTIPLYBY" instead of "*" isn't going to make your code easier to read.

    1. Re:Literate programming... by CastrTroy · · Score: 3, Insightful

      I'm not sure if MultiplyBy is any better. It takes longer to type, and most people have understood that * (or X) meant multiply by since second grade. The thing I like about more verbose languages like VB.Net are that they force you to write out things that most good programmers would write out anyway as comments. At the end of a while loop, you write "End While". Most people using C++/Java/C# end up writing "} //end while" anyway, especially if the loop goes over 6 or 7 lines, and even more likely if there's a nesting construct like an if statement in there anyway. Seeing the "End While" let's you know what you are finishing off, without scrolling higher and trying to line up and see which bracket matches. Which even with visual brace matching, can sometimes be difficult.

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    2. Re:Literate programming... by hedwards · · Score: 1

      That's not at all what he's referring to. It's the practice of using white space and proper comments to document the code in a clear way. Since nobody that's going to be reading code is going to need MULTIPLYBY for clarity over * that wouldn't be an appropriate choice. Further using the former rather than the later would cause further headaches by making the code more difficult to read.

      As a general rule no matter where you are in the code no screen should be without at least a couple of codes, if you can scroll such that there aren't any comments on screen, you're probably doing something wrong.

      The commenting, doesn't have to be terribly verbose, it's just enough to succinctly say what's going on, and variables, really ought to be commented at the top where they're defined for further clarity, when the variable name itself is insufficient. Variable and function names should of course also be a form of documentation, provided that it can be done adequately with a reasonable number of letters.

      That's basically what he's getting at, and I can guarantee you that if you're writing code like that it's far more difficult for bugs to hide than in a terse obfuscated code base which is difficult for anybody to read.

    3. Re:Literate programming... by 1729 · · Score: 4, Interesting

      ... looks like it falls into the same trap as COBOL. The idea that by making programming languages incredibly verbose, they will somehow become easier to use is a fallacy.

      Using "MULTIPLYBY" instead of "*" isn't going to make your code easier to read. From what I've seen (particularly of CWEB), literate programming doesn't change the programming language itself, it just adds a TeX style markup to the comments so that detailed (and nicely typeset) documentation can be generated from the source code. Take a look at some of Knuth's CWEB code, such as his implementation of Adventure:

      http://sunburn.stanford.edu/~knuth/programs/advent.w.gz

      It appears to be ordinary C once the CWEB documentation is stripped out.
    4. Re:Literate programming... by Basilius · · Score: 5, Informative

      That's not literate programming at all. A tad more research on your part is required. I actually remember when "web" in a computing context a literate programming tool rather than that thing you're surfing right now.

      Literate Programming interleaves the documentation (written in TeX, naturally) and code into a single document. You then run that (Web) document through one of two processors (Tangle or Weave) to produce code or documentation respectively. The code is then compiled, and the documentation built with your TeX distribution. The documentation includes the nicely formatted source code within.

      You can use literate programming in any language you want. I even wrote rules for Microsoft C 7.0's Programmer's Workbench to use it within the MSC environment.

      I've frequently thought about going back. Javadoc and/or Sandcastle are poor alternatives.

    5. Re:Literate programming... by jared9900 · · Score: 1

      I think that you're misunderstanding the example provided, and literate programming as a result. Literate programming is a language agnostic technique of writing a program essentially as a paper or book, where the book provides a fairly complete description of the behavior of the code, algorithms used, expected input formats, etc. For instance, if you were to use this technique when writing a compiler you could detail the language you'll be compiling alongside the code that will handle that portion of the parsing/interpreting/translating. On his website (Knuth's programs page) he presents a number of programs written using CWEB, C combined with TeX to generate both compilable C code and a fully documented program. He's also written books using this technique, specifically "TeX: The Program" and "METAFONT: The Program", both make use of Literate programming, and both programs are written in Pascal.

    6. Re:Literate programming... by Anonymous Coward · · Score: 0

      In my experience, software created with literate programming has turned out to be significantly better than software developed in more traditional ways. Yet ordinary software is usually okayâ"Iâ(TM)d give it a grade of C (or maybe C++), I love this subtle dig on C++, that it's only ever marginally readable and not suitable for literate programming. Hah. Nice one, Knuth.
    7. Re:Literate programming... by Junta · · Score: 1

      I read a sample and I must confess that I think the sample was more confusing than most typical code. I'm talking about how multiply gives only one operand, and seems to be using an implicit default variable. Perl also can do this, and when I see people use it in complex situations, it's hard to tell when the last time default would have been set at times.

      I do agree making the primitives verbose doesn't help. Ultimately, it isn't the fact that '*' is hard to understand, or that braces enclose blocks, the primitives used in conjunction with clear variable names is sufficient for that to be comprehensibe. You don't see (at least shouldn't):
      $total = $subtotal * (1+$tax) # Mulitply the subtotal by 1 plus the sales tax

      Because it's so simple. Comments come in to explain things in certain cases. The 'black box' description of the function with what it expects and what it will spit out, without talking about intermediate steps. And to explain potentially convoluted blocks.

      --
      XML is like violence. If it doesn't solve the problem, use more.
    8. Re:Literate programming... by CastrTroy · · Score: 1, Insightful

      So basically it's the same as the XML comments you can put in your .Net or Java code to create JavaDocs, or whatever they are called in .Net, based on the comments in the code?

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    9. Re:Literate programming... by Eunuchswear · · Score: 4, Insightful

      Most people using C++/Java/C# end up writing "} //end while" anyway,
      Pray god I never have to work on code written by these fictitious "most people".

      I'd kill any colleague of mine who wrote such a vacuous comment. With a golf club, in front of its cow-orkers to drive the lesson home,
      --
      Watch this Heartland Institute video
    10. Re:Literate programming... by davolfman · · Score: 2, Insightful

      I don't. It's pointless if you format your code decently. The bracket and the knockdown in tabbing should be enough. The only place I can see it being useful is when you have a truckload of nested brackets and even then you want something a lot more useful than "end while" it should at least name the stinking loop.

    11. Re:Literate programming... by 1729 · · Score: 4, Insightful

      Most people using C++/Java/C# end up writing "} //end while" anyway,
      Pray god I never have to work on code written by these fictitious "most people".

      I'd kill any colleague of mine who wrote such a vacuous comment. With a golf club, in front of its cow-orkers to drive the lesson home, I sometimes add comments like that if the brace is closing a deeply nested block, but then the comment indicates which particular loop or block is ending.
    12. Re:Literate programming... by Anonymous Coward · · Score: 0

      and the thing that I don't like about them is that they force you to write out things when they are not an absolute necessity for readability/maintenance, e.g. a loop with single statement. with C like syntax we have the choice and get rid of clutter when not needed.

    13. Re:Literate programming... by jinxidoru · · Score: 1

      Excuse my ignorance, but please explain how this this different (or superior) to doxygen or any of the many systems that do just this. I'm not meaning to be rude, I'm just asking.

    14. Re:Literate programming... by Goaway · · Score: 1

      No. It also allows re-ordering code for better readability.

    15. Re:Literate programming... by Swizec · · Score: 5, Insightful

      I concur. Comments should tell WHY the while block is there and what it DOES. Not where it starts and where it ends, the code tells us that descriptively enough.

      I've met code blocks several hundred lines long and it was never ambigious where they started and ended.

    16. Re:Literate programming... by iMacGuy · · Score: 2, Informative

      In literate programming, the documentation is the default state and you have to escape it to write code. It's an important difference if you're going to write a lot of it.

      --
      Why won't slashdot let me change my terrible username :(
    17. Re:Literate programming... by numbsafari · · Score: 3, Interesting

      A better way to handle that is to turn the loop body into a function or group of functions. makes the code easier to read and a good compiler will inline the function so their's no performance loss.

    18. Re:Literate programming... by Anonymous Coward · · Score: 0

      I sort of understand the logic of using MultiplyBy. It is the same logic as using const T operator *(const T& arg1, const T& arg2) and A.operator *(int val) instead of *. It forces you to check type and not assume things.

      E = (D = A * (B * C) * 5);

      has a lot of things hidden. Are you passing by reference or value? Are you returning by reference or value? And how many times are constructors and copy constructors called? This statement could be rewritten:

      E.operator =((D.operator =(operator *(A, (operator *(B, C)).operator *(5)))));

      Awareness of this form is critical if you don't want to make a shitload of errors. And awareness of exactly how many times copy constructors and assignment operators are used is essential as well. The MultiplyBy or operator * forms reduce the need to explain the details hidden in the concise form and make it obvious when you need to pass by reference or by value.

    19. Re:Literate programming... by harlows_monkeys · · Score: 1

      That has nothing to do with literate programming. That Wikipedia article is very poorly written.

      You can find an example of the old classic ADVENTURE game, ported to C, here, in the file adventure.zip.

      Run that through the appropriate tools, and you end up with code to feed the compiler, and a listing to give humans. The listing for humans is here.

    20. Re:Literate programming... by Anonymous Coward · · Score: 0

      If that were what Knuth advocates it would be stupid.

    21. Re:Literate programming... by Anonymous Coward · · Score: 1, Funny

      What's a cow-orker? A misspelled description of somebody who irritates cows?

    22. Re:Literate programming... by Sancho · · Score: 2, Informative

      From my brief look at doxygen, it looks like the biggest difference is semantic. Literate Programming with web is effectively documentation with code bits and metacode to indicate where the code bits should go. This means that the code bits can be (and should be) in the order that makes the most sense for the documentation. This is not necessarily the order that makes the most sense for the code.

      Doxygen looks like it just extracts properly formatted comments in code in order to generate documentation. Web extracts properly formatted bits of code in order to generate a semantically correct C file.

    23. Re:Literate programming... by Coryoth · · Score: 2, Informative

      Excuse my ignorance, but please explain how this this different (or superior) to doxygen or any of the many systems that do just this. I'm not meaning to be rude, I'm just asking. I think the prime difference is that literate programming allows you to re-order the code; that is, you include snippet of code within the documentation, and attach tage to the snippets that allow them to be reassembled in a different order. That doesn't sound like much, but it means that you can just write the documentation have code appear as i is relevenat to the documentation rather than having the program structure dictate things. Take a look at some examples (in various languages) to see what I mean. The key here is that documentation is (or should be) first and foremost in the writers mind, and it is the documentation that dictates presentation structure. This means that you are concentrating on writing the documentation, and will thus write it well, as opposed to concentrating on code, and adding documentation as an afterthought if you get around to it. Well, that's the principle at least.
    24. Re:Literate programming... by sholden · · Score: 2, Informative

      It predates it.

      And the philosophy is different, literate program is essentially embedding the code in the documentation. Doxygen is more about embedding documentation in the code.

      So doxygen gives you fancy comments and a way of generating documentation from them and from the code structure itself. CWEB lets you write the documentation and put the code in it deriving the code structure from the documentation, sample cweb program: http://www-cs-faculty.stanford.edu/~knuth/programs/prime-sieve.w

      Literate programming is more suited for "dense" programs, which surprise, surprise is the type of stuff Knuth does.

    25. Re:Literate programming... by Anonymous Coward · · Score: 0

      Would you rather work on code that is a sea of brackets?

      I think I would rather see comments like that to specify what a bracket does than deal with "MULTIPLYBY" "End while" etc. etc.

      It depends on the case of where that close while bracket is whether it should be indicated as such, if it's in a sea of other close brackets it makes some sense, yes, you could collapse in a proper IDE and sort out which is which; but I think I would rather see at a glance where that bracket belongs before I go and start throwing code changes in-between random functions, loops, etc.

    26. Re:Literate programming... by MrSteveSD · · Score: 1

      Pray god I never have to work on code written by these fictitious "most people". I'd kill any colleague of mine who wrote such a vacuous comment. With a golf club, in front of its cow-orkers to drive the lesson home,

      That sort of comment is often written by programmers who put far too much in one function. So much so that the top of the while loop is miles off the screen, so that they actually need the "//end while" to remind them what was going on. I've spent many an hour coming across such monster functions and refactoring them into digestible and reusable pieces.
    27. Re:Literate programming... by CastrTroy · · Score: 1

      Yeah, I'm not saying that it's the best thing to have huge loops that go on for pages, but at least when it happens, it's nice to have a little comment at the end to tell you what's going on. I really wish that every programmer I worked with could be an uber-elite programmer, and wouldn't create these 1000 line functions in the first place, but let's face it. Not all programmers are uber-elite, and many are only slightly better than not being there at all. Any construct of the language that forces them to be a little more explicit in what they are doing is a help to everyone.

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    28. Re:Literate programming... by Anonymous Coward · · Score: 0

      "Literate Programming" simply refers to the same thing as "literate writing".
      We're talking about an idea well expressed, and nothing more. It has nothing particular to do with how code is commented, or how whitespace is used (unless, as in the case of Lisp, whitespace is an integral part of the expression.)
      When Knuth named a book "The Art of Computer Programming", he implied that there is an aesthetic in code. If something is ugly, it's wrong. Comments can't fix wrong. If something is elegant, it's right. Comments can't add much. If someone can't tell the difference, he shouldn't be a programmer.

    29. Re:Literate programming... by Cal+Paterson · · Score: 1

      The idea that by making programming languages incredibly verbose, they will somehow become easier to use is a fallacy.
      Assumptions, they make an ASS out of...etc
    30. Re:Literate programming... by Monkeybaister · · Score: 1
      To say what numbsafari pointed out in a different way: If you're code is getting confusing enough to make it hard to know which block is getting closed, the solution is not labeling the closing of the blocks, but to encapsulate parts of your code into functions so the overall program flow is clear.

      The only place where this could be appropriate is in C preprocessor statements or similar, but then you should be questioning if you're doing too much with them.

    31. Re:Literate programming... by Anonymous Coward · · Score: 0

      You are complety fucking clueless. Who are the morons modding this shit up?

    32. Re:Literate programming... by rascher · · Score: 5, Funny

      I myself solve the problem using this construct:

      #define BeginWhile {
      #define EndWhile }

      #define BeginFor {
      #define EndFor } ...

    33. Re:Literate programming... by pthisis · · Score: 1

      Yeah, I'm not saying that it's the best thing to have huge loops that go on for pages, but at least when it happens, it's nice to have a little comment at the end to tell you what's going on. I really wish that every programmer I worked with could be an uber-elite programmer, and wouldn't create these 1000 line functions in the first place, but let's face it. Not all programmers are uber-elite, and many are only slightly better than not being there at all. Any construct of the language that forces them to be a little more explicit in what they are doing is a help to everyone. Ugh no. Those kinds of comments/verbose delimiters make it harder to read code, not easier.

      Really, any decent editor automatically tells you which brackets you're closing in the (rare) case that it's not immediately obvious from looking at the code.

      There are places where the language forcing conventions are good. They are normally when the convention being enforced is one that is beneficial in good code written by good programmers. For instance, there's almost never a reason to indent code wrongly. Python's white-space enforcement works very nicely in real life. But enforcing things that make good code _harder_ to read is just madness, even when they might make bad code slightly easier to read.
      --
      rage, rage against the dying of the light
    34. Re:Literate programming... by fishbowl · · Score: 1

      >Would you rather work on code that is a sea of brackets?

      Brackets don't bother me as long as indentation is consistent. And if I have an editor
      that can make them consistent and can show me matches, (which I do) so much the better.

      Does not bother me at all, so yes, I have no more problem reading code that is a "sea of brackets" than I have with reading sentences in a book which are in a "sea of commas and periods."

      --
      -fb Everything not expressly forbidden is now mandatory.
    35. Re:Literate programming... by Nicolas+Roard · · Score: 4, Informative

      Literate Programming is not about making programming languages incredibly verbose; it's about *describing* your program in a normal, human way, by explaining it step by step and quoting bits and pieces of the program. Sounds ideal from a documentation point of view, right ? only that if that was all there was with Literate Programming, it would be a stupid idea, as documentation has a nasty habit to not follow up with code modification.

      The really cool idea with LP is that the code snippets you use in the documentation are then weaved together to generate the "real" code of your program. So a LP document is BOTH the documentation and the code. A code snippet can contains references ("include") to other code snippets, and you can adds stuff to an existing code snippet.

      Let me show you an example in simple (invented) syntax:

      {my program}

      {title}My super program{/title}

      Blablabla we'd need to have the code organized in the following loop:

      {main}:
          {for all inputs}:
              {filter inputs}
              {apply processing on the filtered inputs}
          {/}
      {/}

      The {for all inputs} consist in the following actions:

      {for all inputs}:
          some code
      {/}

      The filtering first remove all blue inputs:

      {filter inputs}:
        remove all blue inputs
      {/} ... and then remove all the green inputs:

      {filter inputs}+:
        remove all green inputs
      {/}

      etc.

      {/}

      The above is purely to illustrate the idea, the actual CWEB syntax is a bit different. But you can see how, starting with a single source document, you could generate both the code and the documentation of the code, and how you can introduce and explain your code gradually, explaining things in whichever way that makes the most sense (bottom-up, top-down, a mix of those..).

      In a way, Doxygen or JavaDoc have similar goals: put documentation and code together and generate documentation. But they take the problem in reverse from what literate programming propose; with Doxygen/JavaDoc, you create your program, put some little snippets of documentation, and you automatically generate a documentation of your code. With LP, you write your documentation describing your program and you generate the program.

      Those two approaches produce radically different results -- the "documentation" created by Doxygen/JavaDoc is more a "reference" kind of documentation, and does little to explain the reason of the program, the choice leading to the different functions or classes, or even something as important as explaining the relationships between classes. With some effort it's possible to have such doc system be the basis of nice documentation (Apple Cocoa documentation is great in that aspect for example), but 1/ this requires more work (Cocoa has descriptive documents in addition to the javadoc-like reference) 2/ it really only works well for stuff like libraries and frameworks.

      LP is great because the documentation is really meant for humans, not for computers. It's also great because by nature it will produces better documentation and better code. It's not so great as it poorly integrates with the way we do code nowadays, and it poorly integrates with OOP.

      But somehow I've always been thinking that there is a fundamentally good idea to explore there, just waiting for better tools/ide to exploit it :-P

      (also, the eponymous book from Knuth is a great read)

    36. Re:Literate programming... by Anonymous Coward · · Score: 0

      If you have blocks nested so deep that you can't match them visually, either improve your code layout or refactor some of it into a function. Deep nesting is a good sign that your code is too complicated and hard to understand, let alone debug. Abusing comments for something that any good code viewer could tell you (by means of color, highlighting of matching braces, folding, etc.) is wrong. Comments should explain code, not rephrase it.

    37. Re:Literate programming... by Anonymous Coward · · Score: 0

      there's

    38. Re:Literate programming... by MrSteveSD · · Score: 4, Insightful

      Not all programmers are uber-elite, and many are only slightly better than not being there at all.

      I don't think there's anything elite about writing short concise functions and breaking things up. The problem is when people first go into programming, they make these kinds of mistakes unless there are proper code reviews/training (things which often don't happen). When you are at university, the programs you write tend to be quite short and because of that, you don't realise how bad a programmer you actually are at that stage. It's only when you leap into the workplace and start writing a lot that your inadequacies become evident.

      To me, programming is a discipline requiring a fair bit of intelligence, but all to often companies hire programmers like they are just hiring shelf-stackers or something. I think there is a lot more professionalism in Open Source projects than in many software houses.
    39. Re:Literate programming... by bytesex · · Score: 1

      Eh.. this should be modded funny. Not interesting. It got me to almost splurt the keyboard full of port anyway.

      --
      Religion is what happens when nature strikes and groupthink goes wrong.
    40. Re:Literate programming... by Anonymous Coward · · Score: 0

      Idiot

    41. Re:Literate programming... by Anonymous Coward · · Score: 0

      This may qualify as a vacuous comment, but I promise I've never, ever orked a cow - please don't hit me!

    42. Re:Literate programming... by arivanov · · Score: 2, Funny

      No, it is a person who says moooooo when you ask him about trivial things like O(X) is his algorithm or what is the finite state machine he used to implement a protocol. Using a mutex-locked delete+insert instead of atomic replace in SQL is another popular mooooooo. It is usually done because the cretin cannot fatom the idea that a database op done correctly is atomic anyway so it needs no mutex and the database will NOT DEADLOCK the way an incompetently done mutex can.

      An so on...

      Very common species... The COW-WORKER...

      --
      Baker's Law: Misery no longer loves company. Nowadays it insists on it
      http://www.sigsegv.cx/
    43. Re:Literate programming... by Anonymous Coward · · Score: 0

      The thing I like about more verbose languages like VB.Net are that they force you to write out things that most good programmers would write out anyway as comments. At the end of a while loop, you write "End While". Most people using C++/Java/C# end up writing "} //end while" anyway, I can't work out if you're serious or not. Only a idiot would write that as a comment.

      Are you one of those people that writes

      i++; // increment i

      or is that "most people" too?
    44. Re:Literate programming... by lakeland · · Score: 1

      It's similar. Differences:

      Doxygen is newer.
      Doxygen defaults to code with an escape sequence for documentation, while literate programming defaults to documentation with an escape sequence for code. Think of it as a different 'attitude.

      If I type a one line 'program'

      10 print Hello World

      then in a doxygen world that will generate a program that prints hello world and no documentation.

      And in a literate programming world it will generate one line of documentation and no program.

      I.e. slightly different attitude.

      But that's about all really, pragmatically I view doxygen as a more up to date version of literate programming. I don't even have TeX installed on my main programming machine now.

    45. Re:Literate programming... by Anonymous Coward · · Score: 0
      I'd kill any colleague of mine who wrote such a vacuous comment. With a golf club, in front of its cow-orkers to drive the lesson home,

      Gee, I had no idea Biggus Dickus read slashdot. A true, two-fisted manager we should all emulate.

    46. Re:Literate programming... by Anonymous Coward · · Score: 0

      Using "MULTIPLYBY" instead of "*" isn't going to make your code easier to read.
      It's pretty obvious you didn't even RTFWikipediaA and only looked at the example, because that's the only source you could possibly have for thinking that literate programming had anything at all to do with replacing the * operator with "MULTIPLYBY". The Wikipedia example has basically fuck all to do with literate programming, so I've removed it. Now you'll have to actually RTFWA to see what it's about. It's not about shitty languages with interpreters written in QBasic.
    47. Re:Literate programming... by Anonymuous+Coward · · Score: 5, Funny
      why, have you ever read the source to the original, one-true unix bourne shell ?

      http://unix-archive.kalwun.de/PDP-11/Trees/V7/usr/src/cmd/sh/mac.h

    48. Re:Literate programming... by Anonymous Coward · · Score: 0

      Can you please post the video of that to youtube? There are some people I would like to show it too while beating them with golf clubs myself. I'll record that and post it to youtube. It can be like the infinite cat project.

      If you ever see a closing brace and you can't instantly realize what it's closing then your code should be fixed. Hell, if you can't understand what a totally uncommented function or method does after just a few moments of looking at it then your code probably needs fixing. If you have a function or method that is more than 50 lines long (except for the odd switch() that never ends and is blatenly clear) then your code probably needs fixing.

      Once in a while one does have to generate code that is confusing and hard to follow. When that happens condense the weirdness down as small as possible and put it in its own function/method and comment it. Endless, nested hairballs need to be avoided like the plague.

    49. Re:Literate programming... by Anomolous+Cowturd · · Score: 2, Informative

      Something like this might help: folding in vim. Emacs probably already has an 11-note chord that does this.

      --
      Software patents delenda est.
    50. Re:Literate programming... by digitig · · Score: 1

      So it's just as well Literate Programming doesn't do that, isn't it?

      I've spent a bit of time looking at Literate Programming, and think it's a good idea in theory, but all the tools are clunky and give ugly results, and I'm suspicious about its scalability and it's applicability to modern design approaches (and by "modern" I'm going back as far as the introduction of OO!). Programming small apps in C or Fortran 77, it would probably be a help, but I don't do that often enough to learn clunky tools. Tools that automatically parse specially formatted comments, such as are built in to C#, Java and Python, give some of the advantages of Literate Programming, and combined with conventional design give me all I need working at the scale where I think Literate Programming would apply.

      --
      Quidnam Latine loqui modo coepi?
    51. Re:Literate programming... by Anonymous Coward · · Score: 0

      Nerd rage at its finest. I can hear your huffed, asthmatic screeching as you slap someone harmlessly with a limp wrist.

    52. Re:Literate programming... by SL+Baur · · Score: 1

      Most people using C++/Java/C# end up writing "} //end while" anyway, Pray god I never have to work on code written by these fictitious "most people". Just let me handle their next performance review if such "code" leaks out.

      Comments like that are worthless and if they seem to make some sense, then there are worse problems with the code. I guess that does give it some dubious value, it says "An idiot wrote me, please code review me into oblivion".
    53. Re:Literate programming... by SL+Baur · · Score: 0, Troll

      I sometimes add comments like that if the brace is closing a deeply nested block Deeply nested blocks is a sure sign of crap code. Don't document crap code, rewrite it.
    54. Re:Literate programming... by Anonymous Coward · · Score: 0

      I actually had a professor who did this because his vision wasn't good enough to tell the difference between curly braces and parens. The lame part is that he wanted us to do it, but it toally messes up any kind of auto-indentation or any other useful thing an IDE might do.

    55. Re:Literate programming... by Temporal · · Score: 2, Funny

      What's a cow-orker? A misspelled description of somebody who irritates cows?
      Scott Adams once observed that a person you work with is technically called a "co-worker". The common misspelling "coworker" is actually a contraction of "cow orker", "ork" being an old Scottish slang term the meaning of which is not hard to guess.
    56. Re:Literate programming... by buildguy · · Score: 1

      It is usually done because the cretin cannot fatom the idea that a database op done correctly is atomic anyway so it needs no mutex Thank you, that actually solves a huge problem I have been having. Though the primary problem is that a construction engineer probably shouldn't be doing coding in the first place.
      --
      You think that's a building. Now this is a building.
    57. Re:Literate programming... by buildguy · · Score: 1

      What, this isn't standard management style? 1. Hire underlings. 2. Beat underlings into submission. 3. ... 4. Profit!

      --
      You think that's a building. Now this is a building.
    58. Re:Literate programming... by johannesg · · Score: 2, Insightful

      I worked with Captain Endif for a while. It gets very, very, VERY tiring at some point. Especially in cases like this:

      #define TRUE_VAL true
      #define FALSE_VAL false // if theVar is true

      if (theVar == TRUE_VAL) { // set theVar to false
          theVar = FALSE_VAL;
      } // end if

      (I made this up, but sadly it is not that far removed from actual examples...)

      I also worked with a guy (another one) who left a blank line between every two lines of code. ALWAYS.

      Anyway, if you are in the neighbourhood, feel free to come over to our office. If you forgot your golf club I'm sure we can rig something using parts from the paper cutter or something...

    59. Re:Literate programming... by mkcmkc · · Score: 4, Interesting

      Most people using C++/Java/C# end up writing "} //end while" anyway,
      Pray god I never have to work on code written by these fictitious "most people". Well, actually, once you've programmed in Python for a while, all of those spurious '}'s to close blocks really start to look as annoying and useless as "} //end while".
      --
      "Not an actor, but he plays one on TV."
    60. Re:Literate programming... by jacquesm · · Score: 2, Interesting

      if you feel like experimenting with literate programming try finding the 'leo' editor (written in python)

    61. Re:Literate programming... by 1729 · · Score: 2, Insightful

      I sometimes add comments like that if the brace is closing a deeply nested block Deeply nested blocks is a sure sign of crap code. Don't document crap code, rewrite it. A sure sign? Some code is necessarily complex. Conditional blocks inside nested loops are sometimes necessary for a logical, efficient, and human-readable implementation of an algorithm.

      Furthermore, I don't have the luxury of rewriting millions of lines of existing code. I document the parts I touch and I try not to make anything worse, but rewriting "crap code" is not always an option.
    62. Re:Literate programming... by SanityInAnarchy · · Score: 1

      Well, this is very, very rarely a problem for me, for the reasons others have said -- if I make a nesting construct that is more than, say, a single page long in my text editor, then I probably should be refactoring it.

      But if it's actually braces, just bounce back and forth with % in vim. Don't add comments because your text editor doesn't know how to find the other brace.

      --
      Don't thank God, thank a doctor!
    63. Re:Literate programming... by SanityInAnarchy · · Score: 1

      There is nothing uber or elite about breaking things out into smaller functions. It's a no-brainer -- as in, if you don't do it, you have no brain, and why are you programming in the first place?

      That said, use a better text editor -- one that understands the syntax of the language you're using. % in vim will bounce between opening and closing brackets. No need to pollute the source with a workaround for a bad text editor.

      --
      Don't thank God, thank a doctor!
    64. Re:Literate programming... by SanityInAnarchy · · Score: 1

      He should find an IDE that lets him automatically do that replacement.

      And you should find a better professor. Remember, they work for you, not the other way around.

      --
      Don't thank God, thank a doctor!
    65. Re:Literate programming... by SanityInAnarchy · · Score: 2, Insightful
      Yeah, that's the one thing I hate about Ruby now -- seeing the end of a file that looks like this:

      # for some reason, Slashdot won't indent the first line...
                end
              end
            end
          end
        end
      end
      Especially when the whole culture around things like Ruby on Rails is "Convention over Configuration" (thus, your code should always be indented properly anyway) and "Don't Repeat Yourself" (tons of 'end' statements isn't particularly DRY).

      I will say one thing, though: After haml, I never want to write any raw HTML, or any XML, by hand again. Ever.
      --
      Don't thank God, thank a doctor!
    66. Re:Literate programming... by Anonymous Coward · · Score: 0

      I put my cursor next to the { or } in emacs.

    67. Re:Literate programming... by Anonymous Coward · · Score: 0

      Wow. He managed to make C look like Perl?

      I have no problem with documenting code, but this is just horrendous. I have no doubt that this works well for Knuth, but we're not all geniuses who can write encyclopediac volumes on algorithms.

    68. Re:Literate programming... by Anonymous Coward · · Score: 0

      Most people using C++/Java/C# end up writing "} //end while" anyway,
      Pray god I never have to work on code written by these fictitious "most people".

      I'd kill any colleague of mine who wrote such a vacuous comment. With a golf club, in front of its cow-orkers to drive the lesson home, I sometimes add comments like that if the brace is closing a deeply nested block, but then the comment indicates which particular loop or block is ending. I had read somewhere , and I follow it, that if your code is more than 3 levels deep, its probably time to refactor and extract some methods.

      So following that, you never get 'deeply nested blocks'.

      In fact, I remember the source:
      "If you need more than 3 levels of indentation, you're screwed anyway, and should fix your program."
      http://en.wikiquote.org/wiki/Linus_Torvalds
    69. Re:Literate programming... by aastanna · · Score: 1

      Asssumptions make an ass out of u and mptions?

    70. Re:Literate programming... by ctzan · · Score: 1

      I use the '%' key in vi ;-)

    71. Re:Literate programming... by Tony+Hoyle · · Score: 1

      You've clearly never used SQL Server.. that deadlocks when the wind changes....

      That's a but contrived though.. someone would use a delete+insert rather than an update? Talk about making your life hard...

    72. Re:Literate programming... by syousef · · Score: 1

      Using "MULTIPLYBY" instead of "*" isn't going to make your code easier to read. ...especially when you see code snippets like if (blah) x *= 0; else x *= 1; in critical commerical code! I almost had an anuerism.

      --
      These posts express my own personal views, not those of my employer
    73. Re:Literate programming... by Tony+Hoyle · · Score: 1

      Depends on what you're doing. The best thing to do if you're doing anything complex is to start a transaction and work within that.. especialy if your changes span multiple tables and multiple SQL statements - a single statement is (supposed to be) atomic (not on all databases, alas, but for the major ones its true). Multiple statements aren't guaranteed to be so... which is why you have transactions to batch them into single operations.

      One thing you can't do in SQL is do 'if x doesn't exist then do y' statements - because someone might create x halfway through your operation (unless you can guarantee that you're the only user of the database). If you find yourself trying to do that then think about changing the design.

    74. Re:Literate programming... by TheRealJFM · · Score: 1

      The common misspelling "coworker" is actually a contraction of "cow orker", "ork" being an old Scottish slang term the meaning of which is not hard to guess.

      No, it isn't. I'm not familiar with the particular quote, but co-worker > coworker is a common grammatical contraction, such as "it's" (it belongs to) becoming its, or 'phone > phone, or a million other things.

      The Dictionary of the Scots Language and Oxford English Dictionary, probably the two best resources on the etymology of the language of England and Scotland have no record of that construction or word. I've definitely never heard it here.

      I know it's a joke, but these types of 'word histories' are usually bollocks that actually dilute our understanding of where words really come from.

      (Yes, I am an English major, and I live in Aberdeen, Scotland)

      --
      Joseph Farthing
      http://josephfarthing.com
    75. Re:Literate programming... by Tony+Hoyle · · Score: 1

      It really depends on the context. Some functions *must* be long because of what they do. Once you've nested more than two deep (and two deep is not that deep at all) you're in the risk of misunderstanding the code if it's complex enough - a memory jogger can save a few minutes of frustration when you're making modifications.

      Those are the exceptions though. I generally see such comments on preprocessor statements like #else, which can get lost very easily because they can be quite a distance from their siblings. A mismatch in a #endif can be an absolute git to debug and comments like that really help the maintainer.

    76. Re:Literate programming... by Tony+Hoyle · · Score: 1

      More annoying are the kind of people who think that there's some kind of famine of carriage returns.. so they write entire functions sometimes on one line, and *never* leave blank lines.

      They're also often the people who have the 'functions must be x lines or less' mantra drummed into them. They respond by compressing it into less lines :p

    77. Re:Literate programming... by Tony+Hoyle · · Score: 1

      If that's an example then it's put me off right away... the mix of code and documentation makes the code a lot harder to read (and for any experienced programmer the code itself forms part of the documentation and should be readable.. that isn't).

    78. Re:Literate programming... by coopaq · · Score: 1
      if ( isIHasToWorkOnCodeByTheseFictitiousMostPeople == true) ) {

      return "I'd kill any colleague of mine who wrote such a vacuous comment.";

      } // vacuous="emptied of or lacking content"

    79. Re:Literate programming... by fyrie · · Score: 1

      Visual Studio has had that for awhile now, so I don't come across the //end if type comments anymore. Several years ago it was a common practice though.

    80. Re:Literate programming... by squidinkcalligraphy · · Score: 1

      From what I've seen (particularly of CWEB), literate programming doesn't change the programming language itself, it just adds a TeX style markup to the comments so that detailed (and nicely typeset) documentation can be generated from the source code. Take a look at some of Knuth's CWEB code, such as his implementation of Adventure:

      http://sunburn.stanford.edu/~knuth/programs/advent.w.gz

      It appears to be ordinary C once the CWEB documentation is stripped out. Actually, it's the other way around: rather than adding documentation to the code, the idea of literate programming is that you add code to the documentation. So your code is dispersed in chunks throughout the documentation of the project. A tool (pre-processor if you will) then collects the chunks of code and weaves them into a 'normal' source file/tree.
      --
      "I think it would be a good idea" Gandhi, on Western Civilisation
    81. Re:Literate programming... by spuzzzzzzz · · Score: 1

      You aren't actually supposed to read the code that he pointed to. You're supposed to run it through a processor that will generate a beautifully typeset pdf file with the documentation laid out logically and code examples embedded. The workflow is somewhat different from the workflow that many programmers are used to, but it is similar to working in (La)TeX, if you have done that.

      --

      Don't you hate meta-sigs?
    82. Re:Literate programming... by GalacticCmdr · · Score: 1

      Wow, humor just seems to fly right over you without even pausing to take a dump on your head.

      --
      Programming: Its not just a job - its an indenture.
    83. Re:Literate programming... by multi+io · · Score: 1
      I think you ought to refactor this to make it less redundant:

      #define Begin {
      #define End }

      #define While
      #define For
      ...

    84. Re:Literate programming... by nuzak · · Score: 4, Funny

      I have actually seen code like this:


              } // end while-loop
      } // end if-loop


      You read that right. if-loop.

      --
      Done with slashdot, done with nerds, getting a life.
    85. Re:Literate programming... by nuzak · · Score: 1

      Go look up the etymology of "whoosh".

      --
      Done with slashdot, done with nerds, getting a life.
    86. Re:Literate programming... by FishWithAHammer · · Score: 1

      Twelve.

      --
      "You can either have software quality or you can have pointer arithmetic, but you cannot have both at the same time."
    87. Re:Literate programming... by CastrTroy · · Score: 1

      I remember that a certain database, Oracle I think, supported an InsertOrUpdate command which would insert a record, or if a record with the same primary key already existed would update the current record. When you think about it, it really is a useful command. You don't care if the record already exists or not, you just want it to exist with the values you have passed it. It doesn't matter if it was there before or not. I do know it wasn't MS SQL Server though, as that was the database I was working with at the time.

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    88. Re:Literate programming... by HiThere · · Score: 1

      There are many times when it's quite useful to say which loop is being closed. *Very* many. This doesn't mean that it's always reasonable, or even usually so. But there are times when I'll even so comment a 4 line loop.

      Code isn't static. You can't depend on it not changing. If something just says "}", then an inserted code change above it, which happens to have forgotten the terminating brace, can send you on an extended chase through the code.

      Breaking small loops out as functions is, perhaps, worse than not commenting at all. It's on the near order of impossible to come up with distinctive and meaningful names for an, essentially, unboundedly large number of functions. I've not only seen code like that, I've written it. Then I went back to try to maintain it. Never again! It *is* as bad as spaghetti code. Often worse. (If you can keep all of your branches within 50 lines of their labels, and you have 3 colors of pen and some scotch tape, you can trace the flow of spaghetti code. I used to program in Fortran IV, so I can guarantee that this is true. [There were techniques that couldn't be handled so simply, but spaghetti code wasn't one of them, though it could be quite a logical puzzle to figure out what it was doing.])

      --

      I think we've pushed this "anyone can grow up to be president" thing too far.
    89. Re:Literate programming... by Ecuador · · Score: 1

      Eh.. this should be modded funny. Not interesting. It got me to almost... oh, wait...

      --
      Violence is the last refuge of the incompetent. Polar Scope Align for iOS
    90. Re:Literate programming... by wrook · · Score: 1

      Rather than saying that programming is a discipline requiring a fair bit of intelligence, I tend to think that *good* programming requires a fair bit of sensitivity. Any Joe Blow can get code to work. Usually they make a hash of it, but it usually works (mostly).

      To write good code you need to make appropriate choices. This is difficult. Sometimes the smallest inappropriate choice can lead to mountains of crappy code. So constant vigilance, refinement and "good taste" are required.

      The problem with saying that programming requires intelligence is that it implies that "programming talent" is something your are born with and that you can't improve yourself. Either you have it or you don't. I'm aware that this point of view is prevalent, but I don't agree.

      I believe that a normally intelligent person, with considerable effort, practice and guidance can learn to make appropriate choices -- at least enough to write what most people consider "good code". Perhaps they won't be able to write parts of the code that require complicated math, etc, but that is almost always a very small part of any project.

      I feel the reason we have so few good programmers is not for lack of intelligence, but for lack of good instruction and training. Almost all jobs are "sink or swim". So the naturally good barely survive and the not so good hide their work. This is complicated by the fact that the vast majority of Universities (which train most of the programmers, unfortunately) do not have experienced programmers on staff. So at no point in their careers do most programmers get anything like appropriate training.

    91. Re:Literate programming... by SL+Baur · · Score: 1

      Furthermore, I don't have the luxury of rewriting millions of lines of existing code. I document the parts I touch and I try not to make anything worse, but rewriting "crap code" is not always an option. I'm fully aware of that. I've been doing software development for a very long time and I was responsible for XEmacs for a long time and Emacs source code is without a doubt the poorest code (style and maintenance wise) that I've ever had to deal with. And as in your case, rewriting the worst code (the multi thousand line functions with 5 or 6 levels of nested ifs) is still not an option.

      For you and the idiot who modded me as "troll", I suggest reading the timeless "Elements of Programming Style", Kernighan and Plauger as that quote was more or less lifted from there.

      Full tab indentation has the side effect of forcing deeply nested code off the right side of the screen. This is one of the reasons that some of the oldest operating system code (the BSDs and Linux) continue to attract new programmers.

      I also suggest Brook's Mythical Man Month. He has a classic example of horrible code including ascii art arrows pointing to the destination of gotos (what's funny is that he uses that as an example of _good_ style).

    92. Re:Literate programming... by TapeCutter · · Score: 1

      "Using a mutex-locked delete+insert instead of atomic replace in SQL is another popular mooooooo."

      If your know your SQL will NEVER be used on MSSQL then fine, but understand that 'replace' is a luxury some of us don't have and your bull-ying cow-orkers doesn't help.

      --
      And did you exchange a walk on part in the war for a lead role in a cage? - Pink Floyd.
    93. Re:Literate programming... by Anonymous Coward · · Score: 0

      You could always just use a text editor (Vi, Emacs) or an IDE (Visual Studio, Eclipse, etc), which highlights matching brackets.

      No need for a meaningless comment.

    94. Re:Literate programming... by God_Retired · · Score: 1

      And be yet someone else that I'd end up supporting in prison. Sigh.

    95. Re:Literate programming... by spectecjr · · Score: 1

      The TRUE_VAL/FALSE_VAL can be useful when you've got to write cross-platform code. Although why you wouldn't use TRUE and FALSE beats me.

      The problems happen when someone cargo-cult copies the behavior of another program without understanding why it was done.

      --
      Coming soon - pyrogyra
    96. Re:Literate programming... by spectecjr · · Score: 1

      It also doesn't help that most programmers are rewarded on their output on a by-the-pound basis, rather than how well their code does what it's supposed to do.

      I've seen programmers regularly get beaten up on by their bosses because it takes them 3 times as long to write the same code that Bugsy in the other cube wrote. The difference being that Bugsy's version has 40 bugs in it, which all tend to hit right around ship time, and Joe's code has 1 bug in it, when someone tried to get it to do something it was never intended for.

      --
      Coming soon - pyrogyra
    97. Re:Literate programming... by J.R.+Random · · Score: 1

      Who are the idiots who marked that comment insightful? Literate programming has nothing to do with making the code verbose. It does have a lot to do with having the discipline to explain what you're doing, which is loathsome to most programmers, and no doubt explains the unpopularity of literate programming.

    98. Re:Literate programming... by mrchaotica · · Score: 1

      such as "it's" (it belongs to) becoming its

      Since when did "it's" not mean "it is?!" And since when did "its" not mean "[the succeeding thing] belongs to it" or "[the succeeding thing] of it" (i.e., the opposite of your definition)?

      When it comes to grammar, it's [it is] a damn shame that you don't understand its subtleties [subtleties of grammar, not grammar of subtleties] nearly as well as you think you do!

      (No, I'm not an English major.)

      By the way: cite.

      --

      "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

    99. Re:Literate programming... by Mr.+Slippery · · Score: 1

      A better way to handle that is to turn the loop body into a function or group of functions.

      Only if the function, or group of functions, represent natural borders on encapsulation. People who create arbitrary subroutines out of some misguided notion that a a function/procedure/method should not be longer than N lines, don't understand the basic concept of encapsulation.

      --
      Tom Swiss | the infamous tms | my blog
      You cannot wash away blood with blood
    100. Re:Literate programming... by MrSteveSD · · Score: 1

      Rather than saying that programming is a discipline requiring a fair bit of intelligence, I tend to think that *good* programming requires a fair bit of sensitivity.

      I'd rather have intelligent people working for me than sensitive people.

      Any Joe Blow can get code to work. Usually they make a hash of it, but it usually works (mostly).

      Yeah and then you have to pick up the pieces. That 500 line monster function chews up hours of another programmers time figuring out what it does and then rewriting it. If the people who were in charge of software companies were in charge of building houses, they would stop employing skilled craftsmen and instead grab anyone of the street. Given the task of providing a way into the house, the "builders" would just smash a hole in the wall. It would work, but it's awful and someone else has to fix it.

      The problem with saying that programming requires intelligence is that it implies that "programming talent" is something your are born with and that you can't improve yourself.

      Whatever your level of intelligence, you can certainly get better at programming, yes. It's still requires intelligence though, and frankly the more, the better. I think greater intelligence helps in identifying the generalities and patterns that tend to pop up in programming. Seeing the bigger picture can save a company a lot of money.

      I feel the reason we have so few good programmers is not for lack of intelligence, but for lack of good instruction and training. Almost all jobs are "sink or swim". So the naturally good barely survive and the not so good hide their work.

      That's true, particularly in smaller software houses. I never received any on the job training when I first started. The other programmers weren't exactly Yoda figures, so I had to do a lot of reading and I went through several leaps of skill as I learned new concepts (e.g. Design Patterns, Test Driven software). A few years into the job we had some new people come in and I made sure I passed my skills onto them as quickly as possible. I remembered all the misconceptions and problems I had when I started and sure enough, they pretty much matched the issues the new guys had.

      This is complicated by the fact that the vast majority of Universities (which train most of the programmers, unfortunately) do not have experienced programmers on staff. So at no point in their careers do most programmers get anything like appropriate training.

      Well I did physics, and we weren't really taught how to program. We just did it and solved some Physics problems in Fortran. Most of us went through the whole of university writing programs (on and off) without even knowing the difference between passing by value or by reference. In Computer Science degrees, I trust things are better, but even then, the code they write is probably far removed from the shear volume and inter-relational complexity of business software.

      The other problem is that by the time people become really skilled, they feel like it's time to move on.
    101. Re:Literate programming... by sholden · · Score: 1

      You read raw tex files too? The rest of us will run it through the processor and read the nicely formatted output.

    102. Re:Literate programming... by Anonymous Coward · · Score: 0

      How different is this from Pydoc/Epydoc?

    103. Re:Literate programming... by johannesg · · Score: 1

      The TRUE_VAL/FALSE_VAL can be useful when you've got to write cross-platform code. Although why you wouldn't use TRUE and FALSE beats me. Just use "true" and "false" already! We have a standard for this sort of thing, it is called "ISO/IEC 14882:1998". It isn't politics, there is simply no need to expect things like the value of "true" to change ;-)

      Would you do this?

      #define IF if // to defend against possible future changes in the "if" keyword

      IF (...) {

      }

      Because I wouldn't. Not that I haven't encountered it in the wild :-(

      The problems happen when someone cargo-cult copies the behavior of another program without understanding why it was done. Here's the weird thing: the person who did this had taught himself a certain pattern, and felt comfortable always working within that pattern. He wasn't actually a bad programmer, he had just picked up some weird habits that made his code look as if it were written by a raving moron.

      As far as I can tell, all good programmers teach themselves a set of useful patterns and stick with them. The good thing is that if you review your own code, it is easy to recognize places that don't fit the pattern and thus merit extra consideration. And of course the patterns are easy to write as well, since you never have to think about it.

      This is also, I suspect, why things like bracket placement are such a cause for holy wars: it breaks the pattern and therefore makes all the code using the 'wrong' style look like it is highly suspicious. When you hear those alarm bells all the time, of course you will think that code must be very bad - and it will be because of the brackets.

      I also suspect that people who state they don't care (about things like bracket placement) don't have any built-in patterns, and tend to think of unique solutions for every little problem. In my experience that usually indicates they are pretty bad programmers, and their code will be messy and unworkable.

    104. Re:Literate programming... by johannesg · · Score: 1

      More annoying are the kind of people who think that there's some kind of famine of carriage returns.. so they write entire functions sometimes on one line, and *never* leave blank lines. Don't be too sure you will like

      the alternative. Because it really isn't

      very pretty. In fact it hurts the eyes.

      It also makes it very hard to recognize

      where the *actual* boundaries between

      things are. Notice how the normal flow

      of the text is lost here? And how you

      completely missed the fact that there are

      two paragraphs? Now imagine this happening on

      30,000 lines of code that you have to maintain...

      They're also often the people who have the 'functions must be x lines or less' mantra drummed into them. They respond by compressing it into less lines :p Yeah, well you know how it is. Just about any programmer (good or bad) can subvert *any* coding standard into utter unreadability.

      Sometimes by doing nothing more than just following it, of course...

    105. Re:Literate programming... by Fulcrum+of+Evil · · Score: 1

      Well I did physics, and we weren't really taught how to program. We just did it and solved some Physics problems in Fortran. Most of us went through the whole of university writing programs (on and off) without even knowing the difference between passing by value or by reference. In Computer Science degrees, I trust things are better, but even then, the code they write is probably far removed from the shear volume and inter-relational complexity of business software.

      The other problem is that by the time people become really skilled, they feel like it's time to move on. The thing here is that properly engineered code is easier to maintain. In your case, partnering with an engineer would help; you write the first version and make it go, then you and the engineer build test cases that exercise its behavior. After that, the engineer refactors your code and makes it pretty, then consults on changes in a pair sort of situation. Something like 2:1 physicists to engineers should work reasonably well. All you really need to do is avoid piles of global variables named aa..az.
      --
      "We returned the General to El Salvador, or maybe Guatemala, it's difficult to tell from 10,000 feet"
    106. Re:Literate programming... by Fulcrum+of+Evil · · Score: 1

      Well, actually, once you've programmed in Python for a while, all of those spurious '}'s to close blocks really start to look as annoying and useless as "} //end while". I hate 'indentation is scope'. If your editor disagrees with your runtime on how many spaces are in a tab (or if it changes), your code breaks.
      --
      "We returned the General to El Salvador, or maybe Guatemala, it's difficult to tell from 10,000 feet"
    107. Re:Literate programming... by arivanov · · Score: 1

      You can simulate it in a trigger the way pre-8i Oracle had to be done. You lose speed on the trigger, but you gain it on having less locking in the app.

      --
      Baker's Law: Misery no longer loves company. Nowadays it insists on it
      http://www.sigsegv.cx/
    108. Re:Literate programming... by Anonymous Coward · · Score: 0

      Since when did "it's" not mean "it is?!" And since when did "its" not mean "[the succeeding thing] belongs to it" or "[the succeeding thing] of it" (i.e., the opposite of your definition)?

      Only since grammar and spelling stopped being a movable feast for the educated classes (so, the last few hundred years).

    109. Re:Literate programming... by harlows_monkeys · · Score: 1

      Excuse my ignorance, but please explain how this this different (or superior) to doxygen or any of the many systems that do just this

      Those systems don't rearrange code. You give them program files containing code and documents, and they pull the documentation for humans out of that. The program files, though, go straight to the compiler. Thus, the files you write (the program files), have to be organized the way the compiler wants them to be organized, and that generally imposes an organization on the documentation that is pulled from the program files.

      In literate programming systems, the files you write are NOT passed through to the compiler. The tools pull from your input files the code for the compiler, and the documentation for humans. Your documentation is no longer constrained by the limits of the compiler.

      This is important because the best order for presenting code to a human is often different from the best order to present that code to a compiler. Literate programming toolsets can deal with this. Similarly, some things that have to (or should be for efficiency) inline code in the compiler input might make more sense in documentation if they were more like subroutines. Literate programming tools can deal with that, by essentially having a macro mechanism.

    110. Re:Literate programming... by TheRaven64 · · Score: 1

      Yup. It really sucks being able to jump to the end of a block with a single keystroke in your editor (you are using an editor which matches brackets, right?) and so using whitespace is much more sensible.

      --
      I am TheRaven on Soylent News
    111. Re:Literate programming... by TapeCutter · · Score: 1

      Actually I don't write a lot of SQL nowadays and what I do write is mainly aimed at sqlite. My first thought was a transaction around the delete-insert pair, not sure how well that compares to a trigger under a heavy load. Still, I like the trigger idea because it solves the problem for any app that uses the database (provided you always want the insert to do a replace).

      --
      And did you exchange a walk on part in the war for a lead role in a cage? - Pink Floyd.
    112. Re:Literate programming... by spectecjr · · Score: 1

      I wouldn't redefine IF, but I'd certainly consider redefining bool/true/false.

      Mainly because sizeof(bool) is compiler dependent, and bool values are coerced to be 1 or 0, which can be a performance hit. Not a strong reason, but certainly a reason. (And why I never use bool as a type in data which has to be serialized and read on other platforms).

      Speaking of which... for gawd's sake someone add something to C++ to allow reflection on static data types. I don't care what mechanism it has to work by, but if I had a dollar for every time I've wanted to be able to take something like this:

      struct s
      {
        int a;
        bool b;
        SomeClass c;
        MyPointer* p;
      } ... and get:
      The offset of all the members.
      The size of all the members.
      A list of all the members.
      Information about the padding between members... ... I mean, come on... I don't want to have to write code that cracks open the debug info in an elf or a pdb to get this information. Especially as that's likely to change from compiler version to compiler version.

      (Yes, I know offset_of, alignof, sizeof, etc can get my that information... but it can't get it for any arbitrary class without me writing much more code).

      Si

      --
      Coming soon - pyrogyra
    113. Re:Literate programming... by TheRealJFM · · Score: 1

      Since when did "it's" not mean "it is?!" As recently as the US constitution:

      No State shall, without the Consent of the Congress, lay any Imposts or Duties on Imports or Exports, except what may be absolutely necessary for executing it's inspection Laws: and the net Produce of all Duties and Imposts, laid by any State on Imports or Exports, shall be for the Use of the Treasury of the United States; and all such Laws shall be subject to the Revision and Controul of the Congress.

      (Emphasis mine)

      It's was an invention in the 16th century in England and that spelling lasted until the 19th century

      (Source: OED, http://dictionary.oed.com/cgi/entry/50122404)

      --
      Joseph Farthing
      http://josephfarthing.com
    114. Re:Literate programming... by remmelt · · Score: 1

      You sound like an episode of 24.

    115. Re:Literate programming... by rasteroid · · Score: 1
      I can see how this approach of embedding the source code in a "rich" document can be advantageous. Much of the code I write involves numerical/mathematical algorithms that might implement several formulae. In-code documentation (the kind that we are all used to) is essentially plaintext, so it becomes very difficult to describe mathematical formulae that require special symbols or superscripts/subscripts etc. With a "rich" document, I would gain the power of expressing the mathematical logic natively as well as using simple text-formatting like boldface, italics, etc. For example, if I am calculating the standard deviation for a set of data and my formula is unique (which it isn't in the example below) so I want to include the formula with my in-code plaintext documentation, it would look like:

      // Calculate standard deviation using "unique" formula:
      // stddev = sqrt((sum of (x_i - x_avg)^2 from 1 to N) / N)
      ...
      The plaintext comment becomes just as "difficult" to read than the actual code itself. So embedding source code within a "rich" document would make it easier to include mathematical expressions in the documentation with the actual code that implements it right afterwards.

      However I do acknowledge that it is very unlikely that I will write an extensive expose of my algorithms/code like that available on sample literate programming websites (unless I am publishing a paper or book). I guess the difference is whether a piece of code is meant to be a discourse where every detail needs explaining, or whether I can assume that anyone with interest in my source code would "easily" be able to understand most of the undocumented steps. So if I use a well known standard deviation formula, I would simply omit the second line of the documentation above, but if I switch to a unique formula then I would include the second line.
    116. Re:Literate programming... by DuckDodgers · · Score: 1

      I feel the reason we have so few good programmers is not for lack of intelligence, but for lack of good instruction and training. Almost all jobs are "sink or swim". So the naturally good barely survive and the not so good hide their work. There's two other problems you're missing. First, because training is so poor, lots of developers out there, including senior developers, have gaps in their knowledge. They may be too embarassed to try to teach a new hire for fear of looking stupid.

      Second, knowing how to design, write, and document decent code and knowing how to teach someone else how to do those things are two separate skills. Even if someone else in the company is delegated to teach the new hires, knows their stuff, and wants to help, it does not mean they can effectively pass on what they know.

      This is complicated by the fact that the vast majority of Universities (which train most of the programmers, unfortunately) do not have experienced programmers on staff. So at no point in their careers do most programmers get anything like appropriate training. I think that speaks to my second point above. Some Computer Science professors are brilliant instructors. Some are brilliant software developers. Few that I have encountered are both.

      So one passes on concepts and basic knowledge very well but can't teach you what you need to know to be great. The other knows everything you need, but can't pass anything on.

      I considered getting my PhD in Computer Science and becoming a professor, but I don't think I have what it takes to teach the stuff either. (Hopefully I'm a good developer already. But who knows.)
    117. Re:Literate programming... by obarel · · Score: 1

      In other words, you say that crap code should be rewritten, yet you acknowledge that sometimes crap code cannot be rewritten (unless you're willing to invest a lot of time, probably measured in years).

      I have the utmost respect for anyone who maintained XEmacs, but don't you find the above a bit contradictory?

      I've had the pleasure of working on code that had a basic binary search repeated about fifteen times. I still didn't rewrite it, simply because I had better things to do with my time. Like adding features that were requested by my boss (the one who wrote that code).

      Code is only code - it has to be useful, it has to be maintainable, it had to be readable, and sometimes in that order.

      By the way, that company has now folded, and not because the code base had the same function fifteen times (or because it was riddled with #ifs, or because it was divided into the wrong modules, or because every structure had a back pointer to the structure that contained it, or because there were no unit tests, or because the most complex data structure was the array which was the wrong choice for the data, or ...)

    118. Re:Literate programming... by blincoln · · Score: 1

      Full tab indentation has the side effect of forcing deeply nested code off the right side of the screen.

      That seems to me like less of a concern now that we're well beyond needing an expansion card to get 80-column text instead of 40 on screen.

      --
      "...always new atoms but always doing the same dance, remembering what the dance was yesterday." -Richard Feynman
    119. Re:Literate programming... by Anonymous Coward · · Score: 0

      Nah... it's just the darn Yanks can't spell ;).

    120. Re:Literate programming... by MrSteveSD · · Score: 1

      In your case, partnering with an engineer would help

      When I first started out (years back), partnering with an experienced programmer would have helped, yes. Unfortunately everyone at the company was pretty clueless at the time. I taught myself over several years.

      All you really need to do is avoid piles of global variables named aa..az.

      Well, you need to do more than that. Globals themselves are to be avoided if possible since they potentially couple all of the code together in a horrible spaghetti mess. The company I worked for got some expensive contractors in to to some work once and they added a global variable called "i" into the code. Globals are bad enough, but naming one "i"? I still laugh when I think about it.
    121. Re:Literate programming... by Fulcrum+of+Evil · · Score: 1

      yeah, I'm simplifying. the basic idea is that a physicist need not be a perfect coder, but avoiding certain egregious habits will help the refactor stage go faster and work better.

      i? Surely your company did code reviews?

      --
      "We returned the General to El Salvador, or maybe Guatemala, it's difficult to tell from 10,000 feet"
    122. Re:Literate programming... by MrSteveSD · · Score: 1

      yeah, I'm simplifying. the basic idea is that a physicist need not be a perfect coder, but avoiding certain egregious habits will help the refactor stage go faster and work better.

      Well, I suppose I stopped being a Physicist when I went into software. People coming from University should be under no illusions that they can actually code in a business environment straight away.

      i? Surely your company did code reviews?

      Not at that stage. There was a lack of management from the top down. No-one was formally placed in charge. Eventually I became senior programmer and I changed everything, with code reviews etc. Even then, time pressure and multiple projects made it impractical to review all code. I pushed to have test driven development, but the extra time required resulted in my being overruled. It was all pretty shoddy really, but lots of small software houses are like that. Even some of the bigger ones too.
    123. Re:Literate programming... by masterzora · · Score: 1

      Next I bet you're going to complain about Adams' etymology for analysis: it comes from "anal" meaning what you think it means and "ysys" meaning "to pull from".

      --
      Remember, open source is free as in speech, not free as in bear.
    124. Re:Literate programming... by pablodiazgutierrez · · Score: 1

      I know laugh about it, but I remember in my Intro to Programming class, which was the first one taught in C, the teacher advised us to #define BEGIN { and END } so that the code looked more like Pascal (the previous language of choice at that institution).

    125. Re:Literate programming... by Fulcrum+of+Evil · · Score: 1

      hehe, you should see the stuff where I work. We've started in on proper quality, but it's only been a couple of years.

      --
      "We returned the General to El Salvador, or maybe Guatemala, it's difficult to tell from 10,000 feet"
    126. Re:Literate programming... by Just+Some+Guy · · Score: 1

      (Don't tell anyone, but Emacs's python.el has keybinding to move to the beginning or end of the current block.)

      --
      Dewey, what part of this looks like authorities should be involved?
    127. Re:Literate programming... by stocke2 · · Score: 1

      now thats one of the funniest things I have ever heard, I bet they did alot of tracking down problems just to find that the reason the global kept changing was some loops.....not to mention when loops started interfering with each other

      --
      A Smith & Wesson beats four aces -- Murphy's Law of Poker
    128. Re:Literate programming... by MrSteveSD · · Score: 1

      Well we didn't notice it at first because the scope rules of the language (and I guess most languages) were such that a locally declared "i" would override the global. It was a stupendously dumb thing to do though. I've seen all kinds of horrors. When I first joined the company, someone had coded a form using the user interface as the storage mechanism. So instead of having a variable called "percentage", they would just use the label on the form as the variable itself and the code would actually write to it and read from it during calculations.

    129. Re:Literate programming... by tomtomtom777 · · Score: 1

      Your comment and some other comments here are NOT about literate programming. There is NO reason literate programs should use more words or longer words then normal programs.

      The only thing literate programming is about, is the reversal of comments and code. Instead commenting your code, you write comments and write your code in between; as if you're writing a book.

      It might be a fallen out of fashion for C-programs, but for programs in functional languages it is very common and extremely useful

      A HASKELL program is usually very compact and the surrounding comments are more important then the actual lines of code. This makes writing the program as a book is a very good practice.

    130. Re:Literate programming... by Omnifarious · · Score: 1

      I frequently use a comment like that at the end of namespaces. Namespaces by their very nature are blocks that encompass many lines. And I don't indent code inside of namespaces. So, while I generally agree with you, I think there are specific cases in which that sort of comment is pretty helpful.

    131. Re:Literate programming... by Omnifarious · · Score: 1

      I hate 'indentation is scope'. If your editor disagrees with your runtime on how many spaces are in a tab (or if it changes), your code breaks.

      Stop using tabs for indentation. Please, for all of our sakes, just don't do it. Every single person I know who uses tabs for indentation sets 4 space tabs. Every single tool in existence that's not a programmers editor sets 8 space tabs (except for vi and emacs which also use 8 space tabs). This means that to anybody who doesn't go through and obsessively change any use of a random tool to have 4 space tabs insead of 8, your code looks horribly ugly and is much harder to understand.

      So just stop using tabs for indentation. Ignore the seductive sirens call of setting them to 4 spaces in your editor. Your editor is wrong. You are wrong if you use tabs for indentation. Just stop doing it please.

    132. Re:Literate programming... by Charbox · · Score: 1

      Check out the use of it. It looks like a language better than C, except for the caps. But the caps even set off the syntax nicely.

    133. Re:Literate programming... by Charbox · · Score: 2, Funny

      Nobody who modded this funny ever worked with a foreign language programming team.

    134. Re:Literate programming... by deanlandolt · · Score: 1

      I think there is a lot more professionalism in Open Source projects than in many software houses. This is a big part of what Paul Graham calls The Python Paradox. And before I get flamed: no, it's not limited to Python, just embodied by it. It's more about how the passion that fuels a hobbyist hacker -- the kind you'll often find spending their spare time in foss projects -- is what makes a good software developer.
    135. Re:Literate programming... by DragonWriter · · Score: 1

      Especially when the whole culture around things like Ruby on Rails is "Convention over Configuration" (thus, your code should always be indented properly anyway)


      "Convention over configuration" has nothing to do with indentation or other code format issues, it has to do with the balance between explicit setup (configuration) and implicit setup (convention).

      and "Don't Repeat Yourself" (tons of 'end' statements isn't particularly DRY).


      DRY has only, at most, a tangential relationship to "end" statements: its about repeating vs. reusing code, not about not repeating keywords.

      The biggest problem a cascade of end statements is likely to be symptomatic of is using methods that are too big. This often goes along with violations of DRY (because if you are using big methods, there's a fair chance that you haven't factored bits out that are used in different places), but its not necessarily the same thing.

      (Of course, it can also be a result of using deeply nested classes/modules, since they use a similar block structure to methods and code blocks.)
    136. Re:Literate programming... by Anonymous Coward · · Score: 0

      I know it's a joke, but... ...you nonetheless felt compelled to tell us all that "orker" isn't really a Scottish word, lest a large number of Slashdot readers be confused? If someone quoted the old Dave Barry line about "politics" being derived from "poly," meaning "many," and "ticks," meaning "blood-sucking insects," you'd have popped up with an arch explanation of how that really isn't the correct etymology, wouldn't you?

      Tune in next week, when TheRealJFM sternly informs us that Outback Steakhouse isn't really serving Australian food!

    137. Re:Literate programming... by strstrep · · Score: 1

      The solution is to use vi. % operation for the win!

    138. Re:Literate programming... by SanityInAnarchy · · Score: 1

      "Convention over configuration" has nothing to do with indentation or other code format issues, it has to do with the balance between explicit setup (configuration) and implicit setup (convention). As a specific concept, maybe. But it absolutely does fit -- more generally, it is about explicitness vs implicitness. 99% of the time, if something's indented, I want it scoped that way -- I wouldn't mind typing explicit begin/end blocks or brackets for the other 1% of the time.

      DRY has only, at most, a tangential relationship to "end" statements: its about repeating vs. reusing code, not about not repeating keywords. Again, you're scoping this smaller than it has to be. Even in Rails, a lot of the applications of DRY are, again, about explicitness vs implicitness -- for example, one place Rails is not entirely DRY is validations, many of which could be inferred from the schema. By providing both a column constraint (NOT NULL, say) and an ActiveRecord constraint (validates_uniqueness_of), Rails is forcing you to repeat yourself. (Unless you're using, say, the schema_validations plugin.)

      So, my attitude here is, I follow strict coding conventions already -- I already use indentation to indicate scope, because that's easy for the human eye to pick up on. Why should I have to repeat myself with end statements?

      More generally, when asked why he chose Ruby, DHH said that it was the language in which he could write "the most beautiful code". End statements are not beautiful to me. Yes, it's subjective.

      One more thing: I haven't done a lot of Python code, but I have done a lot of haml and sass lately. It's interesting that the same people who love haml never breathe a word about Ruby's end statements -- even when said end statements are actually abstracted away by haml!
      --
      Don't thank God, thank a doctor!
    139. Re:Literate programming... by DragonWriter · · Score: 1

      As a specific concept, maybe. But it absolutely does fit -- more generally, it is about explicitness vs implicitness. 99% of the time, if something's indented, I want it scoped that way -- I wouldn't mind typing explicit begin/end blocks or brackets for the other 1% of the time.


      Of course, if that's your preference, you can always use Python; there are, IMO, boundaries to the utility of implicit-over-explicit (Rails, itself, sometimes seems to cross over some of them; Python's indentation-based-scoping is far over the line, IMO. [note: I like Python, generally, aside from the handling of indentation.])

      "Convention over configuration" is mostly, IMO, a good idea in the range where Rails applies it; OTOH, like most short maxims, if you generalize it further and make it a quasi-religious precept, it does more harm than good.

      Even in Rails, a lot of the applications of DRY are, again, about explicitness vs implicitness -- for example, one place Rails is not entirely DRY is validations, many of which could be inferred from the schema. By providing both a column constraint (NOT NULL, say) and an ActiveRecord constraint (validates_uniqueness_of), Rails is forcing you to repeat yourself. (Unless you're using, say, the schema_validations plugin.)


      Saying something explicitly twice vs. saying it explicitly only once is not really "explicitness vs. implicitness". Its repeating vs. not repeating, as the name DRY suggests.

      More generally, when asked why he chose Ruby, DHH said that it was the language in which he could write "the most beautiful code". End statements are not beautiful to me. Yes, it's subjective.


      To me, the programming constructs that create large cascades of end statements are generally not beautiful (they are, sometimes, the expeditious way to acheive a particular task; some tasks don't have elegant expression), whether or not you have explicit end statements. The problem, to me, isn't with the language (or, rather, not with the use of explicit scope in the language; its often with the range of substantive constructs available.)

      One more thing: I haven't done a lot of Python code, but I have done a lot of haml and sass lately. It's interesting that the same people who love haml never breathe a word about Ruby's end statements -- even when said end statements are actually abstracted away by haml!


      Yeah, most people aren't fanatical extremists; they see that some things can be useful in one area and counterproductive in another.

    140. Re:Literate programming... by SanityInAnarchy · · Score: 1

      Saying something explicitly twice vs. saying it explicitly only once is not really "explicitness vs. implicitness". Its repeating vs. not repeating, as the name DRY suggests. The ideas are related. Making everything explicit tends to be very repetitive. Some of the most basic DRY is finding ways to avoid actually repeated code -- things like actually using functions vs not. But once you have the basic stuff out of the way, it seems like a lot of it is essentially finding things which have been repeated when they could otherwise be inferred -- but that's not absolute.

      Simple example, then, is the database schema vs validations -- some validations can be inferred from the schema, and in general, if your validation could be expressed as a schema restriction, it should be. However, there's not always an easy one-to-one mapping, so the actual implementation of DRY in this case -- or at least the one I use -- can be disabled, partially or entirely, and can (of course) be added to.

      I'm not quite sure yet, though, how such a thing would look for indentation vs end tags/statements/brackets.

      Yeah, most people aren't fanatical extremists; they see that some things can be useful in one area and counterproductive in another. I'm not a fanatical extremist, either -- I'm making an observation. I don't see how it could be useful for markup, but not for source code. But if that is the case, I'd like to know how.
      --
      Don't thank God, thank a doctor!
    141. Re:Literate programming... by mkcmkc · · Score: 1

      I assume you're being facetious, but I will point out that whether or not this works has nothing to do with whether or not an "end character" is used. If you have a "smart" language mode, it'll work--if not, not.

      --
      "Not an actor, but he plays one on TV."
    142. Re:Literate programming... by doom · · Score: 1
      That would be folding.el, non-standard in Gnu emacs when last I looked, though included with xemacs.

      But while it might help with faking some aspects of literate programming, but it isn't exactly what it's about.

    143. Re:Literate programming... by doom · · Score: 1

      I think the prime difference is that literate programming allows you to re-order the code; that is, you include snippet of code within the documentation, and attach tag to the snippets that allow them to be reassembled in a different order.

      Yes, I believe you're right about that: this is the key piece that's missing from most languages. Though on the other hand you can fake it in many ways, e.g. you put your initialization code in a routine that needs to be called first, but the routine itself can be buried at the end if it's too boring to want to read about first.

      Myself I tend to write perl using the embedded pod style that gives you a pseudo-literate approach toward programming: sometimes I do write the documentation for my methods first and then fill in the code afterwards (nothing encourages simplification of interfaces more than having to describe them coherently first).

      Interestingly Damien Conway recommends against this in his "Perl Best Practices": I gather that he goes into specialized modes where he thinks in either language or code, and he doesn't like being shown language when he wants to see code.

    144. Re:Literate programming... by Redlum_Jak2 · · Score: 1

      there is simply no need to expect things like the value of "true" to change

      And yet it has. In C++, the value of false has always been 0, but the value of true was compiler dependent. Some libraries set TRUE to -1. Other libraries used 1.

      I was very happy when !0 was defined to be 1, although I started seeing programmers use !! to force the value to a 1 or a zero.

    145. Re:Literate programming... by greggman · · Score: 1

      That's all fine and dandy, except I happen to work in the real world where I can't control the the millions of other programmers and stop them from using tabs.

      We long ago realized invisible characters effecting the flow of a program was bad (aka: make). Now pythom comes and reintroduces that problem. Yea, thank's python :-(

    146. Re:Literate programming... by Omnifarious · · Score: 1

      What I recommend is a hook for your source control system that refuses checkins for any code that has leading whitespace containing tabs. :-)

      But yeah, I hear you with Makefiles. And I can see how Python's use of a similar idea is similarly problematic. I've never actually found the leading spaces in Makefiles to be that big of a problem, it's other things about Makefiles that I find problematic. But I know it's something that vexes a lot of people.

  2. Shocked by gowen · · Score: 5, Interesting

    He pitches his idea of "literate programming" which I must admit I've never heard of
    I'm shocked to discover that Knuth is taking an opportunity to push literate programming, given that he's been pushing literate programming at every opportunity for at least 25 years.

    Now, I've no problem with literate programming, but given that even semi-literate practices like "write good comments" hasn't caught on in many places, I think Don is flogging a dead horse by suggesting that code should be entirely documentation driven.
    --
    Athletic Scholarships to universities make as much sense as academic scholarships to sports teams.
    1. Re:Shocked by Coryoth · · Score: 5, Insightful

      Now, I've no problem with literate programming, but given that even semi-literate practices like "write good comments" hasn't caught on in many places, I think Don is flogging a dead horse by suggesting that code should be entirely documentation driven. To be fair to Knuth, I don't think the failure to write good comments detracts from literate programming. What Knuth wants is an inversion of thr traditonal code/documentation relationship: you write the documentation and embed the code within that, as opposed to concentrating on code, and incidentally embedding documentation (as comments) within the code. Ultimately the failure of good comments and good documentation is because people are focussing on the code; as long as documentation and comments are an afterthought they will be forgotten or poorly written. If you switch things around and focus on the documentation and insert the code, comment-like, within that, then you're focussing on the documentation and it will be good.

      The reason I think literate programming doesn't catch on has mostly to do with the fact that a great many programmers don't bother to think through what they want to do before they code it: they are doing precisely what Knuth mentions he does use unit testing for -- experimental feeling out of ideas. Because they don't start with a clear idea in their heads, of course they don't want to start by writing documentation: you can't document what you haven't thought through. This is the same reason why things like design by contract don't catch on: to write contracts it helps to have a clear idea of what your functions and classes are doing (so you can write your pre-conditions, post-conditions and invariants) before you start hammering out code. The "think first" school of programming is very out of favour (probably mostly because it actually involves thinking).
    2. Re:Shocked by Anonymous Coward · · Score: 0

      Knuth was asked a question on literate programming, the opportunity was thrust upon him.

    3. Re:Shocked by Anonymous+Brave+Guy · · Score: 1

      Now, I've no problem with literate programming, but given that even semi-literate practices like "write good comments" hasn't caught on in many places, I think Don is flogging a dead horse by suggesting that code should be entirely documentation driven.

      Perhaps his advocacy is futile, at least for now. However, given that he is one of the very few people on the planet who can honestly claim to have produced a substantial piece of widely useful software that is probably bug-free, I think he is entitled to speak with a certain authority on the subject.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    4. Re:Shocked by Anonymous Coward · · Score: 0

      I'm shocked to discover that Knuth is taking an opportunity to push literate programming, given that he's been pushing literate programming at every opportunity for at least 25 years.
      You're full of shit.
    5. Re:Shocked by gowen · · Score: 1

      Oh, I couldn't agree more. I think any practice that leads to better documented code is a good thing but ... well, I think car safety is important too, but it doesn't mean I don't roll my eyes whenever Ralph Nader gets to speak in public.

      --
      Athletic Scholarships to universities make as much sense as academic scholarships to sports teams.
    6. Re:Shocked by Anonymous Coward · · Score: 0

      Good tests *are* documentation. To me, what you're saying is that TDD and literate programming are just two variations of the same approach.

    7. Re:Shocked by gowen · · Score: 2, Funny

      I'm shocked to discover that Knuth is taking an opportunity to push literate programming, given that he's been pushing literate programming at every opportunity for at least 25 years.

      You're full of shit. A proponent of semi-literate programming, I see.
      --
      Athletic Scholarships to universities make as much sense as academic scholarships to sports teams.
    8. Re:Shocked by Coryoth · · Score: 1

      Good tests *are* documentation. To me, what you're saying is that TDD and literate programming are just two variations of the same approach. Good tests are a form of documentation, but I wouldn't suggest that they're an especially good one. Tests as documentation are certainly better than no documentation, but they do have serious shortcomings. First and foremost, they're not the easiest to read since they're code, not English (or your preferred native language). Tests also suffer from being case specific; they tell you how the code should function under some circumstances, but generally don't provide clear bounds on when and how it won't work, and why.

      Now, that's not to say that TDD and literate programming don't have some similarities -- they both have a mentality of putting your intentions down in some clear fashion before providing the code, Of course there are similarities between TDD and lightweight formal methods (in the form of specification driven design) and design by contract. In general I think all of these ideas are good, and given that they are either orthogonal (as TDD and literate programming are) or compatible (as TDD and SDD and DbC are) it makes sense to use all of them in as much as they make sense for the project at hand.
    9. Re:Shocked by Anonymous Coward · · Score: 0

      Wrong. I'm a proponent of honesty, and you are still full of shit.

    10. Re:Shocked by bonkeroo+buzzeye · · Score: 1

      I was also struck by this: "My general working style is to write everything first with pencil and paper, sitting beside a big wastebasket. Then I use Emacs to enter the text into my machine..."

      In the days of batch programming, which costs zillions of dollars and which you waited long hours/days for, you'd damn well better have thought out what you were going to "enter into your machine". These days, with cheap interactive personal computers that are always around, it becomes much easier to take an incremental trial-and-error approach, with unlimited code/compile/debug cycles and so, yeah, there's nothing fully thought out and set down with pencil on paper to document. Literate programming isn't very RAD at all. ;)

      So I agree with what you say but it's not just 'lazy unthinking kids these days'; it may be related to the different technology producing different methodology. I feel Knuth's 'zeitgeist' is better, but today's is understandable, all things considered.

    11. Re:Shocked by Have+Brain+Will+Rent · · Score: 1

      I very rarely write "me too" posts but in this case I can't resist.

      Ultimately the failure of good comments and good documentation is because people are focussing on the code; as long as documentation and comments are an afterthought they will be forgotten or poorly written.

      Yes! Unfortunately the end users, the very people who should most value good documentation, often support the "code first" approach... because they don't want to think/commit either! Or because they don't see the value of good documentation and don't want to pay for it. It's funny (sad) because I see this frequently with people who really ought to know better, having been badly burned by poor or non-existent documentation in the past, but they don't learn the lesson because the penalty is usually extracted from them a little bit at a time over prolonged periods while the costs of documentation are all up front.

      It's the same same with code maintenance - pay more to write good maintainable code now, or "save" now and pay later to deal with the problems of the the cheap poorly written code. It's a problem at every level of the process and of the hierarchy of people involved. Personally I think it is a reflection of basic human nature and it takes some serious mental discipline to get one's head out of that pit.

      The reason I think literate programming doesn't catch on has mostly to do with the fact that a great many programmers don't bother to think through what they want to do before they code it: they are doing precisely what Knuth mentions he does use unit testing for -- experimental feeling out of ideas

      Yes! I like writing code to see how things pan out, it's one of my ways of thinking about what the problems and goals are. But I don't intend that to be the final code - make a cheap throwaway prototype, then make the final product, possibly salvaging bits of the prototype. In fact when you are using functional programming languages it is a very direct and productive way of figuring out the design of something because you continually decompose the problem in a relatively orderly and constrained way.

      The "think first" school of programming is very out of favour (probably mostly because it actually involves thinking).

      Yes! Up and down the whole food chain from the coders to the end users, getting people to think about what they actually want (to achieve, to use, to...) is amazingly difficult. The idea that one can take a problem that is moderately difficult, or worse, and solve it by just jumping on it and letting the "solution" grow organically as you figure it out.... is ludicrous, yet so very popular.

      One reason this happens is because students are allowed to make changes to their code willy nilly to try and get it work - sometimes hundreds of times in a day - I've watched them and it is clear that for many it is pretty much a random process. Back in ancient days when you might get to run your program once an hour, or once a day, and the only tools you had to solve the problem were the input source code, the output results and your brain, then the only way you had a chance to solve the problem was to think first and act second.

      --
      The tyrant will always find a pretext for his tyranny - Aesop
    12. Re:Shocked by SanityInAnarchy · · Score: 1

      Good tests are a form of documentation, but I wouldn't suggest that they're an especially good one... First and foremost, they're not the easiest to read since they're code, not English (or your preferred native language). It sounds to me like you haven't used particularly good test suites. RSpec is actually very readable. It's not entirely a substitute for documentation, but it does solve the "not in English" problem.
      --
      Don't thank God, thank a doctor!
    13. Re:Shocked by bunratty · · Score: 1

      I find that unit testing helps me to clarify what I want. I usually write the tests before I write the code that will pass them. That's when I start thinking about the boundary cases, and I first think about what the result should be before I think about how I'm going to handle those cases. When I get to the point of writing the code, the tests I wrote help me identify where I need to deal with boundary conditions and how I should do so. The type of programmer that just codes first without thinking, then writes the tests as an afterthought, probably isn't making the most of unit testing.

      --
      What a fool believes, he sees, no wise man has the power to reason away.
    14. Re:Shocked by Coryoth · · Score: 1

      I've seen RSpec. Personally if I'm going that route I would prefer stepping up to proper specifications like JML. It's definitely better for providing documentation, at least in the form of API documentation. Then again, Eiffel or Spec# wold also fit the bill. I'm not really knocking RSpec: it's really very nice -- I'm more trying to point out that there are a few more strings you can add to your bow if you like that sort of approah (ad that literate programming is still one of them).

    15. Re:Shocked by Coryoth · · Score: 1

      Well yes, and as someone else pointed out, the underlying idea of TDD bears some similarities in mentality with the ideas driving literate programming. It's a think first approach in many ways. I would add that they aren't really so much competing and complementary ideas. If you think TDD is good, then you might want to look at literate programming (or lightweight formal methods) and see if there aren't some ideas you can extract and make use of in conjunction with your TDD.

    16. Re:Shocked by Coryoth · · Score: 2, Informative

      Yes! I like writing code to see how things pan out, it's one of my ways of thinking about what the problems and goals are. But I don't intend that to be the final code - make a cheap throwaway prototype, then make the final product, possibly salvaging bits of the prototype. Don't get me wrong, and not arguing against that. Neither is Knuth. He mentions such scenarios as one of the cases when he does find a use for unit testing. That's part of the "thinking" stage. From what I gather from the interview Knuth tends to do that with pencil and paper, but you can do it just as well by mucking out some example code and test cases. The point, as you note, is that it isn't your final code: it is that "final code" step (once you've figured out what you want to do) that literate programming really comes in (and in this sense is orthogonal to TDD and similar approaches).
    17. Re:Shocked by Bodrius · · Score: 1

      I'd disagree on both points.

      I think the main reason literate programming doesn't catch on is because a great many (great?) programmers are just not writers - they just do not enjoy writing out their thought processes, and see the code as more concise and literate enough. Writing an essay for every non-trivial piece is no fun in that case.

      Knuth enjoys writing, he's an academic, and he already has to work like this (on paper or not) all the time - to teach, write research papers and books, etc.

      So I think his system misses the fact that most people don't work the same way he does(nor should they have to), and most code that most people write is not even interesting enough to write about.

      I personally like the literate programming concept and think it would be a lot better than the spec->code cycles used in many companies - which at best is 'literate programming without tool support' (but more often is a lot less useful).
      But many programmers I know find that translation effort a chore that gets in the way, rather than help, the thinking process. They'd be better served and less frustrated spending their time on making their code clear and readable.

      The unit-test thing is also related to his academic work - he misses the point of why it is so valuable in the real world.

      To be honest, unit-tests do not help that much to get your first version of the code working.
      If you plan properly and code carefully, they will not help you find many bugs, and you're likely to unit-test only the things that are unlikely to have missed in the code.

      But Real Code in the Real World changes over time, by the hands of different people and entirely unexpected purposes. The value of unit-tests is that they allow refactoring and modification of the code, after the fact, with greater confidence.

      You do not create unit-tests to "feel out your way in a totally unknown environment". You make them so the OTHER poor bastard who has to feel out their way in YOUR totally unknown environment can use them to have some idea of what works, what doesn't, and an automated set of sanity-check rules that tell him what he missed.

      --
      Freedom is the freedom to say 2+2=4, everything else follows...
    18. Re:Shocked by Anonymous Coward · · Score: 0

      I had a longer response, but the new comment system ate it. It's probably for the best.

      Summary: Documentation has a cost; most people write code to be consumed by machines, not other people; and not all projects justify the effort.

      Yes, there are a lot of "lazy" people out there, but don't be so dismissive of the "get your hands dirty" school of programming. The people that engage in this kind of activity are the same kind of people who used to like to tinker with motorized bicycles and thought of putting some wings on it.

      Plenty of programming falls under this category of activity; it's a fluid, creative process, not something you sit down and plan out meticulously. It's an invaluable prototyping stage, because final systems never look like what you think they should. Every good writer knows they're going to have to throw out the first, second, or even third draft.

      For a system meant to stand the test of time, literate programming may or may not have something going for it. (TeX is the classic example, but the pace of development seems glacial to me. It seems very un-modern.)

      Perhaps what Knuth fails to realize is first, we aren't all as clever as he is, and second, that his background in academic research doesn't necessarily translate to a commercial world where software isn't art, it's product.

    19. Re:Shocked by lysse · · Score: 1

      Isn't that like saying we should abandon "thou shalt not kill" because most people can't even be nice to each other?

    20. Re:Shocked by Coryoth · · Score: 1

      Summary: Documentation has a cost; most people write code to be consumed by machines, not other people; and not all projects justify the effort. Documentation does indeed have a cost, and certainly not every project justifies it. I would contend, however, that most people write code that will spend a great deal of time being consumed by people (for the purposes of maintenance and debugging); just think of how many projects are still kicking around and still being maintained longer than the original author might have forseen.
    21. Re:Shocked by russellh · · Score: 1

      'm shocked to discover that Knuth is taking an opportunity to push literate programming, given that he's been pushing literate programming at every opportunity for at least 25 years.

      I didn't notice him "pushing" literate programming. I don't think the submitter really read the interview very well, in fact, and misread most of what Knuth actually said. Did you read the same article I did? He simply answered the questions. First, in answer to the question about why hasn't literate programming become popular, he said:

      Literate programming is a very personal thing. I think it's terrific, but that might well be because I'm a very strange person.

      But then he said basically, but he thinks it rocks and works for him very well. Then:

      Jon Bentley probably hit the nail on the head when he once was asked why literate programming hasn't taken the whole world by storm. He observed that a small percentage of the world's population is good at programming, and a small percentage is good at writing; apparently I am asking everybody to be in both subsets.

      Ok so far we have 1) it's probably personal and I'm strange; 2) but it works for me; 3) literate programming requires a very weird person.. But, finally we get:

      But I don't believe in forcing ideas on anybody. If literate programming isn't your style, please forget it and do what you like. If nobody likes it but me, let it die.

      How in the hell does this count as pushing literate programming? I don't mean to sound like I'm flaming you here, but seriously. Reread it without being influenced by the awful description by the submitter. Nowhere did I see Don "rip" on anything.

      --
      must... stay... awake...
    22. Re:Shocked by Eivind+Eklund · · Score: 1
      While I agree with you in wanting to use several of the methods, I don't think they're as orthogonal as we immediately think.

      All of these methods are ways to improve the quality of software, essentially decreasing the amounts of bugs in the software or the cost of learning how the software works. However, they come with a cost of their own: They make it more work to write and modify the code. For instance, DbC makes you have to change the contracts throughout the code whenever you change the contract at a core point. This makes your code more rigid.

      TDD makes you have to update tests when you update code, and sometimes the thing you change require you to change tests in many places.

      Literate programming makes you need to spend time on documentation, which helps with understanding the software and thereby more easily modifying it (and making it more likely to be correct the first time around) - but this cost is less palatable when you have another way to cheapen modification and making it more likely to be correct the first time around.

      I don't know the exact tradeoff point between the different methods - I haven't tried to mix them with each other, and I haven't tried full literate programming at all. I just feel quite sure that there's tradeoffs between them, even when they initially seem orthogonal, because the cost/benefit picture is changed by the application of any of them.

      I hope that was clear - and to paraphrase Blaise Pascal, I'm sorry for writing so much, I wish I had time to write less.

      Eivind.

      --
      Doubting the existence of evolution is like doubting the existence of China: It just shows that you're uninformed.
    23. Re:Shocked by gowen · · Score: 1

      Sure, if you think programming methodologies are the same as moral absolutes. That's exactly what its like. Don't you have a car analogy?

      --
      Athletic Scholarships to universities make as much sense as academic scholarships to sports teams.
    24. Re:Shocked by btakita · · Score: 1

      The "think first" school of programming is very out of favour (probably mostly because it actually involves thinking).

      Or mostly because building a large tree of assumptions has fallen out of favor. Requirements and technologies change. The world is not static.

      One of the reasons test incrementally, like in unit testing, is to get feedback that your design is the simplest thing that could work (but no simpler). That does not mean "turn your brain off" and implement a stupid solution.

      I like to think of TDD as an empirical activity because it involves creating an hypothesis of how the software will work and verifying it through the implementation satisfying the test.

      Another benefit of automated testing (unit, functional, and integration) is to guard against regressions when refactoring or implementing new features.

    25. Re:Shocked by Thangalin · · Score: 0

      One issue I have heard is "comments clutter source code". Why not split them? An example editor is shown in the following clip: http://www.youtube.com/watch?v=u3QqjhzhnAw

    26. Re:Shocked by HighPerformanceCoder · · Score: 1

      This new posting system chewed my last comment, so forgive me for being a little short. I used FWeb (Fortran version of CWeb) a while back for a project, but discovered that debugging was extremely hard for exactly the same reason Bjarne Stroustrup warns against excessive use of macros. Line numbers do not correlate between the debugger and the source code. Often you just end up debugging intermediate code instead of the source. Also a problem was that the target of FWeb was a printed page (or equivalently a postscript file) which is hard to navigate. I found that Doxygen (coupled with C++) implements the best features of literate programming without these detriments.

    27. Re:Shocked by hicksw · · Score: 1

      The reason I think literate programming doesn't catch on...

      is that it is too much like waterfall.

    28. Re:Shocked by Coryoth · · Score: 1

      No, it's quite clear, and I agree, everything has its costs and tradeoffs, and won't make sense for every project. You have to evaluate what's going to be most useful. I will maintain, however, that a mix of several is often going to be better than picking one as the silver bullet (which these days seems to be unit testing; who knows why -- it takes just as much time as the others as you point out).

    29. Re:Shocked by Coryoth · · Score: 1

      Only if you're doing it wrong...

    30. Re:Shocked by Coryoth · · Score: 1

      Or mostly because building a large tree of assumptions has fallen out of favor. Requirements and technologies change. The world is not static. That presumes, of course, that by "think first" I mean "design the entire application from soup to buts in your head" as opposed to "get a clear idea in your head of exactly what you want this next function you're going to write is supposed to do. The latter, of course, is perfectly compatible with agile development. TDD asks you to design a test for the code block you're about to write. Literate programming asks you to think enough about the code block you're about to write that you can write the documentation up. DbC asks you to provide the requirements you intend to have on the code block you're about to write. All of this can be quite agile, and none of it asks you to use a waterfall "design everything first" approach.
    31. Re:Shocked by DuckDodgers · · Score: 1

      Another benefit of automated testing (unit, functional, and integration) is to guard against regressions when refactoring or implementing new features. I think that's the biggest value. If you are 100% certain that your initial design is adequate and the software will be static, unit tests are much less necessary.

      But they are spectacularly useful for refactoring.
    32. Re:Shocked by TheLink · · Score: 1

      I'm rather lazy. I prefer to write code with as few bugs as possible.

      So in addition to the normal cases I usually think about the boundary and potential future cases, and try to write code that will better handle them.

      While it's not a 100% substitute for unit tests, it does take a lot less time (since you don't have to write hundreds of different tests for each module), and the resulting code is similar to what it should be in the first place ;).

      Unit tests are a good idea (esp for regression testing). But finding the time, resources and will to write them is hard.

      A number of changes to my programs are to workaround bugs in other people's code (e.g. 3rd party vendor's box that's not working as "advertised" but not going to be fixed/changed anytime soon, or bugs in programs originally written by some programmers from an Indian software company... ).

      Unit testing doesn't help for that.

      It's a lot less work and time to write the stuff, release a decent version and then find the bugs in other people's stuff.

      I'm far from a top programmer, but thank goodness for the crap out there that makes me look good in comparison :).

      --
    33. Re:Shocked by btakita · · Score: 1

      The "think first" school of programming is very out of favour (probably mostly because it actually involves thinking).

      TDD asks you to design a test for the code block you're about to write.

      I'm not sure what you mean by "thinking" then. I practice TDD and I think about the problem, the solution, and the process. We even have design sessions when the problem or solution is particularly complicated.

      I have seen people suffer from paralysis by analysis, especially when the code base becomes too large to hold in one's head. Ultimately, abstraction, separation of concerns, and the many other ways of managing complexity is useful to combat this. Any development technique that establishes the discipline to manage the complexity will be beneficial.

      One thing that TDD does very well is to establish a quick development rhythm. This leads to a very fast "evolution" of the code base. I must say that the Red-Green-Refactor strategy makes my development faster than CreateMentalModel-ComeUpWithSolution-ThinkAboutImplications-ImplementSolution because generating the mental model and thinking about all implications is automated by the test suite. Of course more global architectural problems are thought about and communicated with discussion, whiteboard, and modeling.

      I'm not sure how Literate Programming and DbC fit in with rapid iterations and software evolution because I don't have experience with these disciplines, but I'm intrigued by the idea of learning new tools, especially if they have a low cost and high benefit.

    34. Re:Shocked by btakita · · Score: 1

      I must say that the Red-Green-Refactor strategy makes my development faster than CreateMentalModel-ComeUpWithSolution-ThinkAboutImplications-ImplementSolution because generating the mental model and thinking about all implications is automated by the test suite.

      I'd like to add that the automation of the tests provide an abstraction that allows for quick feedback that verifies or disproves your solution. This abstraction is a "thought abstraction" of a sort, because it allows focus on the localization of the mental model (I can focus on thinking about a smaller part of the system in detail) and globalization of thinking about the implications (if the changes affect the contract of the Object).

      It is also valuable to come up with a coherent Domain Language that ties your tests, implementations, and thoughts together. Perhaps thats what Literate Programming is designed to do?

  3. Did anyone claim the bug prize on TeX? by 140Mandak262Jamuna · · Score: 1

    It is probably folklore. But the story during my grad school days was that, Knuth offered 1000$ prize to anyone fining a bug TeX and he doubled it a couple of times. And it was never claimed. If that was true, it is very unlikely he was just flame baiting.

    --
    sed -e 's/Chuck Norris/Rajnikant/g' joke > fact
    1. Re:Did anyone claim the bug prize on TeX? by paulbd · · Score: 4, Informative

      the prize was not US$1000. it started out very small. Knuth did indeed pay out, and indeed doubled it, several times. From wikipedia: "The award per bug started at $2.56 (one "hexadecimal dollar"[24]) and doubled every year until it was frozen at its current value of $327.68. This has not made Knuth poor, however, as there have been very few bugs claimed. In addition, people have been known to frame a check proving they found a bug in TeX instead of cashing it."

    2. Re:Did anyone claim the bug prize on TeX? by Anonymous Coward · · Score: 0

      http://en.wikipedia.org/wiki/Knuth_reward_check

    3. Re:Did anyone claim the bug prize on TeX? by nuzak · · Score: 2, Interesting

      > But the story during my grad school days was that, Knuth offered 1000$ prize to anyone fining a bug TeX and he doubled it a couple of times.

      The $1000 bounty was from Dan Bernstein with respect to qmail. He's always found a reason to weasel out of ever paying.

      Knuth started the bounty at $2.56 (one "hexidollar") and doubled it every year til it reached $327.68. Several people have claimed it, most people never cashed the checks. One of the first bug finders had his check framed.

      --
      Done with slashdot, done with nerds, getting a life.
    4. Re:Did anyone claim the bug prize on TeX? by TheRaven64 · · Score: 3, Interesting

      The original prize was $2.56 (i.e. 2^8Â), and he doubled it every time someone found a bug until it reached $327.68. Over 400 bugs have been fixed in TeX, and that's just counting the core VM and typesetting algorithms - all of the rest is in metaprogrammed packages, many of which contain numerous bugs. I'm fairly sure that most programmers could write bug-free code if the only place where bugs counted was in a simple VM with a few dozen instructions that interpreted all of the rest of the code...

      --
      I am TheRaven on Soylent News
    5. Re:Did anyone claim the bug prize on TeX? by 1729 · · Score: 4, Interesting

      It is probably folklore. But the story during my grad school days was that, Knuth offered 1000$ prize to anyone fining a bug TeX and he doubled it a couple of times. And it was never claimed. If that was true, it is very unlikely he was just flame baiting. He offers rewards for reporting errors is his books and for finding bugs in his code:

      http://en.wikipedia.org/wiki/Knuth_reward_check

      Many people save these (usually small) checks as souvenirs. My father -- a frugal mathematician -- received a few $2.56 checks from Knuth, and he promptly cashed each one.
    6. Re:Did anyone claim the bug prize on TeX? by Cyberax · · Score: 1

      Seen in someone's signature:

      Intelligence: Finding an error in a Knuth text.
      Stupidity: Cashing that $2.56 check you got.

    7. Re:Did anyone claim the bug prize on TeX? by Nick+Barnes · · Score: 1

      All of my Knuth checks are framed. I can't imagine anyone ever cashing one.

    8. Re:Did anyone claim the bug prize on TeX? by jms · · Score: 1

      I've had my $2.56 check hanging on my wall for 19 years now. (for finding a mostly inconsequential omission in the letter Q in romanu.mf.)

      Did *anyone* actually cash any of those checks? They are one of the truly great trophies in the computer science field.

    9. Re:Did anyone claim the bug prize on TeX? by jschrod · · Score: 1

      Yes, Frank (Mittelbach) cashed several of them, he made a sport to find dozens of errors both in tex.web and in the TeXbook. I cached some as well, and kept only the very first that I got, back in 1983, when we ported the brand-new TeX82 to our then-TeX78 installation. It's now besides the picture of Don and Jill, when they visited us at home a few years later. Oh, such were the times... :-)

      --

      Joachim

      People don't write Manifestos any more -- what's going on in this world? [Frank Zappa]

  4. Youth and trendiness by CSMatt · · Score: 1

    At the end, he even remarks on his adage that young people shouldn't do things just because they're trendy. They shouldn't, but we all know that they do it anyway. Peer pressure has a big impact on the lives of "young people."
    1. Re:Youth and trendiness by Anonymous Coward · · Score: 0, Offtopic

      YOU KIDS GET OFF MY LAWN!

  5. I saw "Donald Knuth Rips One" by Anonymous Coward · · Score: 1, Funny

    I misread the headline. I was looking forward to a good Fart story from Donald "Structured Programming" Knuth. Oh well...

  6. What? by TheRaven64 · · Score: 5, Interesting
    You've heard of TeX, written in Web, the language designed for Literate Programming, but you've not heard of Literate Programming?

    I have a lot of respect for Knuth as an algorithms guy, but anything he says about programming needs to be taken with a grain of salt. When he created the TeX language, he lost all credibility - designing a language in 1978 which makes structured programming almost impossible is just insane. TeX gets a lot of praise as being 'bug free,' but that's really only half true. The core of TeX is a virtual machine and a set of typesetting algorithms, both of which are very simple pieces of code (they'd have to be to run on a PDP-10). Most of the bits people actually use are then metaprogrammed on top of the virtual machine, and frequently contain bugs which are a colossal pain to track down because of the inherent flaws in the language (no scoping, for example).

    If you want to learn about algorithms, listen to Donald Knuth and you will learn a great deal. If you want to learn about programming, listen to Edsger Dijkstra or Alan Kay.

    --
    I am TheRaven on Soylent News
    1. Re:What? by gowen · · Score: 5, Insightful

      Amen about TeX (and even LaTeX). I consider myself pretty knowledgeable about many computing languages, but every time I've hit a non-trivial problem with making TeX do what I want, I've had to consult with a TeXpert (i.e. the utterly invaluable comp.text.tex). And, sadly, in almost every case the solution has been either insanely baroque, or there's been no real solution at all. LaTeX makes brilliant looking documents, but Jesus wept, it's hard to make your documents look like YOU want, as opposed to how it thinks they should look.

      --
      Athletic Scholarships to universities make as much sense as academic scholarships to sports teams.
    2. Re:What? by Jimmy_B · · Score: 0

      designing a language in 1978 which makes structured programming almost impossible is just insane
      TeX is not a programming language, it's for typesetting. HTML doesn't support structured programming either, and nobody cares. If you need structured programming in TeX, you're doing it wrong.
    3. Re:What? by Anonymous Coward · · Score: 0

      I tried taking the TeX LaTeX plunge and decided it wasn't worth the time. Professional printers I use all accept PDFs happily.

    4. Re:What? by gowen · · Score: 1

      I've still found nothing better looking for mathematics, kerning, ligatures, or smarter for indexing and footnotes. But almost everything is easier to work with.

      Maybe LyX and its like is the answer, but I haven't tried it for years.

      --
      Athletic Scholarships to universities make as much sense as academic scholarships to sports teams.
    5. Re:What? by cbart387 · · Score: 5, Interesting

      If you want to learn about algorithms, listen to Donald Knuth and you will learn a great deal. If you want to learn about programming, listen to Edsger Dijkstra or Alan Kay. For those that didn't read the article, Knuth expressed criticism on several of the questions asked, but he didn't want to just duck the question. For instance, the 'trendy question' he said this.

      With the caveat that thereâ(TM)s no reason anybody should care about the opinions of a computer scientist/mathematician like me regarding software development
      --
      Lack of planning on your part does not constitute an emergency on mine.
    6. Re:What? by cbart387 · · Score: 1

      With the caveat that theres no reason anybody should care about the opinions of a computer scientist/mathematician like me regarding software development Sorry, hit submit instead of edit (why does preview turn into submit). Bah!
      --
      Lack of planning on your part does not constitute an emergency on mine.
    7. Re:What? by djmurdoch · · Score: 1

      TeX is not a programming language, it's for typesetting. TeX is a programming language for typesetting. And the GP is right, it's a horrible design for a language.

    8. Re:What? by FranTaylor · · Score: 1

      You need a "real" computer language for typesetting, which is why they invented Postscript. If TeX had fulfilled its promise, Postscript would not have been necessary.

    9. Re:What? by LizardKing · · Score: 1, Interesting

      I think that the grandparent poster was referring to the dissecting and reordering of code that generally occurs with Literate Programming. Take the code from the book "A Retargetable C Compiler: Design and Implementation", which uses Literate Programming. The code is written as snippets and in an order that makes describing the purpose of the compiler easier, but the code itself loses its "integrity" (individual functions are split up and reordered) and is effectively unmaintainable in its source form - it needs to be preprocessed into a more logical order for the programmer to follow, but in doing so you're no longer editing the source in its Literate Programming form!

      I know this will annoy those who believe he's some saint just because they've heard he is from anecdotes, but Knuth is somewhat irrelevant. An academic who has written no significant code (no, TeX doesn't count as it's just a simple interpreter), and who rails against the real world from his ivory tower. Even his books are a waste of time, with code written in an idealised assembly language that glosses over a number of practical considerations, they're dated, unbelievably boring and of no practical use compared to something like the "Numerical Recipes" or "Algorithms in ..." books.

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

      LyX, if anything, is even less flexible. Just as others have said, TeX and friends are fantastic, elegant tools if your layout fits exactly into one of their templates. Otherwise, good luck.

    11. Re:What? by sc00p18 · · Score: 2, Interesting

      Fortune cookie at the bottom of the page for me:

      They are relatively good but absolutely terrible. -- Alan Kay, commenting on Apollos

    12. Re:What? by lekikui · · Score: 1

      How do you think the templates were produced?

      There are a lot of very smart people doing very impressive stuff with TeX and LaTeX, and generally working out large parts of the arcana. Take, for instance, pgfplots. A simple system for plotting data, so that you say, for instance:

      \begin{tikzpicture}
          \begin{axis}[
              xlabel=$x$,
              ylabel=$y$]
          \addplot[smooth,mark=*,blue] plot coordinates {
              (0,2)
              (2,3)
              (3,1)
          };
      \end{axis}
      \end{tikzpicture}

      Very simple and easy. Underneath that there's a hell of a lot of clever pgfplots stuff to turn it into TikZ commands, then a hell of a lot of clever stuff in TikZ to produce the appropriate graphics.

      Similar packages exist for doing most stuff, including various packages for redesigning templates and the like (geometry does everything you need to with margins, for a start). And then you have projects like XeTeX (unicode, system fonts, some other stuff) and LuaTeX (unicode, hooks into the TeX engine for your own Lua code to modify it as you need).

      There are a lot of people working quite hard on making it easier to do more advanced stuff with TeX. It's not just "if you aren't doing exactly $x, you're screwed" any more. And hasn't been for quite a while.

      --
      "Lisp ... made me aware that software could be close to executable mathematics." - L. Peter Deutsch
    13. Re:What? by Anonymous Coward · · Score: 0

      I know this will annoy those who believe he's some saint
      He's no saint, but you've revealed yourself to be a piece of shit. Do you feel like a big man now that you've slandered him?
    14. Re:What? by heffrey · · Score: 1

      Javadoc, doxygen, python docstrings, these are all literate programming tools. Everyone's heard of it, they just don't know the name.

    15. Re:What? by Nicolas+Roard · · Score: 1

      Not really. Javadoc/Doxygen are taking a program and generating a "documentation" (more a reference really). CWEB and similar tools take a documentation and generate a program. It's not just a question of doing it in the other direction -- the results won't be the same (ie, a LP documentation will be much better). But Javadoc/Doxygen have a much, much lower entry barrier, and they do provide something useful, so, better than nothing...

    16. Re:What? by larry+bagina · · Score: 1

      AMEN. I use TeX/LaTeX, and love the output, but...

      Knuth might write a book about parsers, compilers, and programming languages? TeX should be considered a case study in things not to do. The language is a turd by any metric. "How do I ..." programming questions in comp.text.tex are usually answered with "use perl/m4/cpp to preprocess it."

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

    17. Re:What? by WeirdJohn · · Score: 1

      As an old fart, the DEC-10 and DEC-20, when compared bit-for-bit, word-for-word and cycle-for-cycle, ran rings around today's hardware. One reason why so much code developed for those machines worked so well was because they were nice to work with, and in many respects a lot of what you today think is great software is directly descended from that "simple" software written on that platform.

      One example is that an entire file copy program (less the strings for source/destination pathnames) could be written in about 30 bytes of MACRO assembler. Do that on today's hardware.

    18. Re:What? by heffrey · · Score: 1

      What, so I just write the documentation and then get CWEB to turn it into a program? How on earth did I spend 15 years writing software without hearing about this revolution? Or perhaps you are talking rot!

    19. Re:What? by lekikui · · Score: 1

      No, he's telling the truth. You write documentation describing the program, introducing the source code as it becomes relevant, and then run the resulting file through a program called (iirc) tangle. Which produces the valid source code.

      Basically, you write the documentation, and use a program to pull out and compile the source. As someone else said, it's like writing a document, and then adding comments that tell the computer what to do.

      --
      "Lisp ... made me aware that software could be close to executable mathematics." - L. Peter Deutsch
    20. Re:What? by jeremyp · · Score: 2, Funny

      I fon't know. I've found that Dijkstra hasn't said anything new or profound in more than five years.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    21. Re:What? by MichaelSmith · · Score: 1

      An early job I interviewed for ran IT for an entire hospital on an early PDP/11. It had 60 VT terminals.

      The job I wound up doing used PDP 11/83's and 11/84's to run a traffic signal system. I did callout work at night and if a system halted it was usually because a card had failed. Almost always the register dump on the console would give you the bus address of the failed card.

      They were scary systems initially but nice to work with once you got used to them. Just don't slide a box out of the rack without extending the legs first because there is a lot of off centre mass there.

      One thing which started to bring down the PDP boxes was that the plastic padding inside the lid turned to dust, then the dust fell into the backplane. The metal parts easily outlived the plastic ones.

    22. Re:What? by spuzzzzzzz · · Score: 1

      TeX was finished in 1989. PostScript shipped with the Apple LaserWriter in 1985 (source: Wikipedia). Not to mention the fact that you would have to be utterly insane to try to write a book (or even a mathematical formula) in straight PostScript.

      --

      Don't you hate meta-sigs?
    23. Re:What? by papna · · Score: 1

      TeX was finished in 1989, but it had existed before that. I believe the 1982 version of TeX was significant. PostScript was not, I do not believe, an extremely important standard in those early days. But, indeed, TeX and PostScript serve different (and complementary!) purposes. You cannot reasonably do in PostScript what you can easily do in TeX.

    24. Re:What? by gardyloo · · Score: 1

      You should try LyX again. They're working hard at getting out the 1.6.0 version ( I've been compiling and installing the svn version lately and it's given me no problems thus far ). I don't know why there's such a sudden upswing of messages on LyX' user mailing list, but there has been over the last couple of months, and the developers and advanced users are unbelievably helpful and responsive.

            As another respondent has stated, LyX doesn't do anything that LaTeX doesn't do, but since you can embed LaTeX code into your LyX document very easily, and just type for the rest of the work, it's very nice to work with. Plus, it integrates nicely with CAS programs, bibliography managers, etc., and is cross-platform.

    25. Re:What? by McDutchie · · Score: 1

      LaTeX makes brilliant looking documents, but Jesus wept, it's hard to make your documents look like YOU want, as opposed to how it thinks they should look.

      That's because the whole point of LaTeX is not having to design the look of your document. The underlying assumption is that scientists aren't graphic designers and they're better off having their papers and books automatically designed for them. If you want to control the look of your document yourself, you're simply using the wrong tool for the job.

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


      ///they're dated, unbelievably boring and of no practical use compared to something like the "Numerical Recipes" or "Algorithms in ..." books.

      When comparing these books my conclusion is the opposite. To each his own...

    27. Re:What? by gowen · · Score: 1

      Well, yes. But I don't think that "I want multi-page tables" falls under graphic design. And yet its a total PITA to do in basic LaTeX.

      --
      Athletic Scholarships to universities make as much sense as academic scholarships to sports teams.
    28. Re:What? by Anonymuous+Coward · · Score: 1

      It did work just fine for me with 'longtable'.

    29. Re:What? by heffrey · · Score: 1

      He said, "CWEB and similar tools take a documentation and generate a program." How exactly does CWEB generate the program? I don't think stripping out the documentation is really best described as "generating" a program. You still have to write the program yourself don't you?

    30. Re:What? by TheRaven64 · · Score: 1

      The underlying assumption is that scientists aren't graphic designers and they're better off having their papers and books automatically designed for them. TeX is a baroque programming language. If scientists can't write code in it, what on earth makes you think that graphic designers can? If there were graphical tools for creating TeX layouts, then your point would make sense, but it doesn't. TeX, by itself, mixes formatting and text. LaTeX tries to build a semantic markup system on top of TeX, but in order to do anything really complicated you often need to fall back to plain TeX.

      Try getting a graphic designer to mock up a complex page layout for you, and then reproduce the same layout in [La]TeX. For bonus points, put it in a package or document class that typesets existing documents with that layout.

      --
      I am TheRaven on Soylent News
    31. Re:What? by lekikui · · Score: 1

      Go look up a few CWEB examples. You describe, bit by bit, the program, explaining how each bit works, and illustrating it with code snippets. These are in the logical order for the documentation. CWEB then does some magic on it* to turn it into code that will compile.

      So the program gets written as a result of writing excellent documentation on how you're solving the problem.

      *Reordering as necessary, removing extra markup, and stuff like that.

      --
      "Lisp ... made me aware that software could be close to executable mathematics." - L. Peter Deutsch
    32. Re:What? by heffrey · · Score: 1

      Well, my question stands, how exactly does CWEB generate the program? You still have to write it yourself. CWEB does not generate it.

    33. Re:What? by lekikui · · Score: 1

      Well, the file you produce won't compile as a program. So CWEB generates it in that sense, as it ends up producing valid source.

      But yes, the program is written as you construct the documentation explaining it.

      --
      "Lisp ... made me aware that software could be close to executable mathematics." - L. Peter Deutsch
    34. Re:What? by heffrey · · Score: 1

      My point is that generating the program from the documentation is somewhat misleading. You still write the code, but it's annotated with the documentation. Or, if you prefer, you write some documentation but annotate it with code. Either way you then run programs that strip either code or doc and are left with the other to feed into the next stage of the tool chain.

      And that's essentially the same as Doxygen or Javadoc or whatever. Literate programming isn't WEB or CWEB or tangle/weave, it's the mindset. It's just ridiculous to suggest that you can write documentation and then get CWEB to generate the program as the original post said.

    35. Re:What? by McDutchie · · Score: 1

      Wow. I have never seen someone so utterly miss the point of a message. Try reading what I actually wrote instead of what you think my message should have said.

    36. Re:What? by lekikui · · Score: 1

      No, the important difference is that literate programming goes Documentation->Code, while Javadoc/Doxygen goes Code->Documentation. There's an important mindset difference between the two.

      Yes, they're essentially the same, but the mindset difference is very important. To write a good CWEB program you need to thoroughly understand what you're doing. Go look up something like TeX the Program sometime. You can see that Knuth really understands what's happening with each part of it. It's not cobbled together to work, it's the product of being properly thought about and written up.

      In contrast, Doxygen/Javadoc produce references for whatever hacked up stuff you've written. There's no corresponding increase in the amount of thought required to write it.

      --
      "Lisp ... made me aware that software could be close to executable mathematics." - L. Peter Deutsch
    37. Re:What? by McDutchie · · Score: 1

      Well, yes. But I don't think that "I want multi-page tables" falls under graphic design. And yet its a total PITA to do in basic LaTeX.

      Guess you haven't heard of the longtable package. It comes with LaTeX so it's as basic as anything.

    38. Re:What? by heffrey · · Score: 1

      I think that's just what I said. Sure the mindset difference is important. But my main point was that WEB/CWEB whatever cannot generate your program. You still have to write it yourself. But you don't seem to be able to read what I actually say in my posts.

      Now, writing the documentation first helps you work your specification out and therefore allow you to code a system that actually does what the users want. TDD devotees would argue that TDD does the same. All these arguments about which processes work best are rather pointless. What works for one person may not work for the next person. But what will always work is clever people thinking about what they are doing and trying to do it better. Knuth knows this and says that whilst literate programming makes him tick it may not for others. So be it.

    39. Re:What? by epine · · Score: 1

      Your ivory tower comment is rich. Long ago, Knuth founded the discipline of principled pseudo-random number generation. His is a different style of thinking than the "cookbook" audience expects. Sometimes required for problems of greater subtlety. Each to his own, I guess.

      I've never understood criticizing others for setting out with a different purpose in life, especially when that purpose is clearly laid out, as it always was with Knuth. Knuth made positive comments about marching to a different drummer. More people should try it, IMHO.

      In fact, I thought this post's me-centrism "what have you done for me lately" was itself decidedly out of fashion, since the recent (re)discovery that preserving the planet is essential to humanity's continued existence.

      The goal for TeX was to produce a system that would still produce pixel for pixel identical output many decades later. Another post criticized that TeX is not structured. I don't know what advantage Knuth would have gained from that. The advantage of structured programing is that the program becomes more suitable for adapted toward evolving specifications, which is exactly what Knuth wished to avoid.

      For suitability to task, Knuth was primarily concerned with typesetting his own TAOCP, which is a fair representation of manuscripts from the high-end of mathematical typesetting.

      Google is now in some respects the antithesis of what Knuth was attempted to achieve with TeX. I go to my personal Google maps not knowing from minute to minute if the UI will continue to work as I last used it. Is that a good direction?

      From a modern software engineering perspective, the underlying TeX macro language is a frustrating pile of crap. But I accept the reason, in the same vein as I accept Stroustrup's decision for C++ to remain compatible with C, even though bolting C++ abstractions onto the C style declaration syntax remains an undying source of ugliness and detraction.

      In Knuth's case, much of this was driven by his long-ago determination that TeX should function as a one-pass system. It was a practical reality at the time he wrote TeX that it functioned this way given the size of the TAOCP manuscript, and Knuth's personal work style.

      Knuth was quite open that he is largely opposed to programming by maintenance, but welcomes re-purposing and adaptation.

      Is the grass greener on the other side of the fence? On the other side of the fence, we have expat, Jade and DSSSL, to which few of the same criticisms apply. Panacea? I think not. Nor do I think any less of James Clark for having brought it to fruition.

      I don't look to the giants among us to pave the road of convenience. I look to the giants among us to illuminate what is possible. It's when the gold brickers arrive from the private sector that I succumb to ennui. Except when I'm the gold bricker myself. Then I become strangely fascinated with my own reflection in the mirror, as if my every keystroke is a clarion click of eternal significance.

      It's a rare day at the office when the significance of my work output surpasses the most boring paragraph in the TAOCP.

      "Bernard of Chartres used to say that we are like dwarfs on the shoulders of giants, so that we can see more than they, and things at a greater distance, not by virtue of any sharpness of sight on our part, or any physical distinction, but because we are carried high and raised up by their giant size."

      Then along comes the noble idiot who declares "the view is just as good, and life is more comfortable, standing on this loose pile of shifting rocks".

    40. Re:What? by lekikui · · Score: 1

      I am reading your posts. I was just disputing that it's "essentially the same as Doxygen or Javadoc or whatever". Nothing much more.

      --
      "Lisp ... made me aware that software could be close to executable mathematics." - L. Peter Deutsch
    41. Re:What? by TheRaven64 · · Score: 1
      I'm replying to exactly what you said. You claimed that the point of LaTeX was that

      scientists aren't graphic designers and they're better off having their papers and books automatically designed for them LaTeX doesn't automatically design papers or books, it applies templates that another human has designed. You claim that graphic designers are the ones who should be designing layouts (implicit in the fact that people who aren't graphic designers shouldn't), and yet the only people who can design a layout in LaTeX are programmers (I've done it myself, and it's a huge amount of work for even simple tasks), the very people you claim shouldn't be designing layouts.
      --
      I am TheRaven on Soylent News
  7. Programming for the human VM by TuringTest · · Score: 4, Insightful

    Literate programming is an old friend for developers of functional programming languages. I see it like "code for the human mind": it provides a source code that is well adjusted to the needs of the developer, not just the machine.

    It interleaves code and documentation in the same files, and provides a specialized compilator to tell the two kinds of codes apart. Just like Doxygen and Javadoc can extract the comments from a source code project, the "tangle" process can extract all the code from a Literate program and pass it to a clasic compiler.

    Now that C and C++ seem to have a declining popularity, maybe we can look for better ways of getting away from the bare metal (which, don't forget it, is why those languages become popular at the beginning). Don't get me wrong, they served us well for 36 years, but I think it's time again to begin caring more for the developers' requirements and less for the hardware requirements.

    --
    Singularity: a belief in the "God" idea with the "demiurge" relation inverted.
    1. Re:Programming for the human VM by Anonymous Coward · · Score: 0

      if you start doing that you end up with vista :)

    2. Re:Programming for the human VM by Anonymous Coward · · Score: 0

      I think it's time again to begin caring more for the developers' requirements and less for the hardware requirements. Microsoft got in with that attitude 10 years before you. Vista was the result.

      And OSS plays catchup once again...
    3. Re:Programming for the human VM by Anonymous Coward · · Score: 0

      Any concept which requires the developer to maintain a form of documentation is doomed to failure. The code itself, in every detail, needs to be understood by people who maintain it or they will make a mess of it. Comments only create the illusion of insight, a false confidence which occludes the necessity of thinking changes through. The only legitimate form of documentation is an architectural description, a document which presents the big picture, the conceptual foundation of a program or system. Everything else needs to be in the code. If a precondition is important to a function, write the test code. Documenting the precondition does not help at all. If you can't read and understand the code itself, don't touch it.

      I understand that there is a need to have lesser coders work on programs, but the solution to that is to raise the abstraction level of the language to a point where they can understand the code, not to pretend that comments or documentation are substitutes for understanding the actual code.

    4. Re:Programming for the human VM by Angst+Badger · · Score: 1

      Don't get me wrong, they served us well for 36 years, but I think it's time again to begin caring more for the developers' requirements and less for the hardware requirements.

      Maybe someday it will be fashionable to care about the users' requirements, which is all that really matters unless you're just coding for your own amusement. It may at least occasionally be the case that serving the user well will require the developer to use tools that are difficult or inconvenient.

      That's not to say that in many applications, high-level languages and automated development tools aren't the right tool for the job, but it would be a good thing if we could turn down the narcissism of the programmer cult just enough to remember that software development isn't about developers.

      --
      Proud member of the Weirdo-American community.
    5. Re:Programming for the human VM by jcast · · Score: 1

      Caring about the users is fine, but last I checked, they were paying me by the day. The faster I get the job done, the faster they get their app. I can code it up in C in a year, or in Haskell in two months; which serves the user better?

      --
      There are reasons why democracy does not work nearly as well as capitalism.
      -- David D. Friedman
    6. Re:Programming for the human VM by smellotron · · Score: 1

      Caring about the users is fine, but last I checked, they were paying me by the day. The faster I get the job done, the faster they get their app. I can code it up in C in a year, or in Haskell in two months; which serves the user better?

      It depends on a lot of factors. If you follow the advice of "care about the users", then you should already know the answer.

    7. Re:Programming for the human VM by jcast · · Score: 1

      If you follow the advice of âoeget the job done the best possible wayâ, you'll also know the answer. Good programming advice is user-centric, because that's what supplied the selective pressure to allow it to evolve. But the only time I've every seen âcare about the userâ(TM) actually applied, it's a priori advice that contradicts sound development tradition. I trust the development tradition more.

      --
      There are reasons why democracy does not work nearly as well as capitalism.
      -- David D. Friedman
    8. Re:Programming for the human VM by Angst+Badger · · Score: 1

      Well, speaking from the point of view of management in this case, I sure wouldn't want it coded in Haskell, because Haskell programmers are a lot less common than C/C++ programmers and therefore probably more expensive and harder to find, and -- as management -- I want to make sure the code is going to be maintained, so obscure academic languages like Haskell are out, and the following possibilities remain: C++, C#, Java, and Visual Basic. To be fair, depending on what the app is, PHP, Perl, Python, and Ruby might be worth considering. And yes, I do know that there are other options that could be considered, but again, from a management point of view, what really matters is how easy is it to get decent coders who know Language X? It's safer to go with whatever is in common use.

      That aside, if it's going to take you six times as long to do it in C (or, more likely, C++) as in Haskell, you probably should consider learning and using, firstly, the STL, and secondly, any off-the-shelf libraries specific to the domain in question, of which there are likely to be several and which are almost always going to be cheaper to purchase and use than to pay someone to reinvent the wheel in-house.

      Whether this serves the user any better is an open question, but if you're going to invoke the POV of management, you get into an entirely different set of considerations, most of which are aimed at making developers cheaper and easier to replace.

      --
      Proud member of the Weirdo-American community.
    9. Re:Programming for the human VM by jcast · · Score: 1

      Nice way to jump horses in mid-stream. We no longer care about the user at all; now, we just care about management.

      I'm sorry; I don't care about management, or its fetishistic belief that it's always and everywhere better to hire a crappy programmer you can replace easily than a good programmer you might have to work harder to replace, or the twin belief that it's always and everywhere better to use crappy methodology (e.g. new/delete) that everyone understands than good methodology (e.g. GC) that management is irrationally afraid of. As a software house, your programmers and your methodology are your capital as much as your code, and you have to be willing to invest in them. That is why your management consultants call your programmers âoehuman capitalâ, not to demean them.

      Ideas like those you spout are believed by management not because they've been proven in practice, but because they are repeated by worthless trade magazines. Which makes believing them (let alone acting on them) more stupid, not less.

      --
      There are reasons why democracy does not work nearly as well as capitalism.
      -- David D. Friedman
  8. You misunderstand by Rix · · Score: 4, Interesting

    Using "MULTIPLYBY" instead of "*" is asinine, because both are equally descriptive. Putting a comment above the line telling people why you're doing it isn't.

    1. Re:You misunderstand by Anonymous Coward · · Score: 5, Informative

      The GP must have been confused by the example on Wikipedia, which a) wasn't literate programming and b) used a shitty made-up language where "multiplyby" was one of the operators. Literate programming is programming (in your favourite language) with a code-in-documentation approach instead of the usual documentation-in-code approach. So, for example, the flow of your literate program is defined by how best to explain what's happening to a human reader, rather than being constrained by the order the compiler requires. You run your literate program through a tool and it spits out compilable code or pretty documentation.

    2. Re:You misunderstand by Anonymous Coward · · Score: 0

      In COBOL's defense...

      Both are equally descriptive, assuming that you know the language/notation. One could argue that "X" or "x" or ">" or "." or "zwerble" are all equally descriptive of a multiplication operation.

      One of the ideas behind COBOL was that you could show business logic code to the PHB/customer and they had a chance of cluing in. Drawing on their four years of college getting a degree in English, it was decided to write code which was closer to that language than to math. For a mathematically competent readership, you wrote in FORmula TRANslator, not COmmon Business-Oriented Language.

      If you were weren't writing COBOL for that audience, you still could use the COMPUTE verb instead of MULTIPLY BY and put in your customary mathematical expressions.

    3. Re:You misunderstand by jwiegley · · Score: 3, Informative

      It is also the use of accurate and descriptive symbol names.

      Database database("data.txt");
      if (database.empty())

      is a lot more readable (i.e. literate) than

      DB d("data.txt");
      if (d.e())

      --
      I will never live for sake of another man, nor ask another man to live for mine.
    4. Re:You misunderstand by ruben.gutierrez · · Score: 2, Funny

      I like the idea of using "ZEROORMOREOFTHEPRECEDINGCHARACTER" rather than "*", myself.

    5. Re:You misunderstand by mrchaotica · · Score: 1

      You run your literate program through a tool and it spits out compilable code or pretty documentation.

      If it's truly a literate program, shouldn't the "tool that spits out pretty documentation" be a no-op, returning the source code unchanged?

      --

      "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

    6. Re:You misunderstand by HishamMuhammad · · Score: 1

      No, because it would return only the contents of the comments, usually in a format more suitable for straight reading (ie, a .tex file ready to be compiled into a book).

    7. Re:You misunderstand by PingPongBoy · · Score: 3, Funny

      Putting a comment above the line telling people why you're doing it isn't.

      I don't have to tell people why I do it. I do it for money. Well, sometimes for love and world peace, but that's rare.

      --
      Know your pads. One time pad: good for cryptography. Two timing pad: where to take your mistress.
    8. Re:You misunderstand by budgenator · · Score: 1

      Strange world we live in CS people hate COBOL because it's wordy rather than elegant, hate Perl because it can be terse to the point of being illegible, yet they put the bread on the table by hacking VB scripts embeded in an Excell "Database" that occasionally botches simple arithmetic.

      --
      Apocalypse Cancelled, Sorry, No Ticket Refunds
    9. Re:You misunderstand by NotZed · · Score: 1

      No it isn't.

      That might be more 'literate', but it isn't 'literate programming' at all. Most of Knuth's code for example, which is the pre-eminent example of literate programming (he invented it) - uses minimalist variable names.

      And FWIW if the second example was more realistic (i.e. just the variable name was abbreviated to d) I would find the it more readable - 'readability' is very subjective.

      --
      _ // `Thinking is an exercise to which all too few brains
      \\/ are accustomed' - First Lensman
    10. Re:You misunderstand by SilentBob0727 · · Score: 1
      And then we could spell out characters in regexes by their phonetic equivalents!

      pattern group ecks why zee comma endgroup zeroormoreoftheprecedingcharacter endpattern
      --
      Life would be easier if I had the source code.
  9. Adm. Hopper is ... by Anonymous Coward · · Score: 0

    Dead. Sad. But Knuth is knocking on that door now, too. I pre-ordered IV about 5 years ago on Amazon. It's a race between it and Duke Nukem (3D was my fav game) For/n/ever.

    Long Live COBOL !!

  10. Unit Tests are not wasteful by LargeWu · · Score: 5, Insightful

    The reason for his dismissive attitude of unit tests - that he knows exactly how all of his code works, and what impact a change will have - is exactly the reason you need them. In the real world, most programmers do in fact have to share their code with others. You're not always going to know the ramifications of refactoring a particular block of code, even if you wrote it yourself. And if you can keep all of that in your head at once, either your program is trivial, or you are some sort of supergenius. Now while I think the TDD guys are a little bit overzealous sometimes with their "100% coverage or die" attitude, unit testing is still a good habit to get into, regardless of what Knuth thinks.

    1. Re:Unit Tests are not wasteful by CodeBuster · · Score: 4, Insightful

      Unit tests, especially if written and organized in an intelligent fashion, can be of tremendous value in eliminating small coding errors that were not inteded but are bound to creep in if the project is large enough. If you are clever about your tests then you can usually inherit the same test multiple times and get multiple uses out a test or part of a test. If unit tests are not used then it is more likely that several small errors in seemingly unrelated classes or methods can combine in an unforseen way to produce nasty and unexpected emergent behavior that is difficult to debug when the whole system is put together. Unit tests will not make up for crappy design, but they will help detect minor flaws in a good design that might otherwise have gone undected until final system integration where they could be much more difficult to debug.

      I actually have a great deal of respect for Knuth, but I think that he is wrong about unit tests. Perhaps it is the difference between the academic computer scientist and the career programmer who admires the ivory tower, but is willing to make concessions in the name of expedience and getting work done on time.

    2. Re:Unit Tests are not wasteful by Jeff+DeMaagd · · Score: 1, Insightful

      I would agree. I was probably doing "unit tests" in programs before it was given a name. As far as I'm concerned, not doing them is a waste of time, I think I learned it the hard way, so I got in the habit of writing code to test code to make sure it was providing all the right results for several different circumstances. If I make changes, the test is re-run to be sure I didn't miss something.

      I think it's possible that this person, despite his earlier genius, has ceased to be as useful as his previous self. Genius is very often like that, they make a good body of work at one point in their life, and their previous success seems to alter them to the point that later work is suspect or just wrong. Sometimes it's ego, other times it's just being stuck in a mental rut, or whatever other reason there may be.

    3. Re:Unit Tests are not wasteful by ivan256 · · Score: 3, Insightful

      I think that the arguments about unit tests often go too far in one direction or the other. People either treat unit tests as a religion, or they disavow them entirely.

      People in the first group end up with a project full of tests where many are valid, many end up testing basic language functions, and many end up not helping due to oversimplication of behavior in the mocked interfaces.

      People in the second group end up missing simple problems that could have been caught had they exercised their code.

      Both groups waste a lot of time.

      Perhaps this is what you were trying to say when you said "TDD guys are overzealous". I think there are other problems with TDD. Namely that you can only use it when you don't need to learn how to solve a problem as you go... Most interesting programs fall into that category.

      Really, people need to use good testing judgement.

    4. Re:Unit Tests are not wasteful by seaturnip · · Score: 5, Interesting

      It actually doesn't sound to me like Knuth has heard of the term 'unit test' before this interview at all. It sounds like he thinks it means prototyping a function before writing the real version. Given that he likes to push his model of documentation-driven programming, I think he might be more sympathetic to unit tests if he understood that they can serve as a kind of formalized documentation.

    5. Re:Unit Tests are not wasteful by bunratty · · Score: 1

      He's still very useful and productive. He's currently churning out new material for The Art of Computer Programming. This includes the new MMIX 64-bit RISC architecture computer that replaces the aging MIX computer and new material on combinatorial algorithms.

      I agree with you on unit tests. I find them invaluable to ensure I have a piece of code working properly, and to ensure that I don't introduce errors when I make changes. Probably anyone that didn't write The Art of Computer Programming finds them useful as well.

      --
      What a fool believes, he sees, no wise man has the power to reason away.
    6. Re:Unit Tests are not wasteful by bytesex · · Score: 1

      I think you're probably not in a position to be speculating about the quality of the brains of Mr Knuth. Especially since you do not seem to want to even consider a universe in which unit testing does not provide anything useful to a project, but just wastes time. So you're not only prejudiced in this case, but you're also an assumer.

      Personally, I'm not convinced. I like to test stuff to see whether it conforms to my ideas of it, but I'm also humble enough to realize that other people have other ideas of it, and that generally, the stupidest end-user can make a bloody mess of anything. Unit testing is fine while you're in your ivory tower, ready to throw stuff over the fence. Ideally, a bunch of tech-savvy people from the side of the client should be writing /my/ tests. But they're usually not to be had. Leave aside the layers of management that will tell you or them that that's not possible/not going to happen.

      At the end of the line, writing your own unit tests is like the butcher judging his own meat. Even if he /does/ have the health and the taste of his clients at heart, it's still his own immune system and his own taste against that of this clients.

      --
      Religion is what happens when nature strikes and groupthink goes wrong.
    7. Re:Unit Tests are not wasteful by Anonymous Coward · · Score: 0

      I've found one of the greatest benefits of unit testing to be how easily I can change code and not worry about the changes. When I'm restructuring the code or adding new features, I can run the unit tests for that code and be pretty sure that I haven't destroyed anything in the process. The tests don't cover everything, of course, but they make sure I don't forget the basics and help show me where I screwed up instead of letting me discover it hours later when I no longer have any idea what's going wrong.

      Knuth, on the other hand, simply doesn't make bugs in the first place, so it should be no surprise that he has no use for a system which helps him find them more easily. (I'm not really kidding; the guy is currently offering $327.68 for any bug found in TeX and he's not particularly rich.)

      For us mere mortals, though, they're great.

    8. Re:Unit Tests are not wasteful by Jeff+DeMaagd · · Score: 1

      Call me prejudiced or whatever, but I think it's also likely that Knuth is prejudiced as well. Maybe he's just the perfect programmer that doesn't make any mistakes in assumptions, design or implementation, or that system he uses somehow catches all those problems in a more efficient manner.

      I really don't understand why "nothing needs to be mocked up". In just about any engineering and R&D field that I'm aware of, mockups of various kind are a necessary part of the process of developing a project. I just don't see what's special about software that somehow excludes itself from that sort of task.

      I do understand that ideally, unit tests should be done by someone else that's not the programmer of what's being tested, though a client would be rarely, at best, in a position to do them. I don't think unit testing really takes a lot of time if you don't get carried away.

    9. Re:Unit Tests are not wasteful by bytesex · · Score: 1

      Being the perfect programmer doesn't have anything to do with ones preference for unit tests or not. There are other methods (review, debug, lots of logging) and besides, unit tests may simply be too costly and time consuming. What remains is that it does take quite the super-person to be a programmer and a good test-designer at the same time, and even then we're still talking about the butcher judging his own meat. Given that, it's not surprising that a lot of people are adverse to unit testing. You don't have to be a superprogrammer for that.

      --
      Religion is what happens when nature strikes and groupthink goes wrong.
    10. Re:Unit Tests are not wasteful by Have+Brain+Will+Rent · · Score: 1

      Knuth pretty much is a super-genius so you can see why he might have the point of view attributed to him. It's informative to visit his home page... check out his CV http://www-cs-faculty.stanford.edu/~knuth/vita.html

      Better yet start here http://www-cs-faculty.stanford.edu/~knuth/index.html Take a look at the number of refereed papers and unrefereed papers. Whatever you do don't click on the link labeled "(don't click here)"!!!

      --
      The tyrant will always find a pretext for his tyranny - Aesop
    11. Re:Unit Tests are not wasteful by Jeff+DeMaagd · · Score: 1

      and even then we're still talking about the butcher judging his own meat

      That analogy really doesn't fit. The beauty of a routine to test modules of code is that the test is the same every time it is run unless the test is changed. A butcher might be a under a different set of circumstances every time the "test" is done.

      I don't think it's a complete substitute for other kinds of checking, don't get me wrong about that. But I'm just not convinced that it's a waste of time. For example, it's a good way to quickly test code that was changed against a known and stable set of conditions before you waste other people's time doing a code review of a code change that turns out to be faulty, but could have been caught with a simple run of a test.

    12. Re:Unit Tests are not wasteful by Bodrius · · Score: 1

      He's not wrong about unit-tests - he is just trivially (and pointlessly) right.

      He says unit-tests are rarely useful to him - and for the type of work and code he does, that is probably correct.

      You do not write unit-tests for yourself. You write unit-tests for Other People who deal with your code - even if that "other people" is you 12 months and a few unrelated projects later.

      You write them for when someone needs to modify your code, to do something that was not an original requirement, on a real world schedule and without the complete mental picture you (may) have had on your head when you wrote it.

      If you can afford to say that your requirements are complete, correct and immutable, and that any change after that can only be to fix a bug - then sure, there are better ways to make that first code bugfree.

      But if that is the case, you are either in academia, or your type of work has very specific requirements and needs different (formal) methods from most of the industry anyway.

      --
      Freedom is the freedom to say 2+2=4, everything else follows...
    13. Re:Unit Tests are not wasteful by dubl-u · · Score: 1

      I think there are other problems with TDD. Namely that you can only use it when you don't need to learn how to solve a problem as you go... I mostly disagree. With TDD, you just have to know at least one thing about the output of whatever you're creating. You assert that, then you make it pass. Maybe you refactor a bit now that, through implementation, you understand the problem better. Then you say, "What's the next thing this should do?" and start the cycle over.

      So I use it all the time when I'm figuring out what I'm doing, and in fact lean on it a lot to get me through tricky problems. It's especially helpful there because I can radically change key pieces and my tests tell me where I've gone wrong.

      There are two times when I don't use TDD. One, where it's some quick script. The other is when I'm trying something radical enough that I know I'll be throwing the code away.

      But for anything I intend to maintain and that I want to actually work, I love TDD + Refactoring. On teams where we've started that way from the beginning, our bug rates have been below one per developer-month, and sometimes well under that. TDD's not all you need for that, but it's a key piece.
    14. Re:Unit Tests are not wasteful by wrook · · Score: 1

      I haven't RTFA, but I actually don't see why unit tests and literate programming can't coexist. I've always thought of my unit tests as "documentation by example" rather than "documentation by explanation".

      Usually I set up my tests so that it's easy to see how something is intended to be used. For example, lets say I have a Time object and someone wants to see if they should use the Time object to represent dates. They look at the unit tests and see, "No, there are no tests implementing dates". So this gives them the idea that they should look elsewhere. If they can't find an appropriate class, then they can add a few unit tests to show that *now* the Time class should be used for implementing dates (or they can implement a Date class).

      I actually like the idea of literate programming. Or at least my impression of it ;-) Organize your code in an order that allows others to understand it. Then write a computer program to reorder it the way the computer wants to see it.

      But more and more, I've been finding that English (or any other natural language) is not the best language for describing computer programs. For one thing, since it is not parseable by the computer, I can't create an automated way to determine if the description is out of date with the implementation (mistakes happen).

      So, I've been experimenting with writing a meta-language for program description. Something that allows you to express *why* you did something, but that can be tied directly to the code so that you can tell if it's out of date. So far it's too early to tell if it's useful...

    15. Re:Unit Tests are not wasteful by smellotron · · Score: 1

      Unit tests, especially if written and organized in an intelligent fashion, can be of tremendous value in eliminating small coding errors that were not inteded but are bound to creep in if the project is large enough [emphasis mine].

      If unit tests help to eliminate what was not intended, what will save us from the small coding errors that were intended?

    16. Re:Unit Tests are not wasteful by symbolic · · Score: 1

      In addition to this, one of the greatest values of units tests lie in regression testing. It's not enough that the code works now, but whether it still works after some changes have been made.

    17. Re:Unit Tests are not wasteful by bbtom · · Score: 1

      Absolutely true. One situation where unit testing is even more important is when writing in dynamically-typed scripting languages like Ruby and PHP. I tend to find that if I'm writing a small Java class, I don't really need to write tests, since I can rely on the compiler to pick up any type flubs I make - while in scripting languages, it's very useful to have the tests to make sure one doesn't screw up the typing.

      In Ruby, I've been getting into the 'BDD' side of things on an open source project - using RSpec. It's pretty cool, actually. You write your tests so that they describe the behaviour (using brackets rather than do-end so that non-Ruby folks can read it):

      describe "Cars" {
      it "should have four wheels" { car = Car.new; car.wheels.should == 4 }
      it "should have a reverse gear" { lambda { car = Car.new; car.reverse_gear! }.should_not raise_errors }
      it "should have reclinable seats" { car = Car.new; car.driver_seat.recline!; car.driver_seat.location.should == :reclined }
      }

      What's cool about this is that the code describes what the class should do and is a lot more readable than the standard xUnit tests (is it assert_equal(expected, actual) or assert_equal(actual, expected)?), it forces you to write tests for the actual behaviour - the things that the code is doing! - and it also makes a really pretty HTML output that has each description and behaviour listed - coloured with red (if the test is written and fails), yellow (if the test hasn't been written) or green (if it works). The BDD approach is extremely hyped up and trendy in the Ruby community, but is actually well worth pursuing. Especially now JBehave exists.

      --
      catch (HumourFailureException e) { e.user.send("You, sir, are a humourless idiot."); }
    18. Re:Unit Tests are not wasteful by ivan256 · · Score: 1

      So I use it all the time when I'm figuring out what I'm doing, and in fact lean on it a lot to get me through tricky problems. It's especially helpful there because I can radically change key pieces and my tests tell me where I've gone wrong. Your tests don't have to be the starting point for you to gain that benefit. I didn't say "don't write tests". I said that it doesn't make sense to start with tests when you understand the problem, but don't understand what the solution looks like yet.

      That also doesn't mean I'm entirely opposed to test driven development. In fact there are some situations where it is essential. For example when you are outsourcing much of your development, or when you have a straightforward problem with thorough design completed before you begin implementation.
    19. Re:Unit Tests are not wasteful by Noble+Kiwi · · Score: 1

      Knuth does not seem to understand the value of unit tests. The main value of unit tests is to serve as a mental aid.

      They help you define and communicate tasks in very small chunks, which is necessary for pair programming. They help you define and document the assumptions made by sections of the code. They help you modify code with confidence as you get better ideas, in two ways: they lead you to make an extremely modular design, and they tell you what assumptions you've just violated in the code that calls what you just changed (like a debugger specially tuned to your app).

      Unit tests off-load error-prone consistency checking and documentation from your brain and onto the computer. They are the substitute for literate programming that actually works in real life. They are not, however, a substitute for real QA.

      http://flashburrito.com

    20. Re:Unit Tests are not wasteful by NotZed · · Score: 1

      Mental aid? But that is exactly the issue that literate programming addresses - so it would obviously be totally pointless for Knuth. Defining and communicating tasks in very small chunks is precisely what it is for.

      Anyway - although i've had grand ideas to use unit tests and even written quite a few - in the end they've never actually been all that useful. Usually nobody but the original author uses them anyway because discipline is lacking, and what they test will usually show up pretty fast in other testing anyway.

      It's a good idea, but like documentation it is usually to hard to keep them up to date - e.g. when you actually want the behaviour to change you have to go and fix all of the tests. Which actually means re-testing the tests. You spend more time maintaining your tests than writing the code, for very little practical benefit.

      --
      _ // `Thinking is an exercise to which all too few brains
      \\/ are accustomed' - First Lensman
    21. Re:Unit Tests are not wasteful by Deliveranc3 · · Score: 1

      I wish to subscibe to your news-letter.

    22. Re:Unit Tests are not wasteful by Noble+Kiwi · · Score: 1

      Yeah, I think you are right: unit testing is actually a non-trivial skill (a bit like the kind of writing needed for literate programming, perhaps?), and requires a lot of discipline and practice. As "lite" as unit tests are, they're still too much for most shops.

      I heard it said ages ago, when structured programming came out, that before structured programming, good programmers wrote good code and bad programmers wrote bad code; and after structured programming, the same programmers wrote good code and the same programmers wrote bad code.

      Speculation: there is a certain way that your brain has to represent things in order to write good, solid code. Fancy programming techniques provide aids for doing that. But if a person's brain doesn't work that way, the fancy programming techniques have little effect.

    23. Re:Unit Tests are not wasteful by dubl-u · · Score: 1

      . I said that it doesn't make sense to start with tests when you understand the problem, but don't understand what the solution looks like yet. Again, I disagree. I do it all the time, and prefer it except for throwaway code. It may not make sense to you, but that's different than it not making sense.

      when you have a straightforward problem with thorough design completed before you begin implementation. Sure, you can use it there, but that is not its strength. Go read a book, any book on TDD. Any of them will tell you that it is not just a testing technique, it's a design technique.
    24. Re:Unit Tests are not wasteful by Anonymous Coward · · Score: 0

      I find that TDD provides the greatest help when you need to learn how to solve a problem as you go. It allows me to speculate quickly. For example, the other day I had to solve a problem that I guessed I could solve using reflection and code generation, but I wasn't sure if I understood what was possible. So I wrote some tests to verify my understanding. My understanding proved to be incorrect, and with a few further tests I found a solution. With this knowledge I then wrote the rest of the code (with tests!). If you don't use a testing framework, what do you do? Do you write a single executable and hope it works? Do you develop a new executable for every idea? Do you evolve one executable? With a test framework its like having a hundred main() functions in one executable. I can take hundreds of guesses. Best of all, if I write a test that fails, because my understanding was wrong, I can leave it in there, after renaming it something like "VerifyThatSomeOsFunctionDoesNotInFactWorkLikeIExpected"...

    25. Re:Unit Tests are not wasteful by ivan256 · · Score: 1

      If you don't use a testing framework, what do you do? Do you write a single executable and hope it works? Do you develop a new executable for every idea? Do you evolve one executable? With a test framework its like having a hundred main() functions in one executable. Why would you assume that simply because somebody didn't write tests before implementation that they can't use a testing framework? If you are writing in a language or for an execution environment where a quality testing framework is readily available, you can use that framework whether or not your development is test-driven. You'd be a fool to write your own. For environments where there isn't a "framework" there are many techniques that have been used for ages to test small portions of your code in the scope of a larger project without unmanageable development overhead. There are too many to enumerate here, and if you are sufficiently skilled in the art you should know what they are already anyway. (Unfortunately, many zealots for a particular methodology don't have a solid understanding of the alternatives, even though there is more than one right way to develop software.)
  11. and, arguably, one of the founders of open source? by xx_chris · · Score: 2, Informative

    No, that isn't arguable.

    Tex got started in 1977 after Unix (1974), well after SPICE (1973), and about even with BSD.

  12. His comment on unit tests by free+space · · Score: 2, Interesting

    ...the idea of immediate compilation and "unit tests" appeals to me only rarely, when Iâ(TM)m feeling my way in a totally unknown environment and need feedback about what works and what doesnâ(TM)t. Otherwise, lots of time is wasted on activities that I simply never need to perform or even think about. Nothing needs to be "mocked up."


    I'm not sure, but I think he's talking personally about his own work on his code. Remember that he comes from an era where people had the goal of mathematically proving that the code is indeed correct. He isn't necessarily doing this now but my persaonal guess is that he prefers statically checking the code to checking a running program. In certain kinds of mathematic/scientific applications this could make sense.
    1. Re:His comment on unit tests by a66at · · Score: 2, Interesting
      No, he prefers debugging (which is dynamic checking) over systematic unit-testing. See:

      That simulator includes debugging features like the ones I found so useful in Ed Satterthwaiteâ(TM)s system for ALGOL W, mentioned earlier. I always feel quite confident after checking a program with those tools.
    2. Re:His comment on unit tests by mollymoo · · Score: 1

      Given the program in question was written on punch-cards (and worked on the second compile), I wouldn't be so sure that those debugging tools are quite the same as the modern interactive debuggers we all know and love.

      --
      Chernobyl 'not a wildlife haven' - BBC News
  13. Bug checks by symbolset · · Score: 1

    He's written some checks. Few of them are cashed - (pdf) On page 10 of this document he explains one.

    --
    Help stamp out iliturcy.
  14. Documentation is the source by CustomDesigned · · Score: 5, Informative

    So basically it's the same as the XML comments you can put in your .Net or Java code to create JavaDocs, or whatever they are called in .Net, based on the comments in the code? Not quite. In Javadoc (or the C/C++ equivalent) the C/Java code is the source, and documentation is generated from that. In literate programming, the documentation is the source, and it has code snippets, like you would see in a Knuth textbook.


    The snippets have markup to indicate when some snippet needs to come textually before another to keep a compiler happy, but mostly this is figured out automatically. But in general, the resulting C code is in a different order than it appears in the source documentation. For instance, the core algorithm might come first, with all the declarations and other housekeeping at the end. (With documentation about why you're using this supporting library and not that, of course.)

    1. Re:Documentation is the source by Compholio · · Score: 1

      Hmmm, I must explore this - awk scripts to strip LaTeX from comments are not nearly so fancy.

    2. Re:Documentation is the source by rhendershot · · Score: 1

      >>code is the source, and documentation is generated from that

      not true. the documentation are separate markup to the source. And, if not maintained, suffer all the problems of literate programming.

  15. Re:and, arguably, one of the founders of open sour by heffrey · · Score: 1

    Are you saying that TeX is the first thing that Knuth wrote?

  16. if i had a big brain like he does... by Anonymous Coward · · Score: 0

    i wouldn't waste time on unit tests, either.

  17. He's right by Brandybuck · · Score: 4, Insightful

    He's right about unit tests... sort of. Just as most coders shouldn't be designing interfaces, most coders don't know how to test. It can often be more work writing the unit tests than writing the code.

    If you have a function that multiplies two integers, most coders will write a test that multiplies two numbers. That's not good enough. You need to consider boundary conditions. For example, can you multiply MAX_INT by MAX_INT? MAX_INT by -MAX_INT? Etc. With real world functions you are going to have boundaries up the whazoo. In addition, if you have a function that takes data coming from the user, check for invalid cases even if another function is validating. Check for null or indeterminate values. Write tests that you expect to fail.

    --
    Don't blame me, I didn't vote for either of them!
    1. Re:He's right by Brandybuck · · Score: 3, Insightful

      Conclusion: Knuth is somewhat right, in that most unit tests written by coders are useless. But unit tests themselves are not.

      --
      Don't blame me, I didn't vote for either of them!
    2. Re:He's right by clap_hands · · Score: 4, Interesting

      The thing about unit testing is that it's subject to the law of diminishing returns. A simple test of the basic functionality gets you a lot for minimal effort. Writing dozens of carefully chosen tests to examine boundary conditions etc. gives you a little bit more, but for a great deal more effort. Whether or not it's worth it depends very much on the situation and the nature of the code you're writing.

    3. Re:He's right by sydneyfong · · Score: 1

      I also have this doubt about unit test: If the coder is already aware of the possible failures, then he should be fixing the code instead of writing a test.

      And after a "unit" of code is written correctly, it shouldn't be changed a lot. Any big changes means a change in semantics, which means the original unit tests are useless anyway.

      --
      Don't quote me on this.
    4. Re:He's right by Anonymous Coward · · Score: 0

      In the hardware world, that's why there are verification engineers; people who do not write any RTL but are aware of the corner cases. What Knuth says has some relevance here. In hardware design, standalone block-level tests are used to eradicate the most obvious bugs. Also these tests are extremely fast. But the most difficult bugs in my experience have been discovered in tests that are more on the top-level module level or even at the full-chip level.

    5. Re:He's right by clap_hands · · Score: 1

      There's a whole school of thought that advocates refactoring as one of the primary activities in writing software. The purpose of unit tests is then to give you confidence that you haven't changed the semantics.

    6. Re:He's right by jordyhoyt · · Score: 1

      It can often be more work writing the unit tests than writing the code. Yeah, I think this underscores one of the main advantages of test-first coding. Once you've written all the tests, you have a really good idea how to go write the actual code and that process will be much quicker and easier.
    7. Re:He's right by Xarin · · Score: 1

      Boundary conditions are nice but first you need to at least make sure that each line of code is executed first. I once read about a program that ran for years without a problem and then after many years a line of code finally was executed and the process crashed. Before getting fancy in testing, one should first weed out simple blunders and to do that, one needs to make sure each line of code actually runs. The same holds true for a GUI, every button / menu item needs to be executed. When the end user clicks on something and the program crashes, the product loses a lot of credibility quality wise no matter how many boundary conditions or code paths are tested. After getting this far, one can then start testing boundary conditions. One also needs to test each use case including the failure modes but once again all the very simple use case success scenarios need to be tested since the user will think that if one can't get the simple things correct then things are going to get a lot worse.
      Use cases also help protect the schedule, as defects will continuously be found and fixed instead of having a big bang at the end. One of the most important aspects of writing use cases, is the questions they generate such as 'What happens if ...?', 'Is null treated the same as an empty String?', 'Does case matter?', 'Why does it take so long?', 'Why does this work on Windows but not UN*X'?', and the very important, 'I made some changes did I break anything?'.

    8. Re:He's right by jzap · · Score: 1

      Yes, he's right in his own context -- single programmer.

      In a multi-programmer environment, robustness is king. That's robustness as in maintainability. That comes from readability (comments and style) and, yes, from unit tests, too.

      Maintainability trumps performance to a large degree. With a large body of code, it's pretty much guaranteed that some J Random Hacker will have to dig into it to fix a bug or add a feature. The chances that Mr Hacker will break something are greatly reduced by an existing body of unit tests. Plus, JR probably sleeps better, too! --jzap

    9. Re:He's right by Anonymous Coward · · Score: 0

      It can often be more work writing the unit tests than writing the code. And it is much more work trying to fix a bug in production, on the spot, than writing the unit tests earlier that would have caught it.

    10. Re:He's right by shutdown+-p+now · · Score: 1

      If you have a function that multiplies two integers, most coders will write a test that multiplies two numbers. That's not good enough. You need to consider boundary conditions. For example, can you multiply MAX_INT by MAX_INT? MAX_INT by -MAX_INT? Etc. With real world functions you are going to have boundaries up the whazoo. In addition, if you have a function that takes data coming from the user, check for invalid cases even if another function is validating. Check for null or indeterminate values. Write tests that you expect to fail.
      It's precisely because of this that we make better and better automated test generators now. With them, you do precisely that - write a function that multiplies two integers - and then run the generator on it, and it comes up with all sorts of creative inputs for that function that are likely to break it, by analyzing the code inside.
    11. Re:He's right by tknd · · Score: 2, Interesting

      If the coder is already aware of the possible failures, then he should be fixing the code instead of writing a test.

      The purpose of a unit test testing for failure cases is not to detect places where the code has issues, but to ensure that the code performs as expected given the initial requirements/specifications. When people talk about "failure cases" they mean that they expect the code to return some sort of exception, not that they expect the code to fail in how it operates.

      For example consider that a block of code is required to perform a "division" operation. A unit test case to test for a failure case would be one that provides a denominator of zero. In this case we can expect that the code will throw a divide-by-zero exception or return a special error code rather than halt the entire program.

      And after a "unit" of code is written correctly, it shouldn't be changed a lot. Any big changes means a change in semantics, which means the original unit tests are useless anyway.

      Not necessarily. An easy example is a developer writes division function and test cases are written to ensure it operates as expected. A month later we determine that we need to improve performance of the software that utilizes the division function, and the current division function performs poorly. So given the unit test cases, we can re-implement an optimized version of the function, and testing for accuracy of the function is almost free.

      Another example is a developer starts working on a big software project. 6 months later he conveniently leaves the company without notice and his portion of the project is only 50% complete. Would you rather have 50% of code that you are not sure works or 25% of code that you are not sure works, but 100% of the unit test cases required for the existing code to tell you whether or not it works?

      An even more useful example is dealing with bugs. You receive a bug report on some software that performs some function. You eventually find the cause of the bug in a particular function, but realize that it requires a specific state of the system. You fix the bug in the software but it results in "ugly code" that at first glance is unexplainable. How should you ensure that this code is not modified accidentally? A unit test case of course! This is a good example for very special bugs that are the result of hardware issues or other software systems that are out of your control.

      There are valid argument against unit test cases (and automated testing in general). One argument is that in order to do automated testing, you are required to write more code for the test cases. This is a problem because now you have new code that does not have test cases for itself and can have bugs. So if the test case is written incorrectly, then it may point out that the original code is working incorrectly when in fact the test case is the culprit.

      Another argument (which is what I think you were trying to say) is that when the specifications for the code change, so must the test cases. This can potentially double the maintenance work required when updating the software.

      So I don't think that every piece of code needs a unit test case. But for code that will be reused considerably and is closer to the foundation of your project, you probably should make unit test cases.

    12. Re:He's right by cgranade · · Score: 2, Insightful

      Unit testing is often about detecting regressions, and so writing a unit test to catch some failure that you found and fixed can often be very helpful. To borrow the MAX_INT * MAX_INT example above, if after getting that case to work right and writing a unit test to confirm it, you decide to improve the performance of your integer multiplication routines (silly, I know... imagine a better example if you have to, like that they're matricies and you're implementing Strassen's Algorithm), then the unit test can tell you if you introduced bugs back into your code.

      --

      #define DRM chmod 000

    13. Re:He's right by Anonymous Coward · · Score: 0

      He's right about unit tests... sort of. Just as most coders shouldn't be designing interfaces, most coders don't know how to test. It can often be more work writing the unit tests than writing the code.

      If you have a function that multiplies two integers, most coders will write a test that multiplies two numbers. That's not good enough. You need to consider boundary conditions. For example, can you multiply MAX_INT by MAX_INT? MAX_INT by -MAX_INT? Etc. With real world functions you are going to have boundaries up the whazoo. In addition, if you have a function that takes data coming from the user, check for invalid cases even if another function is validating. Check for null or indeterminate values. Write tests that you expect to fail. Wow... that takes me back to my intro C programming course years ago. Prof wanted us to write a program that would multiply two numbers together and print the result. I finished mine, he wandered over and tried (for the inputs):

      2 and 3, which gave him 6.

      100 and -10, which gave him -1000.

      5 and ^^^^, which gave him... garbage. He told me to go back and fix it.
    14. Re:He's right by Anonymous Coward · · Score: 0

      It's true that most unit tests do not thoroughly cover every boundary condition. Most of the time they don't need to.

      The unit tests are simple, fast, developer written tests that show the code works as the developer intended. You still want to use more traditional testing from a QA team and beta tests.

      They are supposed to say "here, this piece of code works on my machine and your machine and the build server." There could still be all kinds of integration bugs, boundary conditions, UI bugs.

      They don't catch everything, but they do find some problems that would otherwise be missed and they can speed up the testing process.

    15. Re:He's right by Anonymous Coward · · Score: 0

      Just as most coders shouldn't be designing interfaces...

      And who should, a pie-in-the-sky architect? Welcome to 2008. "Coders" are no longer neaded in most fields. Modern software developers should understand testing at a unit level (but not necessarilu functional or integration level) as well as good design.

    16. Re:He's right by rawler · · Score: 2, Interesting

      Testing is not a waste of time. Writing unit-tests, is. A better use of that time could be learning about http://en.wikipedia.org/wiki/Design_by_contract, and possibly a language that implements it. (Dare I suggest http://en.wikipedia.org/wiki/D_(programming_language) ?)

      The problems with unit test as someone already pointed out, is that writing small tests helps you verify the really simple things is relatively quick and easy but, those mistakes are easy to detect and find anyways, even a decent compiler/lint-tool will find many of them for you.

      Most of the really tricky problems comes in the interfacing between units and no unit tests will help you here.

      Design-by-contract, on the other hand, can.

      First of all it requires you to give really clear formal declaration on each component and how it may be used. (A contract) This contract can be used to automate testing of all the exotic, but allowed, corner-cases your implementation may have missed.

      The contract implemented by classes and function will furthermore function as a REALLY clear documentation, spelling out exactly what the allowed input and expected output is.

      Finally, in a design-by-contract-enabled language, you can choose to turn on debugging at run-time, and enable all kinds of tests, including input/output validation, class invariants and other really handy tests that allows you to test AND debug your entire system at once, but still at a highly granular level.

      Design-by-contract will in no way prevent you, or discourage you, from writing test-code (in fact, it encourages it), but it can help you spend your time writing those tests more sensibly, and drive your code in much more life-like scenarios.

      All in much less time spent, and much more return than the traditional ways of unit-testing.

    17. Re:He's right by Anonymous+Brave+Guy · · Score: 1

      And that school of thought is fundamentally unsound, because it relies on the automated unit tests to find any change in behaviour, but you'll never get near 100% coverage for most practical projects. There was some good discussion of unit testing and TDD over on the programming reddit recently, where the brave author of a somewhat inflammatory blog post then tried to defend it against several critics.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    18. Re:He's right by clap_hands · · Score: 1

      Some people's attitude is "just change the code, no need to think too hard about correctness, your tests will catch it if you get it wrong." That's a bit foolhardy. As you point out, there's every chance the tests won't catch all the problems you might introduce. You always have to use your brain. Still, unit tests can catch mistakes and give you evidence that you haven't changed the semantics.

    19. Re:He's right by dfj225 · · Score: 1

      I also have this doubt about unit test: If the coder is already aware of the possible failures, then he should be fixing the code instead of writing a test. I've often thought much the same thing. It seems to me that if the same person is writing the code and the unit test, there is a high chance that errors will still slip through the system. If I write a function and forget to check for null, what are the chances that I'll remember to write a unit test that checks for failure with null arguments?
      --
      SIGFAULT
    20. Re:He's right by scotch · · Score: 1
      Refactoring is inevitable. If you work with me, I expect you to write unit tests to show that you've thought about the behavior at boundary conditions, documented those behaviors, and tested those behaviors. When refactoring becomes necessary, the fact that you've moved on to another job become less of an issue.

      If you can't do this, and you're not some kind of knuth-like super-coder, I really don't want to work with you. You make my job harder. Unit testing is really not that hard. The idea that if you can't do 100% coverage then the activity is worthless is a fallacy.

      BTW, I think you an I agree - this is more directed at the grandparent.

      --
      XML causes global warming.
    21. Re:He's right by Anonymous+Brave+Guy · · Score: 1

      BTW, I think you an I agree - this is more directed at the grandparent.

      I wrote the grandparent post, and I suspect you and I would agree as well. I'm not criticising unit tests: on the contrary, both my personal experience and the more formal studies I've seen tell me they are a solid, effective way of improving quality. What I'm criticising is the idea that unit tests are some sort of 100% reliable safety net, such that you can refactor away without risk as long as you have them; this is a common claim by TDD advocates and was the allusion I was concerned about in the post I originally replied to above.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    22. Re:He's right by scotch · · Score: 1

      Ok, yeah - we agree - unit tests just help - you still need to use your brain when you do these activities. Thanks

      --
      XML causes global warming.
    23. Re:He's right by SanityInAnarchy · · Score: 1
      I think I get the basic concept of design-by-contract, but I don't really get how it's different than unit tests, or why it's superior.

      Design-by-contract will in no way prevent you, or discourage you, from writing test-code (in fact, it encourages it), but it can help you spend your time writing those tests more sensibly, and drive your code in much more life-like scenarios. Yeah, interesting. How?

      Most of the really tricky problems comes in the interfacing between units and no unit tests will help you here. No, then you have integration tests, and functional tests -- which are essentially higher-order unit tests.
      --
      Don't thank God, thank a doctor!
    24. Re:He's right by Anonymous Coward · · Score: 0
      I think the basic point behind design-by-contract is that you aren't just throwing out something like:

      int multiplyTwoInts(int a, int b)

      and then have to Do The Right Thing(TM) in response to any kind of input, but rather specifying something more like:

      // a is a number from 0 to 9.
      // b is a number from 0 to 9.
      // Returns a number from 0 to 81.

      int multiplyTwoDigits(int a, int b)


      Now, you can see how it's a lot simpler to design a test for multiplyTwoDigits() than multiplyTwoInts(), because the first method does a lot less, and it's defined right in the contract.

      And heck, you can even get an automated tool to do some formal reasoning on such a contract, to design tests and even perform optimizations.

      It's the sort of thing Ada was famous for, in particular. C-derived programming languages tend to leave a lot of the assumptions and restrictions on valid input implicit, rather than rigorously defined in the language's types. (Ada, by contrast, would let you define a type directly that could only take values from 0..9, or 0..81.)

      No, then you have integration tests, and functional tests -- which are essentially higher-order unit tests. I don't think that word means what you think it means. Unit testing is a very specific kind of testing: testing of isolated units. That's where the name comes from. You can't say something is a "higher-order unit test," because that's a whole different ball game.

      One of the key aspects of integration testing is that you are no longer writing tests only for functionality created by you or someone in your immediate organization. That definitely adds an additional dimension to the problem of how to do good testing.
    25. Re:He's right by Brandybuck · · Score: 1

      And do you actually use such a generator on every function you write? No, I didn't think so.

      --
      Don't blame me, I didn't vote for either of them!
    26. Re:He's right by nuzak · · Score: 1

      DBC is actually a perfect complement to unit testing. I daresay you could call it unit testing that's been refactored into your code, so that you assert your test invariants precisely once. It's also why I'm a fan of static typing, since you don't waste time checking what the compiler does for you.

      The real force multiplier that DBC gives you, however, is to think about invariants. Classes are all about their invariants: the definitions of how their member data interrelates and how operations affect (and very importantly how they do NOT affect) member data. Any fool can stick asserts into functions, but I've found that if I can't come up with good class invariants, the design of the class itself is dubious. So DBC is ultimately not just about sprinkling asserts all over, but about keeping you honest about your high level OO design as well.

      --
      Done with slashdot, done with nerds, getting a life.
    27. Re:He's right by nuzak · · Score: 1

      This post was actually meant to be a reply to your post. DBC works well with unit tests, because one test can tickle all the different DBC assertions in ways you might not have forseen. Not terribly compatible with mocks though, which often do violate class invariants in the name of faking -- but it's sometimes nice to discover which assumptions your mocks are making that aren't necessarily good ones.

      GNU Nana is a pretty nice way to add DBC-ish stuff to C and C++ code -- beats the pants off just using assert.h/cassert. It's ancient, but it's really an overlooked gem.

      --
      Done with slashdot, done with nerds, getting a life.
    28. Re:He's right by dubl-u · · Score: 1

      I also have this doubt about unit test: If the coder is already aware of the possible failures, then he should be fixing the code instead of writing a test. That's a false dichotomy. You should do both.

      Every good programmer manually tries out bits of code they have just written so that they can be sure it works. Unit tests just capture that manual testing and automate it, so that you're sure the code works not just today but tomorrow, next month, and next year.
    29. Re:He's right by dubl-u · · Score: 1

      And that school of thought is fundamentally unsound, because it relies on the automated unit tests to find any change in behaviour, but you'll never get near 100% coverage for most practical projects. You might not. I do, though.

      If you start a code base with TDD and stick with it, though, it's pretty easy to get strong effective coverage. And both my gut feel and the stats from my teams suggest that unit testing is effectively free. Time spent on writing and maintaining tests is made up for in time saved through reduced debugging and reduced cost of change.

      Getting 100% coverage is something I never care about, as there's some stuff that is rarely worth it, like simulating disk failures. But 95% coverage is certainly doable, and I've done it on projects up to the 5 developer-year size, and a team of mine is doing it now on a web project serving 3 million users a month that has released on average twice a week over the last year.
    30. Re:He's right by dubl-u · · Score: 1

      What I'm criticising is the idea that unit tests are some sort of 100% reliable safety net, such that you can refactor away without risk as long as you have them; this is a common claim by TDD advocates [...] If some TDD advocates say that, they are wrong. For near-riskless refactoring, you also need good acceptance tests.

      Unit tests prove that the program does what the programmers think it should. Acceptance tests prove that a program does what the people using and paying for it think it should. Some people, like me, think automating the acceptance tests is well worth it. Others don't, and are happy with the level of safety full unit testing gets them.

      Either way, the claim that strong tests mean riskless refactoring is almost tautological. If you refactor and break your system in some way that the tests don't catch, then that means you don't have everything tested. That probably means you added functionality without adding a test first, which means you're not fully doing TDD.

      In practice, nobody tests quite everything, and nobody starts knowing how to test everything anyhow, so part of learning good TDD is learning how to make the risk trade-offs. As long as they're doing some short-cycle iterative process, teams learn this pretty gracefully; when you get hit with a production bug, you say, "Oh, we missed a test. Can we avoid that in the future?" and go from there.
    31. Re:He's right by dubl-u · · Score: 1

      It seems to me that if the same person is writing the code and the unit test, there is a high chance that errors will still slip through the system. If I write a function and forget to check for null, what are the chances that I'll remember to write a unit test that checks for failure with null arguments? There are a couple of common fixes for this problems in shops that like unit testing.

      One is doing test-driven development. If you write the test before you write the function, you are much more likely to write good tests.

      Another is pair programming. If you are there with another developer, they will hopefully remind you. And by reminding you, you'll learn, and remind other pairing partners in turn. Often we'll play a game where one person writes a bit of test and another makes it pass. Then the second person writes a bit more test and hands it back to the first. This forces you to think about the code from both sides, which is both fun and effective.

      If you hate pairing, then code reviews are another option. Because the feedback comes later, people are less likely to apply it, but it's still much better than solo coding.
    32. Re:He's right by smellotron · · Score: 1

      but you'll never get near 100% coverage for most practical projects.
      You might not. I do, though.

      What do you use to measure your coverage? 100% of execution paths taken or 100% of lines executed is not sufficient to prove correctness.

    33. Re:He's right by SanityInAnarchy · · Score: 1

      Unit testing is a very specific kind of testing: testing of isolated units. That's where the name comes from. And an entire program can be seen as an isolated unit. Conversely, the smallest of the "isolated" units you try to test are still going to be relying on something -- even if it's just the compiler and the language -- so you are always testing that something as well.

      One of the key aspects of integration testing is that you are no longer writing tests only for functionality created by you or someone in your immediate organization. Which is exactly my point: You can never write tests only for functionality created by you or someone in your immediate organization, unless you are hand-coding assembly for your very own CPUs -- and you're smelting the metal for your own cases, etc.

      Now, you might only be considering your own software when creating those tests, and that's fine. That's encouraged, especially when most of these units will have been tested individually already.

      Let me put it this way:

      def multiply_two_ints(a, b)
        a * b
      end
       
      def raise_int_to_positive_integer_power(a, b)
        result = 1
        b.times do
          result = multiplyTwoInts(result, a)
        end
        result
      end
       
      def factorial...
      Been awhile since I had to do much mathematical code, but I think that demonstrates what I'm talking about: You simply do not have an isolated unit to test there. You could always mock up a multiplyTwoInts for that specific purpose -- one with a preset table of values, and an expectation of being called in a certain order -- but it's simpler to just write a "unit" test (that's really an integration/functional test in disguise) for raise_int_to_positive_integer_power.

      And by the way, multiply_two_ints assumes the * operator does what it's supposed to.

      No, I would never use function names like that -- but I'd also never write that function anyway.

      So by the time you get to "When the user adds something to their shopping cart, it should persist there and update the total when they check out..." etc etc... You're still ultimately testing one unit (the entire app, maybe specifically the routing code), with the assumption that all the other units do what they're supposed to.
      --
      Don't thank God, thank a doctor!
    34. Re:He's right by dubl-u · · Score: 1

      What do you use to measure your coverage? 100% of execution paths taken or 100% of lines executed is not sufficient to prove correctness. In this case, I was talking about LOC coverage, which is the common metric used. I agree that's not sufficient to prove correctness, but in my experience it's plenty good for easy refactoring and low bug rates. For recent projects, it has been somewhere under one bug in production per developer-month, and often much lower than that.

      That's plenty good for consumer and most business apps. If I were doing life-critical development, I'd add more pratices, though.

      As with any metric, though, you shouldn't use it as the sole driver of decisions. One should first strive for good tests, and only use a coverage metric to look for missed spots. If a manager uses a coverage number as part of an incentive plan or employee evaluation, it's an easy metric to hack by writing garbage tests that don't test anything.
    35. Re:He's right by Anonymous Coward · · Score: 0

      I do that boundary-conditions testing in any case. I used to do it by manually putting stuff in the gui of the running program, or even creating a little extra gui to do it with. Now I write unit tests instead. I actually find it to be faster than my old way, even without considering the ability to re-run them.

      I'm no zealot about it, I still don't do test-first or insist on 100% coverage of obvious code...and I try to make the code as obvious as possible. But whatever testing I would have done anyway, I do with unit-tests, and save a lot of time.

    36. Re:He's right by shutdown+-p+now · · Score: 2, Informative

      It's integrated into my IDE (VS2008 Team Edition), so I have no excuse not to - it's just a couple of clicks.

    37. Re:He's right by elronxenu · · Score: 1
      Quite right.

      Unit tests aren't of much worth to Knuth because he writes the code once, tests it whichever way he wants to, and publishes the code in his book. Once it's published he doesn't need to change it ever again, or perhaps only if he brings out a new revision of the book - in which case he can test the new version.

      Code (subroutines, functions, methods) in the real world need to interoperate with a lot of other code - calling code and called code. In the real world, code changes are always occurring and so it is necessary to re-test if changed code still works (unit test) and if the contracts between two pieces of dependent code are still followed (probably also done as part of a unit test). Automating unit tests by writing code for them means that the re-testing can be done with minimal re-work.

    38. Re:He's right by dossen · · Score: 1

      Just curious, how would you handle developing in a framework, where your non-trivial functionality is hard/impossible (within the constraints of the real world - i.e. you can't discard/rewrite major pieces of the infrastructure, you have to live with them) to unit test? An example that I'm familiar with is Microsofts Sharepoint. Given enough time one could either muck up the entire environment - something that would be very brittle (and another huge block of code to maintain), or one could script the creation of a virginal environment for each testcase - but that could add several minutes of setup time to each test case - not really what you want in a large project.
      Don't get me wrong, I think unit tests are nice when they work, but unless you've got some tricks I haven't seen, you need to be able to control the inputs and capture the output of the unit you are testing. and unless you are building from scratch, it might be difficult to retain that level of control over units of a meaningful size (larger than "trivial" and smaller than "the entire system").

    39. Re:He's right by rawler · · Score: 1

      Actually, DBC is not at all about sprinkling asserts into your code. DBC is about modelling your interfaces between code components very carefully.

      The asserts only tests that your code actually fulfills the contract (while themselves being contracts). Also, ideally your assertions should not be sprinkled in the code itself, but separate enter-exit-conditions and class invariants held separate from your implementing code. (This, of course is best shown in a language with DBC-built-in, or a templating-based overlay on other languages.)

      So, don't confuse assertions with DBC any more than you confuse classes with object-oriented programming. Classes is just one method of implementing OOP, just as assertions is just one method of implemeting DBC.

      The biggest strength of DBC according to me, is the enter-exit-conditions of methods. They are highly reusable and is valid both for the method they are attached to, and also any subclassed method, while class-invariants may be tied to the implementation more than the actual contract.

    40. Re:He's right by rawler · · Score: 1

      I really think you should spend some time looking at the reasoning behind DBC. Reading your comments here makes me suspect that you're already, like me, thinking much in the lines of DBC when you're "unit-testing".

      It seems as you, like me, acknowledge that any real-world application tends to be by far too complex to realistically except to be able to fully use unit-tests of all units completely isolated. Instead, you and I (different from the usual definition of a unit in unit-testing) consider a unit to be a hierarchial element of the code, ranging from the system as a whole, including all processes, threads, protocols etc, down to the really simple method such as addTwoInts(a,b).

      DBC and unit-tests are closely related, but they are a big fundamental difference.
        * Unit-testing as a methodology tries to impose a certain kind of modularity and isolation on your code. I.e. mocking away everything else than the fundamental unit you're working on requires mostly all code to be implemented through interfaces in a typed language.
        * DBC does not really impose any such requirements on your code (other than to design sensibly and actually define contracts). It relates much more on how your code is used in YOUR application, and defining how it may be used in someone elses. In DBC you also spend some time writing interface-specifications, but here you don't do it for the purpose of mocking the object later, you do it as a part of defining the interface of the unit which can later serve both for automatically driven testing, input validation, and API-documentation.

      An example:
      Two fundamental units A and B, where B depends on A. Unit-testing suggests mocking away A for testing B, while DBC don't care, and considers testing of A to be a part of the testing of B.

      In practice, the big fundamental difference between unit-testing and DBC is that DBC does not make a big difference between unit-testing and all other testing, similarily to what I'm reading between the lines in your posts.

      In DBC, you may write a few unit-tests for them both if there's anything in particular you want to constantly verify when building, but the focus of DBC is performing the tests directly in YOUR application, with higly granular verification to easily detect and track down problems.

      Am I making any sense? If not, please go ahead and read http://www.digitalmars.com/d/2.0/dbc.html. It's a bit shorter, and maybe more clear. (D-specific but it gives some idea of the concept.)

    41. Re:He's right by rawler · · Score: 1

      Oops, re-read your post and realised we're probably already on the same page. :)

      Except with good DBC tools, you wouldn't need to drive your unit-tests much yourself, though. The interface specification allows fuzz-testing (http://en.wikipedia.org/wiki/Fuzz_testing) + explicit corner-case-testing to be a great automated way to drive your code.

    42. Re:He's right by rawler · · Score: 1

      Mocks are basically the fundamental difference between DBC and Unit-testing (As a methodology, not as one of the test-methods in DBC.)

      Unit-testing as a methodology tries to impose a kind of modularity and isolation in your code that truth be told is not always sensible.

      It's not uncommon that a perfectly good design contains a few units very tightly coupled together to the point where it's more useful to test them together as they are used, rather than painfully trying to drive them apart to the point where they are tested under conditions that, strictly speaking, is not really sensible for their real use and thus should not be part of their respective contracts.

      The main viable reason I can see for mocking away parts of your code are performance-reasons, and components that may require interaction to users or external components that can't be integrated into the test. (I.e. a business-system where getting a test-setup for development is not an option.)

    43. Re:He's right by SanityInAnarchy · · Score: 1

      It sounds to me like DBC is much more closely related to strict type-checking than to unit testing (or any other kind of testing).

      In other words, it's a subset of testing. I still don't see why I'd want it to be formally defined by the language, though I can see it being useful to have a DSL that's faster at writing the simplest test cases.

      By the way: I generally do both kinds of tests. I write unit tests (mocking away what isn't related to this particular chunk of code) and more thorough tests (trying to get as close as possible to the way this object will actually be used). For a web app, for example, it's possible to get browser-based tests -- as in, tests that actually run in a real web browser and interact with your app.

      But I would much rather have a flexible language in which it's possible to write DSLs, than a language in which certain kinds of tests are baked in as a DSL, and for others, you're on your own.

      --
      Don't thank God, thank a doctor!
    44. Re:He's right by rawler · · Score: 1

      Well, DBC is about just that, designing by contract, making code give promises on how it works, and be explicit about it.

      Just as you can be object-oriented in many objects without object-orientation-mechanisms built-in, you can DBC in almost any language. (Implicitly, you do it whenever you write documentation.)

      DBC however encourages knitting the contract directly into the code, and making it enforceable in a variety of ways, where testing is often perceieved as the more useful way.

      Also, DBC can be implemented slightly differently, where some implementations are strictly test-focused, and others more aimed at letting the compiler mathematically enforcing the validity of your code.

      So yes, DBC is (partially) about testing, but only as a method of verifying your contracts. :)

    45. Re:He's right by SanityInAnarchy · · Score: 1

      Suppose, for a moment, that I don't care about the mathematical correctness, or any of the other static tools. Suppose I only care about the testing.

      Given that, I think that testing frameworks can be made less verbose than DBC -- mostly because I don't often need to design contracts at all like the examples I've seen so far.

      Often, code will work on proper inputs, and fail with improper inputs, without me having to do any extra work -- and it will do this at a relatively high level. I much prefer high-level tests to low-level ones.

      --
      Don't thank God, thank a doctor!
    46. Re:He's right by Brandybuck · · Score: 1

      You let Microsoft test your code? Holy crap!

      --
      Don't blame me, I didn't vote for either of them!
    47. Re:He's right by rawler · · Score: 1

      The thing is, you're probably already doing DBC in some form. If you document your code (and I'm sure you are ? ;) You are already giving out contracts.

      Contract-based programming is simply about formalising those contracts to a form where it can be used for documentation, testing AND code analysis, all at once.

      If that's not appealing, well then I guess DBC really isn't your thing. :)

      Btw, can you point me to an example where DBC gives you more code compared to a test-driven-design?

  18. To test code for literate programming compliance.. by 3seas · · Score: 1

    .... use a spell checker.

    Ultimately literate programming is a matter of translation.
    When you boil it all down to what the machine understands, it comes out binary.

    To achieve the literate programming goal its clear there needs to be a programming language designed for it and a translator, be it a compiler or interpreter, that can take the results and convert it to machine understandable binary that runs as intended by the programmer/writer.

  19. Re:he's from another era by lekikui · · Score: 1

    No he doesn't. He says they're unnecessary in most cases, and that he only uses them when he's ``feeling my way in a totally unknown environment''.  Otherwise he simply doesn't need to.

    The ALGOL on punch cards story is quite separate.

    --
    "Lisp ... made me aware that software could be close to executable mathematics." - L. Peter Deutsch
  20. On multicore by cryptoluddite · · Score: 2, Insightful

    Making a program parallel will always be too hard for most programmers. But that's exactly why you don't have normal programmers do it... have the libraries do it automatically. Functions like qsort(2) are already black boxes, so they can be made to always run in parallel when the input is large enough. Other functions like say Ruby's .collect can run in parallel. For things like .each there can be a parallel and a sequential version that the programmer can pick which is appropriate.

    But to do this we need operating systems that can efficiently and reliably schedule code across cores. Add an ability to 'bind' threads together, so that they schedule always at the same time but on separate real processors. This gives the program the ability know when running an operation split between these threads will always complete faster than sequentially, without vagaries of scheduling possibly starving one thread and making it run much slower.

    Once you have this then you can automatically get some speedups from multiple cores on programs that are designed to only run sequentially, and more speedup on programs with just minor tweaks. You aren't going to get perfect scaling this way, but you will get substantial improvements at virtually no cost to the programmer.

    1. Re:On multicore by Nomen+Publicus · · Score: 4, Insightful
      I've been involved with "parallel programming" for 20 years. There is no mystery involved. The C family of languages are particularly ill suited for parallel programming which may be why we are seeing reports recently claiming that it is "too difficult". Pointers in particular make life difficult for both the programmer and the compiler.

      There are a few techniques to be mastered and using a language designed with parallelism in mind helps hugely with the picky details.

    2. Re:On multicore by shutdown+-p+now · · Score: 1
      To be fair, I find that a lot of high-level (business layer) code I write today consists of "foreach (...) { ... }". It would seem that there are quite a few opportunities to parallelize there.

      We're getting there, too, what with OMP, Parallel LINQ, and for a glimpse of the future - foreach in Fortress is parallelizing by default (you have to explicitly ask for sequential behavior if you need it).

    3. Re:On multicore by kolbusa · · Score: 1

      You are not only going to get very low scaling (due to Amdahl law) unless all you do is calling quicksort, but also can get worse performance if your libraries make bad decisions when to run in parallel and when not. To get reasonable scaling one needs to parallelize at the highest level possible and design accordingly. I work pretty much with application called WRF and it has _hybrid_ MPI+OpenMP parallelization: 2D domain decomposition with parallelized with MPI + tiling inside each subdomain with OpenMP. This makes its computational part extremely scalable.

    4. Re:On multicore by Argon · · Score: 1

      I must admit I am not sure why people are so hung about about the need for parallel programs to take advantage of multiple cores on desktop systems. Clearly there are already parallel programs today - most server applications are multi-threaded and can certainly use multi-cores.

      On desktop systems, 2 or 4 cores can be effectively used, may be not as well as a single high powered single core but definitely much more effectively than people seem to be believe. You don't need all multi-threaded apps, you just need several CPU intensive apps running at the same time. Video encoding, tabbed web browsing, email and compiling at the same time for example. While it's difficult to parallelize compile/optimize/link of a single source file, multi-core makes total sense when you think "make -j8".

      Okay, your multiple cores are underutilized most of the time and are used only in bursts. But so what? What do you think happens with single core CPUs? Surprise, the CPU is grossly under utilized! It's usually memory and I/O that's a bottle neck even in desktop systems (except for some CPU intensive applications like encoding video for example). If power management is done well and cores can be enabled (and clock speed increased) on demand, I am fine with multi-cores.

      Ganesan

  21. In other news, Chuck Norris rips on safety gear... by CaptKilljoy · · Score: 5, Insightful

    The headline is misleading. Donald Knuth represents the epitome of the solitary super-programmer stereotype, so it's only natural that he sees no need for unit tests to catch mistakes or extreme programming to improve team development practices. I don't think he's necessarily saying that those things are without value for ordinary programmers.

  22. A sample literate program by Lengyel · · Score: 2, Interesting
    I cannot resist including my own literate program. The original was written in reply to a programming test, posed by a prospective employer. During the interview I was told that the company contained their costs by keeping salaries low. In keeping with the spirit of literate programming, this story is recounted within the body of the program.

    Literate programming might be more popular if it had support for interactive debugging, with the standard features common in contemporary interactive development environments.

    1. Re:A sample literate program by Anonymous+Brave+Guy · · Score: 1

      During the interview I was told that the company contained their costs by keeping salaries low.

      Sorry, I realise this is off-topic, but isn't that like going into an interview as a candidate and stating that as a general policy, you do the minimal amount of work possible to give the appearance of meeting your responsibilities to your employer?

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    2. Re:A sample literate program by Anonymous Coward · · Score: 0

      I don't see the relationship. The purpose of a debugger is to make the computer tell you in exhaustive detail what a program actually does as written, because nobody understands it well enough to explain it to you in a less painful way. If anyone were capable of documenting it correctly, you wouldn't need the debugger in the first place.

  23. Dismissive of DAK by symbolset · · Score: 3, Insightful

    That's a brave stance. He's old, but he hasn't reached his dotage yet. The good doctor has contributed more to the science of information than most, and almost certainly more than you.

    debugging ALGOL on punch cards as he has done would be brutally painful, of course, but here we are in 2008 with no punch cards or ALGOL.

    One of the reasons why we're reinventing so much over and over with nuisances like VB and C# is that developers are architecting grand toolchains based on ideas that were in the 1960's proven incorrect. They get a lot profits from their workarounds, and then we burn it all down and start over because they all contain the same fatal flaws.

    my dualcore laptop really has no problem with that.

    That would be because you haven't installed Vista on it yet.

    Having watched this tragedy unfold for a quarter century I've often shook my head and wondered what y'all were thinking. And then I remember that I once thought my parents were fools too. If you can read TAOCP and understand a good fraction of it you will come away with a firmer foundation for the way all things work. It's a tough slog, though, and not everybody is capable.

    --
    Help stamp out iliturcy.
  24. erlang rocks with parallel cells! by Anonymous Coward · · Score: 0

    erlang is the balm to ease you pain mr knuth.
    Tri it youll like it.

    -AC

  25. I've only proven that it works... by DirtySouthAfrican · · Score: 3, Funny

    "I've only proven that it works, I haven't tested it" - Knuth

  26. The Summary Exaggerates the Interview by Cal+Paterson · · Score: 5, Informative
    Knuth said many of these supposedly outrageous things in passing, and does it while noting that he is an academic. Most of these claims in the summary vastly exaggerates the strength of the claims in the interview. Knuth specifically states;

    there's no reason anybody should care about the opinions of a computer scientist/mathematician like me regarding software development.
    Knuth doesn't claim that unit testing is a waste of time for everyone, just that it is a waste of time for him, in his circumstances. This makes sense, considering he follows his own (diametrically opposed) doctrine of "literate programming", which, if the summary author has never heard of, should cause him to be cautious about interpreting Knuth.
  27. computer programming by nguy · · Score: 1, Interesting

    Knuth's view of programming seems to be that of clever tricks and fast algorithms. That may have been true when he got into the field, but it isn't anymore. Today, it's about creating big systems that need to be maintained by many programmers, not all of whom are as smart as Knuth. Algorithms come in libraries and are implemented by specialists. So, maybe Knuth doesn't need unit tests for his projects, but real-world projects do.

    1. Re:computer programming by Anonymous+Brave+Guy · · Score: 4, Insightful

      No offence meant, but I think your preconceptions may be clouding your judgement here.

      You claim that today's programming field is not about clever tricks and fast algorithms. I claim that if more people understood these old-fashioned concepts, we would have much better software today. For a start, anyone developing those "libraries implemented by specialists" you mentioned had better be very good, since a lot of other people's code is going to depend on them. Having worked in groups that develop various kinds of library, I can assure you that a little more general programming knowledge about clever tricks and fast algorithms wouldn't go amiss.

      You claim that today's programming field is about big systems with many programmers. I claim that this is because management and technical leadership in most places isn't competent enough to divide up a big system in modular fashion and allow smaller, more flexible teams to solve the little problems before multiplying them all up to solve the big ones. Instead, the guys at the top tend to reduce all problems to the least common denominator, "throw enough people at it and we'll win eventually" philosophy. This explains how a small company with a few dozen employees can produce software that is better in every way than the competing offering from a larger company with hundreds of developers. You don't even need to have a dew dozen genius programmers; you just need to understand the concept that there are O(n^2) lines of communication between n individuals working in a single large team, but if your project is divided hierarchically then logarithms start coming into play, and if you can split a problem into several properly independent smaller ones this becomes a constant factor overhead. This elementary mathematics seems to be beyond a lot of senior management in the software business, and that has far more to do with the need to build monolithic systems maintained by zillions of developers than any actual project requirements do.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    2. Re:computer programming by kramulous · · Score: 1

      O(n^2) lines of communication between n individuals
      Is there a trace of zero? I don't communicate with myself.
      Although there is one guy down the hall who talks a lot when nobody is around ...
      --
      .
    3. Re:computer programming by kalidasa · · Score: 1

      Excellent posting. I'd say that the number of lines of communication is not O(n^2), but O(2^n) - communication even in non-hierarchical environments can be more than one-to-one, and people express themselves differently to each audience.

    4. Re:computer programming by Bodrius · · Score: 1

      I think you managed to both get and miss the point in the same message with remarkable coherence...

          I completely agree with you on the first point that software would be better if people still understood the basics better...
          But the parent comment is STILL right - the bigger problems for most programmers today have to do with the big, complex systems they need to deal with. Not the algorithm details.

          On your second point, you even seem to agree with this.

          The big problem in software development today is in understanding the target problem, and dividing it up, so it can be solved in a modular fashion. If this is not done right, and the problem remains too big or nebulous, a number of issues crop up that need to be mitigated.

          This is a hard problem, and it is not a computer science problem. Clever algorithmic skills don't help as much on this as domain knowledge, communication, and other skills that have nothing to do with algorithmic analysis.

          But if you look at what is broken in most software we use right now, it's not that the algorithms aren't fast or clever - it's the poor design choices, overly complex user interactions, quality control, and in general the things that get broken, and stay broken, even if you have solved all the hard computation problems perfectly.

      --
      Freedom is the freedom to say 2+2=4, everything else follows...
    5. Re:computer programming by systemeng · · Score: 1

      The O(n^2) idea is used in the COCOMO model for software development which was one of the first models for predicting the development time of a large system.

    6. Re:computer programming by nguy · · Score: 1

      You claim that today's programming field is about big systems with many programmers. I claim that this is because management and technical leadership in most places isn't competent enough to divide up a big system in modular fashion and allow smaller, more flexible teams to solve the little problems before multiplying them all up to solve the big ones.

      You're stating the obvious: of course management doesn't have the competency and leadership to do that. Who do you think does? You? God? Some mythical guy that's the company may be able to hire in 5 years?

      In real-world projects, there's deadlines, there's a given group of managers and programmers that one has to work with, and there are ill-defined and constantly changing requirements. Nobody knows how to divide up such problems correctly among teams or how to solve many of the subproblems.

      This explains how a small company with a few dozen employees can produce software that is better in every way than the competing offering from a larger company with hundreds of developers. [...] This elementary mathematics seems to be beyond a lot of senior management in the software business, and that has far more to do with the need to build monolithic systems maintained by zillions of developers than any actual project requirements do.

      Senior management understands that just fine. What you don't seem to understand is that, although by sheer luck, sometimes a small company can get just the magic combination of really smart programmers that are 10x more productive than the average (you don't hear about the other 99.9%), but that one can't run a company assuming that that's the case.

      If the product is due in 18 months, you need to get started now, with the programmers and managers you have. And they are going to be average. You can't hire really smart programmers because there simply aren't enough of them to go around.

      You claim that today's programming field is not about clever tricks and fast algorithms. I claim that if more people understood these old-fashioned concepts, we would have much better software today.

      Most software today isn't slow because of lack of clever tricks or lack of fast algorithms, it's slow because people get basics like memory management, communications, and system design wrong. And the most serious problem with software is not speed anyway, they are usability, crashes, data loss, and security holes. Your attitudes of "let's get out the C compiler and the algorithms textbook to speed this up" is quite common, and it's completely the wrong way to go, and (no offence) to me is the mark of an average and fairly inexperienced programmer.

      No offence meant, but I think your preconceptions may be clouding your judgement here.

      My preconceptions are based on working in industry for 25 years and building products (in addition to teaching).

    7. Re:computer programming by Anonymous+Brave+Guy · · Score: 1

      In real-world projects, there's deadlines, there's a given group of managers and programmers that one has to work with, and there are ill-defined and constantly changing requirements. Nobody knows how to divide up such problems correctly among teams or how to solve many of the subproblems.

      The first sentence there is clearly true, but I'm afraid the second simply isn't. IME, good management is in a minority in our industry, but it certainly exists, and plenty of successful projects do result. Contrary to what you wrote later in your post, you don't need the super-guru, 10x as wonderful programmers to make a successful project, nor exceptional management blessed with the insight of a genius. It is perfectly possible to do it with an average development team and merely competent management. The picture of doom you describe seems more like what I've seen in cheapskate businesses who pay well under the odds and consider an average programmer the office guru and anyone with five minutes' experience a project manager.

      Most software today isn't slow because of lack of clever tricks or lack of fast algorithms, it's slow because people get basics like memory management, communications, and system design wrong.

      And none of those things are based on algorithms, and they are the only areas that slow things down? Really?

      My preconceptions are based on working in industry for 25 years and building products (in addition to teaching).

      And yet you still assume that anyone with different experience and a different opinion from your own has "the mark of an average and fairly inexperienced programmer"?

      BTW, you completely missed my point if you think clever tricks and fast algorithms equates to using a C compiler (for what, bit twiddling and in-line assembly?) and an algorithms textbook (do you think I'm just talking about CS 101 sorting and searching here?).

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    8. Re:computer programming by TheRaven64 · · Score: 1

      You seem to be making the rather strange claim that some programs are not algorithms, which even a first-year computer science student could tell you is wrong. Understanding the stuff that Knuth is famous for - the complexity of algorithms - is still vitally important. It doesn't matter how fast computers get, a O(n!) algorithm is still going to be a bad choice in almost all situations (unless you can guarantee very small values of n for the entire lifespan of your program).

      --
      I am TheRaven on Soylent News
    9. Re:computer programming by Anonymous Coward · · Score: 0

      IME, good management is in a minority in our industry, but it certainly exists, and plenty of successful projects do result.

      Sure: good management exists. Among other things, it keeps people like you from screwing up entire projects.

      And none of those things are based on algorithms, and they are the only areas that slow things down? Really? [...] And yet you still assume that anyone with different experience and a different opinion from your own has "the mark of an average and fairly inexperienced programmer"? [...] BTW, you completely missed my point if you think clever tricks and fast algorithms equates to using a C compiler (for what, bit twiddling and in-line assembly?) and an algorithms textbook

      I'm sorry, but either you have trouble reading basic English, or you're responding to someone else, because I didn't take any of those positions.

    10. Re:computer programming by kalidasa · · Score: 1

      Maybe so, but I'd still say that lines of communication are O(2^n). Just because Barry Boehm doesn't see it that way isn't a good counterargument.

  28. Re:and, arguably, one of the founders of open sour by mfnickster · · Score: 1

    Unix(TM) was never open source. The source was available under certain restrictions, but it failed on the "free distribution" requirement at the very least.

    --
    "Slow down, Cowboy! It has been 3 years, 7 months and 26 days since you last successfully posted a comment."
  29. those damn kids by superwiz · · Score: 2, Funny

    and their unit test. in my days, if you needed a language, you wrote your own assembly. and when you couldn't document it, you wrote your own mark up language.... and your own fonts. phew... multiple cores. who needs them?!

    --
    Any guest worker system is indistinguishable from indentured servitude.
  30. Uhh ... who hates Knuth? by khaladan · · Score: 1

    It's pretty inane to end the post with "whether you love him or hate him". Who hates him? For what? Maybe you're confusing him with someone else. He's not a controversial figure in the CS world, and he's not part of the Free Software or Open Source punditry.

    I hope he lives to 100+ so he can keep writing.

    1. Re:Uhh ... who hates Knuth? by Xiaran · · Score: 1

      Well he did run over my puppy as a child...

    2. Re:Uhh ... who hates Knuth? by SanityInAnarchy · · Score: 1

      Well, I don't hate him, but I don't respect him as much after this.

      Basically, I can see why Knuth wouldn't need unit tests, in code he writes himself, that no one else will ever use. But to not see value in unit tests at all -- let alone multicores and code reuse -- tells me he is a dinosaur. A genius dinosaur, but a dinosaur nonetheless.

      --
      Don't thank God, thank a doctor!
    3. Re:Uhh ... who hates Knuth? by khaladan · · Score: 1

      It's hilarious that you say "If you're going to reply to this post, please read it first!" but it's clear you didn't read the article.

      Knuth never says that he doesn't see ANY value in unit tests, and also doesn't go beyond his own reasons for unit tests. He also admits that parallel code can be useful for several applications.

      And so he prefers "re-editable code" to code reuse. So what?

      Your mom is a dinosaur.

    4. Re:Uhh ... who hates Knuth? by SanityInAnarchy · · Score: 1

      Knuth never says that he doesn't see ANY value in unit tests No, he said that they were "a waste of time." Did you read the article?

      He also admits that parallel code can be useful for several applications. In the kind of grudging way that a Linux zealot might admit that Microsoft can be useful in certain situations. Here, let me quote the article for you:

      During the past 50 years, Iâ(TM)ve written well over a thousand programs, many of which have substantial size. I canâ(TM)t think of even five of those programs that would have been enhanced noticeably by parallelism or multithreading. Surely, for example, multiple processors are no help to TeX. Which also shows a lack of imagination, by the way -- I can imagine how Tex could scale to multiple processors. The only reason multiple processors aren't a help is that any one today is more than fast enough.

      And so he prefers "re-editable code" to code reuse. So what? Here in the modern software world, we have this concept of a thing called a "shared library."

      I've read his arguments about "re-editable code", and I continue to believe that re-usable code is better, especially in a modern language where, without even trying, it's just about as flexible as going and editing the code in question. (Example: Ruby's open classes.)
      --
      Don't thank God, thank a doctor!
  31. 200 times a day? by PipingSnail · · Score: 1

    Well, if you are testing your code 200 times a day, you are almost certainly wasting time. Lets run some numbers:

    Assuming you work an 8 hour day, that means you are testing your code every 2 minutes and 24 seconds. Given that most of your tests will take this long to run (you've got a suite of them right?), that leaves you with zero time to actually do the work you are testing.

    Frankly, if you are using Unit Tests you should be using them after major chunks of work, not in a trial and error fashion. Now if you were using them in a trial and error fashion - "lets change this, run the tests and see if they pass, no that didn't work, lets try this", etc, I could understand how you hit the 200 times per day mark.

    If you are coding in a trial and error fashion and using unit tests that way, I'd advise getting some tuition or changing career.

    If you aren't doing a trial and error, then I'd suggest that you've perhaps exaggerated the 200 times figure.

    I'm a highly productive individual, in terms of writing software and I'd guess I'd have cause of getting out the unit tests a few times a day down to maybe once every few days. The rest of the time I'm actually implementing the design thats in my head/on paper etc.

    I believe in incremental development, but that doesn't mean blowing huge wads of time needlessly running unit tests. Which means, by implication, the unit tests ARE NOT part of the build process. They are something I run at times of my choosing when I think the work I'm doing is at a point that may benefit from such tests.

    Making the unit tests part of the build process is like requiring a roadworthiness test for you car every one mile you drive it. Sure the car is safe, but its not very productive at getting you from A to B, you could walk faster.

    What counts is that when you run the unit tests, they pass, and that they accurately test the conditions that need testing.

    1. Re:200 times a day? by Anonymous Coward · · Score: 0

      Huh? You don't sit around watching unit tests run.

      You set up an automatic build system, whereby the code gets automatically compiled and unit tested whenever there hasn't been any checkins for some preset period of time (say, half an hour). If a unit test fails, the build system sends email to the people who checked in code since the last unit test ran.

      In other words, running unit tests takes zero human time.

  32. erlang rocks for multi-cell by Anonymous Coward · · Score: 0

    erlang is the balm for your multicell blues.
    tri it youll like it.

  33. "Open source" and Stanford policy by Animats · · Score: 2, Interesting

    There's a relevant quirk of Stanford University employee policy. For Stanford academic employees, software usually is considered "work for hire" and an "institutional work", with Stanford holding the copyright. But books and papers are considered to be the property of the author. (Policy on this changed in the late 1990s; there's a long history here, primarily involving the founding of Sun and Cisco.) However, Stanford permits the creator to place a work in the public domain, unless external funding prohibits this.

    Knuth's code is open source. But his books are not.

    1. Re:"Open source" and Stanford policy by 1729 · · Score: 1

      Knuth's code is open source. But his books are not. The source code for Knuth's TexBook is available:

      http://www.ctan.org/tex-archive/help/Catalogue/entries/texbook.html
    2. Re:"Open source" and Stanford policy by Anonymuous+Coward · · Score: 1

      But the source of TAOCP unfortunately isn't.

  34. Umm, Not Quite... by reallocate · · Score: 1

    It's been some time, but it seems to me the notion of literate programming is that anyone who knows the language can read the code and understand what's going on.

    So, whether you use "*" or "MULTIPLYB" is no more a mark of literacy than if you say "Thank you" or "Merci".

    Verbosity has nothing to do with it. Cobol code that is readable is better than C code that's not.

    --
    -- Slashdot: When Public Access TV Says "No"
    1. Re:Umm, Not Quite... by Tony+Hoyle · · Score: 1

      It's been some time, but it seems to me the notion of literate programming is that anyone who knows the language can read the code and understand what's going on.

      Surely thats the goal of *all* programming. If you're writing code without thinking about whether it'll be understandable in a month or two (or in 5 years) then you're not doing your job properly... hence rules like if you've made a nonobvious choice, write a comment why.. don't just assume the next guy will know your reasons (and don't comment obvious stuff because it'll get on everyone's tits).

  35. beg to differ by mevets · · Score: 1

    It has always been about trying to avoid making big systems. Unit tests have many of the limitations of spell checking; they are know replacement four vigorous review.

  36. Mod parent up!! by gwniobombux · · Score: 1

    The headline as well as the summary have quite a lot of spin in it. If you want to know what Knuth actually says, you should RTFA. Yes, I know this /., but you won't regret it, it's a good read. By the way, Knuth uses Ubuntu.

  37. erlang rocks for multicell programming by Anonymous Coward · · Score: 0

    try it youll like it
    erlang is the balm for your multicell pain, mr Knuth

  38. Knuth is hardcore by Sits · · Score: 2, Insightful

    FVWM on Ubuntu Linux. Emacs with special modes using a homemade bitmap font. Mac OSX for Illustrator and Photoshop...

    Now that's breadth AND depth.

    1. Re:Knuth is hardcore by tomtomtom777 · · Score: 1

      I currently use Ubuntu Linux, on a standalone laptop - it has no Internet connection. I occasionally carry flash memory drives between this machine and the Macs that I use for network surfing and graphics

      Ehhh.. WTF?

  39. Re:he's from another era by Not+The+Real+Me · · Score: 2, Informative

    "...but here we are in 2008 with no punch cards..."

    Yes and no. Yes, the physical punch cards are gone, but they live on in financial institutions in the form of Automated Clearing House (ACH) debits and credits which use the 96 column IBM punch card format. So, the next time you use your credit card, ATM card, e-check or pay a bill online through some company's web site, on the backend they are probably using ACH upload files (aka NACHA format) which was based on IBM's 96 column punch card to transfer financial data. Magnetic tape may be used on a contingency basis but it has to have an additional header record, be EBCDIC encoded and use 9 track tape. The IRS and many state tax agencies use ACH transfers, as an option, to refund personal income taxes instead of sending taxpayers a physical check.

  40. Is Multithreading a Flop? Answer: Yes by MOBE2001 · · Score: 2, Interesting

    From the interview I see that Knuth thinks multithreading may turn out to be a flop. I agree and I would go even further. I don't think there is any question that the multithreading strategy used by Intel and AMD for multicore programming is a big flop already. Multithreading is the second worst thing to have happened to computing. The worst is single-threading which is what normal algorithmic programming is based on. Parallelism is the correct approach to computing. Computing should have been parallel from the start even on single-core processors. If parallelism had been emulated in a processor from the beginning, adding more cores would have been a simple evolutionary transition, a mere engineering problem. My point is that there is a better way to do parallel programming that does not involve threads at all. Cellular automata and neural network programmers have been emulating parallism for decades without threads.

    Essentially, you need to have two buffers and a loop. While the first buffer is being processed, the second buffer is filled with objects to be processed in the next cycle. When the first buffer is done, swap the buffers and start over. Two buffers are used in order to prevent signal racing conditions. It's not rocket science. We just need to take it to the instruction level by changing it from a software mechanism into a hardware mechanism. In other words, the mechanism should reside in the processor, whether single or multicore. This is the correct approach to parallelism. Multithreading is going to be a complete disaster, a multi-billion dollar disaster. Google "Nightmare on Core Street" to find out why multithreading is not part of the future of parallel computing.

    1. Re:Is Multithreading a Flop? Answer: Yes by hey · · Score: 1

      Why does it have to be one program multithreading?
      Maybe a user is applying a Photoshop filter while doing a 3D render while ftping a file. Each can run on a different core.

    2. Re:Is Multithreading a Flop? Answer: Yes by FrankSchwab · · Score: 1

      I look forward to your first successful implementation.

      --
      And the worms ate into his brain.
    3. Re:Is Multithreading a Flop? Answer: Yes by SeekerDarksteel · · Score: 1

      So it's stream processing.

      Which is still hard to program for anything but the most obviously data parallel applications

      Unless you're suggesting we make it even lower level and have the compiler map individual instructions/basic blocks to processing elements.

      In which case it's dataflow processing and has it's own equally large set of problems, most notably....that it's really hard to program in a way that maps well to the dataflow hardware.

      --
      The laws of probability forbid it!
    4. Re:Is Multithreading a Flop? Answer: Yes by MOBE2001 · · Score: 1

      So it's stream processing.

      No. It's discrete signal processing, similar to the signal (pulse) processing done in the brain. Stream processing is vector or data parallel processing. It's a completely different beast.

    5. Re:Is Multithreading a Flop? Answer: Yes by Bitmanhome · · Score: 1

      Essentially, you need to have two buffers and a loop. While the first buffer is being processed, the second buffer is filled with objects to be processed in the next cycle. When the first buffer is done, swap the buffers and start over. Two buffers are used in order to prevent signal racing conditions. I think you've gone too far off track there. Your paragraph as stated is pretty useless; most algorithms are only able to place one object in the buffer each pass. We need a good practical theory for mass-market parallel computing, and we just don't have that. Until we do, the proper chip and language design won't be obvious.
      --
      Not that this wasn't entirely predictable.
    6. Re:Is Multithreading a Flop? Answer: Yes by Anonymous Coward · · Score: 0

      Essentially, you need to have two buffers and a loop. While the first buffer is being processed, the second buffer is filled with objects to be processed in the next cycle. When the first buffer is done, swap the buffers and start over. That very much sounds like stream programming. See work on the Sequoia, Merrimac and the Imagine in Stanford, for example. The Sequoia project has been using the Cell processor among others.
    7. Re:Is Multithreading a Flop? Answer: Yes by lysse · · Score: 1

      > Computing should have been parallel from the start even on single-core processors.

      Maybe. But the thing is that *humans* aren't parallel. Oh yes, at the implementation level we are, certainly - but at the application level, that parallelism is put to work emulating a single-threaded, mutable object. We even impose a serialised perception on time, despite strong evidence that it doesn't seem to work like that.

      In any case, the notion of cause and effect (or maybe call and response) dictates sequentiality to pretty much any programming model that has to respond to external events. Moreover, what you describe in your second paragraph is nothing but simple pipelining, and that's been done (both in low-level processor implementations and in larger structures) for decades now.

    8. Re:Is Multithreading a Flop? Answer: Yes by Kjella · · Score: 1

      Essentially, you need to have two buffers and a loop. While the first buffer is being processed, the second buffer is filled with objects to be processed in the next cycle. When the first buffer is done, swap the buffers and start over. Two buffers are used in order to prevent signal racing conditions. It's not rocket science. We just need to take it to the instruction level by changing it from a software mechanism into a hardware mechanism. In other words, the mechanism should reside in the processor, whether single or multicore. This is the correct approach to parallelism. Multithreading is going to be a complete disaster, a multi-billion dollar disaster. Google "Nightmare on Core Street" to find out why multithreading is not part of the future of parallel computing. I just have to ask, were you asleep for the last decades? Modern processors do all kinds of pipelining, parallel instructions, speculative branching and more to make your applications go faster. Your idea that processors can be parallelized further on the instruction level is way past the expirery date. The individual cores don't go faster and if you want to send the instruction to a different core, you need to flush the state from the old CPU = ~200 cycles, read the buffer into the new core = ~10-15 cycles and process the entire pipeline = ~10-15 cycles which means that if your "objects" depend on each other sending them to different CPUs is a REALLY REALLY BAD idea. Meaningful multi-core processing REQUIRES that your work is split into independent work packages that are of a size large enough to justify the overhead. Sure the language can assist but that just doesn't come naturally.
      --
      Live today, because you never know what tomorrow brings
    9. Re:Is Multithreading a Flop? Answer: Yes by tuomoks · · Score: 1

      I halfway agree. Parallelism (tasks,attach,etc) is often more useful and easier to handle. By the way, parallelism was available in single core systems, I wrote those before we got systems with more than one cpu - a long time ago. Can be useful even in one core if they do I/O, as you said, or there is for example an attached vector processor.

      Now - threading can be useful. I just designed a system where the system itself controls the threads. Let's say the image convert on message path is slow and slows down the whole messaging because of serialization. They systems checks if more cores are available, if there is cpu / memory resources and if so, starts a new image process. It is also very handy way to start a new thread but with different arguments, dynamic configuration, and signal the old thread to exit once it has done the current processing. Or, if the audit process fails or gets an fatal error from SQL server and server has to be restarted, which takes time, the system starts another audit server temporarily saving messages somewhere else. Makes coding these processes much easier - no recovery code or queuing in process itself, can even swapped to use totally different SQL system in flight, etc. Or a new "line" is configured to system, just start a new TCP/IP thread for it, nothing else have to change.

    10. Re:Is Multithreading a Flop? Answer: Yes by Anonymous Coward · · Score: 0

      No. It's discrete signal processing, similar to the signal (pulse) processing done in the brain. How does FFT and filters relate to processes of the brain? How a parallel DSP is different from a parallel stream processor, except from the execution unit types and memory architectures?
  41. Spaghetti-O Code by illegalcortex · · Score: 4, Insightful

    I somewhat disagree with what you and... *sigh* Monkeybaister posted. Yes, there are many times when long stretches of code should be broken out into functions. But I tend to do that mostly when the same bit of code is used in several different cases. The reason being is that when you start modularizing off all your while loops that are more than a dozen lines long, you create a whole new type of spaghetti code. I'm going to coin a term and call it "spaghetti-O code." You try to track down a bug and what would have been a straightforward couple pages of code now has all kinds of functions at different places in the code. As such, it can often make debugging or forming a mental map of the code much harder.

    1. Re:Spaghetti-O Code by fishbowl · · Score: 3, Insightful

      >The reason being is that when you start modularizing off all your while loops that are
      >more than a dozen lines long, you create a whole new type of spaghetti code.

      There is also a risk that you or a maintenance programmer might re-use such a "function"
      that was created simply to make a while loop more aesthetically pleasing, and introduce a bug because that function was not designed or tested for use in isolation.

      And in the spirit of the topic, such functions become awkward to unit test, since you're extracting a unit of work out of a loop or control structure, that logically lives there.

      --
      -fb Everything not expressly forbidden is now mandatory.
    2. Re:Spaghetti-O Code by Kent+Recal · · Score: 4, Interesting

      I know this problem very well from the dark days when I was still writing java.
      There doesn't seem to be a satisfactory solution, it's always a tradeoff.

      While reading this thread I realized a funny thing: This particular annoyance
      totally vanished from my day-to-day headaches when I switched to python about
      a year ago.

      It's a bit wierd because Python doesn't even use braces so one would expect
      it to be even harder to identify where a block begins and where it ends.
      But the opposite has been the case for me: The clean syntax and language
      design has led me to write, on average, shorter blocks with very little
      nesting.

    3. Re:Spaghetti-O Code by DarkOx · · Score: 1

      I have to agree a fuction really ought to perform a (in human terms) atomic task. Something like ReadRecord() that gets the next byte form the stream, looks at it as a magic number indicating the type of record to follow and then reads it into memory and finally retunrs a pointer which cold be cast to to a struct pointer reflecting that type of record makes plenty of sense.

      A function that is essentially RunThisInnerLoop() is not good, because when you look at that line in the context of the outerloop you can't get any idea of what the outerloop is for now until you go and look at that function, which you no doubt surfed past it not really understanding its use when you saw it the first time ether.

      --
      Repeal the 17th Amendment TODAY! Also Please Read http://www.gnu.org/philosophy/right-to-read.html
    4. Re:Spaghetti-O Code by WhoCantTakeAJoke · · Score: 1

      This applies mostly to programmers who write functions. Developers who create objects with methods usually don't require blocks of code "pages" long. I'll give a by to computer scientists implementing algorithms because the developers will encapsulate their code for them.

      I blame one-shot college CS projects. These long chunks are usually the result of a procrastinator cranking out the code in one sitting. That shopping list will work well enough to turn it in for a grade. If it doesn't then build and fix with liberal use of a pretty IDE debugger will find the bugs. You won't understand the code next month, but that doesn't matter. You won't be able to reuse or extend that code, but that doesn't matter.

      Try maintaining that same code over the course of years. Try debugging that code when it's running in a distributed system in production. If colleges made students maintain legacy systems as part of their trials, then code would be much cleaner, with much more logging, and we'd all be a lot happier.

      --What does static do? I dunno, I think it makes it faster. Then let's make it all static.

      --
      I have no direct experience or knowledge, but I'd imagine...
    5. Re:Spaghetti-O Code by mykdavies · · Score: 4, Informative

      It's called ravioli code

      --
      The world has changed and we all have become metal men.
    6. Re:Spaghetti-O Code by buildguy · · Score: 1

      Is there any programming language/family that allows one to explicitly state which functions are stand alone and which one's are "one-offs"? I'm not a programmer, and most of my experience is with PHP and C, so I could be saying gibberish.

      --
      You think that's a building. Now this is a building.
    7. Re:Spaghetti-O Code by Anonymous Coward · · Score: 0

      It's a bit wierd because Python doesn't even use braces so one would expect
      it to be even harder to identify where a block begins and where it ends.
      But the opposite has been the case for me: The clean syntax and language
      design has led me to write, on average, shorter blocks with very little
      nesting. I know what you mean. It's almost like they'd rather be coding in assembly.

      For example, they'd rather write this (Python version cause I'm lazy):

      def calculate(nums):
          s = 0
          for i in nums:
              s = s + i
          return s * 1000

      than this:

      def calculate(nums):
          return sum(nums) * 1000

      def sum(nums):
          s = 0
          for i in nums:
              s = s + i
          return s

      Obviously sum() is a built-in so you wouldn't need to write that function, but you get the drift. It's not spaghetti code if you know what you're doing. I mean that literally: think about what you're doing. Then write and name an appropriate function for it. If you can't come up with a name for it, it's probably a bit too "clever." Rewrite it. If you regularly write nested loops more than 3 levels deep, I really, truly, hope I never have to work with you.

      And if you're worried about reusing a function you shouldn't, the function probably isn't coded very elegantly. If it has side-effects, well that's what scope is for.
    8. Re:Spaghetti-O Code by jacquesm · · Score: 1

      proper modularization and the 'static' keyword are a feature of C and C++

    9. Re:Spaghetti-O Code by illegalcortex · · Score: 1

      I like that. But considering it only gets around 1k hits on google, I'm not really going to consider it an established term. ;)

    10. Re:Spaghetti-O Code by Mr.+Slippery · · Score: 3, Insightful

      This applies mostly to programmers who write functions. Developers who create objects with methods usually don't require blocks of code "pages" long.

      Oh, please. Don't put on object-oriented airs. A "method" ain't a nothing more than a function associated with a class..

      A function (method, procedure, subroutine) should be just as long as it has to be to encapsulate the work it's doing. Sometimes that's one line. Sometimes it's pages.

      Breaking those pages of code into a bunch of other subroutines solely on some misguided notion that a function shouldn't be longer than N lines, makes for code that is harder to understand an maintain.

      --
      Tom Swiss | the infamous tms | my blog
      You cannot wash away blood with blood
    11. Re:Spaghetti-O Code by Tony+Hoyle · · Score: 1

      In practical terms the longer a function is the more likely you're repeating something that should be broken out into functions.. although there are some tasks that can take pages of unique code - breaking those into functions just makes it harder to read (OTOH I've not found them that common).

      The rules about the length of a function come from the days when we used 80x25 terminals and a long function couldn't be contained on the screen.. these days we can view 100+ lines in a window and it really isn't an issue.. and it's an asinine thing to make a rule about anyway - the code is there to do its job in the best way possible.. not to hang in an art gallery.

      I once saw a case where someone had this rule drummed into them - they'd taken a perfectly working algorithm and broken it into 20 line functions, called 'fn_1', 'fn_2', 'fn_3' etc. and written a wrapper that called them in sequence. In the process they broke the algorithm.. just subtly enough that it didn't come out until quite late in testing.

    12. Re:Spaghetti-O Code by Anonymous Coward · · Score: 0

      Why are we repeating a chapter from the book Code Better in this thread? Surely, if it has been discussed before, this is kind of useless?

    13. Re:Spaghetti-O Code by FishWithAHammer · · Score: 1

      So does that make the happy medium "manicotti code"? :D

      --
      "You can either have software quality or you can have pointer arithmetic, but you cannot have both at the same time."
    14. Re:Spaghetti-O Code by Kuros_overkill · · Score: 1

      Tell me about it. The app I'm currently in charge of maintaining, has logic so complex that only 7 people in our company "understand", (out of a few hundred.) Currently, I am the one charged with maintaining it. I drives me nuts because all this emensely complicated code is all in SQL stored procedures (I didn't write it.) that all call other SQL stored procedures, that call SQL stored procedures... ect... Trying to track a single value through the system becomes a nightmare.

    15. Re:Spaghetti-O Code by MichaelSmith · · Score: 1

      breaking those into functions just makes it harder to read Funny that your comment is structured into three paragraphs.
    16. Re:Spaghetti-O Code by Tony+Hoyle · · Score: 1

      Breaking into functions is the equivalent of breaking it into 3 comments.

      Code *should* contain paragraphs, otherwise it's just a mass of text.

    17. Re:Spaghetti-O Code by multi+io · · Score: 1

      It might get really nasty if some less-than-stellar programmer who writes such a "function" introduces "creative" means like global variables to pass information from the loop to the function and back; so what was previously a local variable that was visible only to the loop body is now a global variable that, in addition to confusing the reader, may encourage other happy programmers to set them to funny values and wreak all kinds of havoc.

    18. Re:Spaghetti-O Code by mykdavies · · Score: 1

      I think it's fairly common in the XP community, e.g. at Portland Pattern Repository's Wiki, so it's got a certain pedigree :-)

      --
      The world has changed and we all have become metal men.
    19. Re:Spaghetti-O Code by Anonymous Coward · · Score: 1, Insightful

      I've heard such overly-modularized code referred to as "ravioli code". Usually it has to do with object orientation though. When you have a maze of interdependent functions, you have a plain old hairball.

    20. Re:Spaghetti-O Code by nuzak · · Score: 1

      Lasagna code perhaps. Or maybe that's for code broken into too many layers. I don't think any of the pasta metaphors for code are supposed to be complimentary.

      --
      Done with slashdot, done with nerds, getting a life.
    21. Re:Spaghetti-O Code by CastrTroy · · Score: 1

      I've often thought that something like that was necessary. To be able to create a function that could only be called from a certian other function. It would be nice if you had a function that was only supposed to be called from certain other functions, and that almost any other circumstances, you wouldn't want to be calling this other function. Another feature I often would like to have, is a way to undeclare a variable. Because sometimes a variable gets into a point where you don't want to be using it after a certain part of the function. I'm not aware of any languages that offer either of these features.

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    22. Re:Spaghetti-O Code by Anonymous Coward · · Score: 0

      to quote someone i can't remember who.....refactor, mercilessly

    23. Re:Spaghetti-O Code by try_anything · · Score: 2, Interesting

      This is why good programmers must be good writers as well. The ability to explain the structure of code, primarily with clear, precise names for classes, functions, and variables and secondarily with comments, is as important as the ability to decompose a program logically. I have seen programs that were twice as complex as they should have been, yet made perfect sense and were easy to hack on, because the code and comments made it easy to understand the original programmer's understanding.

      In the interview, Knuth gave one reason why literate programming isn't popular: few people are good programmers, few people are good writers, and literate programming only works for people who fall into both categories. I think he's right. Encouraging people to write more unstructured prose than they feel a need to results in worthless verbiage, and most programmers naturally limit their comments to sentence fragments and the occasional short paragraph. If you have to force people to write, you need to provide structure and clear expectations. That's why Javadoc and similar schemes are so much more valuable in practice than literate programming.

    24. Re:Spaghetti-O Code by try_anything · · Score: 2, Interesting

      Breaking those pages of code into a bunch of other subroutines solely on some misguided notion that a function shouldn't be longer than N lines Usually people can come up with better reasons than that.

      I've worked with code written in the "pages-long function" style. One thing I've found consistently in such code is duplicated functionality. I've even personally seen how this happens: A programmer implements a very large, complex piece of functionality as a function. Later, the need arise to implement a variation on this functionality. It turns out that the variation is quite structurally different, so to implement it by parameterizing the original function would result in spaghetti code. So, a second enormous function is written. The programmer scans the two functions and finds no large sections of code that are duplicated between the two functions, so he calls the job done.

      Naturally, code developed in this manner degenerates into an unmanageable mess as more and more variations are added. Anyone trying to program this way in the business world, for example, will quickly drown. However, people tend to get by with this style in the scientific computing world, where there are relatively few variations that cannot be handled by parameterization.

      The first thing that must be done to get out of this mode of programming is to assume that such variations will arise. Treat the first problem you solve as merely the first of many variations that you will be asked to solve in the future. (Either that, or make the opposite assumption and then completely rewrite your code when the second variation arises.) Then, analyze each variation in terms of the things it must accomplish. You can categorize things using problem domain concepts, solution domain concepts, whatever, as long as you can put names on things.

      (The tendency to think in human terms and give natural language names to things is a hindrance to mathematical insight, but it often generates effective ways to decompose code. Perhaps this is another reason why the "big function" style tends to plague scientific computing.)

      Once you have split the original task into conceptually separate chunks that can be given reasonable natural language names, split the program up into pieces that have those names.

      Voila, now you have a program made of small chunks that can be understood by other programmers. And, since each chunk has a reasonable name, programmers can limit themselves to reading the name and documentation of most pieces of the program, rather than reading every single line of code. This makes the code effectively shorter and easier to maintain, even if you never reuse the chunks to compose a new variation.
    25. Re:Spaghetti-O Code by Anonymous Coward · · Score: 0

      I'm not sure what your problem is.

      Is your problem that there are all sorts of small functions all around 'the code'? We should be talking about mostly functions which are NOT reused by any other function and are merely a functional discomposition(?) of the whole. These small nonreused functions can indeed 'float' a bit... *inside a class*. And any decent development environment should easily give you the tools to follow it all. Plus, debugging should be a synch if you have a trace of what is going on. When the small functions have names it even becomes easier to debug, as a descriptive name should tell where it fails *without looking at the code*.

      But, I have to admit, I'm a java programmer. In C I've used gdb when a crash occured, but I don't have that much experience in other languages...

    26. Re:Spaghetti-O Code by jsight · · Score: 1

      To be able to create a function that could only be called from a certian other function.


      This is a good place to use a privately declared function (closure) in javascript. Actually, Javascript makes dealing with circumstances like this really easy. Unfortunately, it doesn't handle your scoping issue as variables declared within a function in javascript are scoped through the whole block (accessible before and after "declaration") and in most cases cannot be deleted (there is a delete function, but it only works for implicit global variables, which are pure evil anyway).

      I believe that Python has both of the features that you seek, though.
    27. Re:Spaghetti-O Code by Bill+Dog · · Score: 1

      To be able to create a function that could only be called from a certian other function.
      Pascal had nested functions, which IIRC made them private to all accept their outer function. It would be nice if its successors (in popularity, not lineage) had that. If classes can be nested in C++ and Java, why not functions? It has utility even without closure support.

      Because sometimes a variable gets into a point where you don't want to be using it after a certain part of the function.
      Just create another scope inside the function. In C++ just add an inner set of braces and declare your variable in there. In Java, well, that won't work for objects.
      --
      Attention zealots and haters: 00100 00100
    28. Re:Spaghetti-O Code by entrylevel · · Score: 1

      Yes: JavaScript (and many others, but JavaScript makes the technique quite obvious.)

      // re-usable function (has a name)
      function doSomething () {}

      // one-off function (no name)
      function () {}

      PHP has create_function() but it's kinda pointless (PHP doesn't have a "function" data type, create_function returns a string.) It is somewhat useful if you must generate an unknown number of functions that must be compiled at runtime. C has the "inline" keyword, which allows you to factor code out into functions but prevents the compiler from doing the same.

      (OT: WTF happened to "Plain Old Text"? It doesn't work anymore.)

      --
      Karma: Incomprehensible (Mostly affected by posting at +5, reading at -1, and metamoderating everything unfair.)
    29. Re:Spaghetti-O Code by mrchaotica · · Score: 1

      A function (method, procedure, subroutine) should be just as long as it has to be to encapsulate the work it's doing. Sometimes that's one line. Sometimes it's pages.

      But if it's pages long, then the "work it's doing" is most likely more than one thing.

      Breaking those pages of code into a bunch of other subroutines solely on some misguided notion that a function shouldn't be longer than N lines, makes for code that is harder to understand an maintain.

      You're right that there should be no limit in the number of lines, but there certainly should be a limit in the number of "things."

      --

      "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

    30. Re:Spaghetti-O Code by mrchaotica · · Score: 1

      Then the problem is that the "less-than-stellar programmer" didn't understand (pointers|out references|returning structs), not that he wanted to divide stuff up into a helper function.

      --

      "[Regarding the 'cloud,'] ownership was what made America different than Russia." -- Woz

    31. Re:Spaghetti-O Code by Anonymous Coward · · Score: 0

      That's not a bad thing. Each function creates a new context and you can understand its internals much easier when not having to think about all the layers above and below it. And, if you get so confused about deep call stacks, i'd recommend setting breakpoints and stepping through the code (examining the call stack as you go).

    32. Re:Spaghetti-O Code by Anonymous Coward · · Score: 0

      That sounds a little like the argument against Wikis - "No, you cant make that editible by all, someone might modify it!!", which is of course, the whole point.

      As is reuse the whole point of a function.
      If the function is well named, and does what it says, then why shouldn't it be reused?

      Anyone who blindly modifies a function to do something other than its name implies is asking for trouble anyway.

      You don't split out inner loops into functions to make them more aesthetically pleasing, you do it to increase reuse and maintainability.
      That separate function can now be tested easier, and may save extra work later. If it has a bug, then the bug can be fixed - and if reusing exposes that bug, then that's a GOOD thing.

    33. Re:Spaghetti-O Code by llefler · · Score: 1

      emensely complicated code is all in SQL stored procedures (I didn't write it.) that all call other SQL stored procedures, that call SQL stored procedures... ect...


      Wait until they start using stored procedures to build other stored procedures on the fly to call the next level of stored procedures. The code morphs based on data values.
      --
      It is amazing what you can accomplish if you do not care who gets the credit. -- Harry Truman
    34. Re:Spaghetti-O Code by xouumalperxe · · Score: 1

      I't s not exactly the same, but in terms of what use you'd want to give it, I'd say that anonymous functions are what you're looking for. In my Lisp days I used them a fair bit, they're pretty decent in Python, and absolutely god-like in Mathematica (where they're called pure functions, and, together with the abbreviated functional programming operators, give way to code that makes Perl look as readable as a children's book)

    35. Re:Spaghetti-O Code by poopdeville · · Score: 1

      Please submit your story to http://thedailywtf.com/

      --
      After all, I am strangely colored.
    36. Re:Spaghetti-O Code by bdp · · Score: 1

      To be able to create a function that could only be called from a certian other function.
      Pascal had nested functions, which IIRC made them private to all accept their outer function. It would be nice if its successors (in popularity, not lineage) had that. If classes can be nested in C++ and Java, why not functions? It has utility even without closure support.

      The problem with nested functions (as in Pascal's scoping) is that in many situations it made it difficult to share values between functions or procedures, (Pascal makes a distinction between those). One way to solve that problem is to push variables up in scope, which leads to all the familiar problems with global variables. The better option was to not nest your functions and procedures in the first place, so newer languages stopped supported that feature. Most notably, C didn't include it, and as a result it drastically simplified scoping rules to more or less what we're accustomed to now.

    37. Re:Spaghetti-O Code by Dexx · · Score: 1

      Something like unset?

      --
      Feel the fear and do it anyway.
    38. Re:Spaghetti-O Code by doktor-hladnjak · · Score: 1

      Several years ago, I remember doing this in some C code I wrote. gcc handled it without any trouble, although I ended up having to unnest the functions when I had to port the code to the Visual C++ compiler. I'm not sure if gcc still supports it, but I'm pretty sure it's not part of any ANSI C standard.

    39. Re:Spaghetti-O Code by baxissimo · · Score: 1

      The D programming language has nested functions. I think maybe I heard C++0x was going to get them too. I hope so. They're just too darn useful not to have.

    40. Re:Spaghetti-O Code by CastrTroy · · Score: 1

      Looks like that's only useful for removing named indices from an array. Since you don't actually have to declare variables in PHP, when you use unset on regular integer or string values, you're basically setting them to null. But it doesn't stop you from using the same variable later on in the function.

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    41. Re:Spaghetti-O Code by illegalcortex · · Score: 1
      I'm having a little trouble following what you wrote. Could you give an example to clarify? I'm just curious if what you're talking about applies to Delphi (Object Pascal). I think I know what you mean, but I'm not really seeing the difference between having to pass values into nested functions versus passing them into non-nested ones. The only thing nesting gets you is the aforementioned "privacy" of the nested function to it's containing function.

      The big problem I have with nested functions is that yet again they make the code difficult to understand with the eyeballs. Worse yet, you have to define the function between the declaration of the outer function and the body of it. So you get this:

      procedure MyProc(Foo: Integer; Bar: Boolean);
        procedure DoSomething(X: Integer);
        begin
          (* several lines go here *)
        end;
        function CalcSomething(H, W: Integer; G: Double): Double;
        begin
          (* several more lines go here *)
        end;
      var
        Q: Integer;
        Z: Boolean;
      begin
        (* bunch of lines here *)
      end;
      It makes it fairly easy to get lost.
    42. Re:Spaghetti-O Code by PingPongBoy · · Score: 1

      I prefer deep nesting, a nasty code to read as it is when that's what it takes to do the job. As I see it, if you outsource :) the inner loops you may have declared a number of local variables many of which may be relevant at a feature change's notice to an inner loop. If you have to call a function of a function, which looking good as it may be if done right, the function becomes a function of many parameters.

      A habit of mine is to start writing code into the same function if it is not immediately known whether there will be a separate function caller of portions of the function. However, coupling through local variables is kept to a minimum between obvious segments that look separable. After debugging everything, which is easier in a single function than skipping all over in a trace, separation into different functions is painless. The separation could have been done to start with, but the coupling through local variables and big parameterization give me pause.

      BTW, I see unit tests as good things for lengthy runs or runs with lots of particular inputs. However, I've avoided unit tests lately to keep costs down. Instead I pretty much know what I do is going to work, run a couple of tests, and things are fine, except lately I've seen some odd bugs due to Microsoft Windows and Office--that's where the costs really occur, making unit tests seem more a requirement except how do you unit test visual output from Office without writing almost as much code as was written?

      So the thread all goes:

      A better way to handle that is to turn the loop body into a function or group of functions. makes the code easier to read and a good compiler will inline the function so their's no performance loss.

      I somewhat disagree with what you and... *sigh* Monkeybaister posted. Yes, there are many times when long stretches of code should be broken out into functions. But I tend to do that mostly when the same bit of code is used in several different cases. The reason being is that when you start modularizing off all your while loops that are more than a dozen lines long, you create a whole new type of spaghetti code. I'm going to coin a term and call it "spaghetti-O code." You try to track down a bug and what would have been a straightforward couple pages of code now has all kinds of functions at different places in the code. As such, it can often make debugging or forming a mental map of the code much harder

      --
      Know your pads. One time pad: good for cryptography. Two timing pad: where to take your mistress.
    43. Re:Spaghetti-O Code by drinkypoo · · Score: 1

      Oh, please. Don't put on object-oriented airs. A "method" ain't a nothing more than a function associated with a class..

      There is a good point though, which is that all the code related to doing something to the object is defined in the same place. You could and should do this even without object-oriented programming, but I do find that when I'm trying to decipher what someone else's code does, I like to read that OO-type code. It seems quite logical to do things that way, rather than to have a whole bunch of functions, which may or may not have similar names, which act only on a certain type of data.

      Breaking those pages of code into a bunch of other subroutines solely on some misguided notion that a function shouldn't be longer than N lines, makes for code that is harder to understand an maintain.

      Actually, I think keeping functions relatively short makes sense, but the key thing seems to be to break them on logical boundaries. If there isn't a logical division there, don't try to make one. The real problems tend to come when zealously following rules that may not make sense.

      --
      "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
    44. Re:Spaghetti-O Code by TheLink · · Score: 1

      I agree. And with the "marvels of modern technology" we shouldn't have to create functions for the sole reason to make it easier to figure out stuff ends.

      The editor or IDE you are using should be able to do that for you.

      --
    45. Re:Spaghetti-O Code by TheLink · · Score: 1
      --
    46. Re:Spaghetti-O Code by joto · · Score: 1

      The problem with nested functions (as in Pascal's scoping) is that in many situations it made it difficult to share values between functions or procedures

      Uh? Say again? What was the problem? Nested functions solve this problem. If the variable isn't local, it's in the containing lexical scope. This simplifies sharing of values.

      One way to solve that problem is to push variables up in scope, which leads to all the familiar problems with global variables.

      I'm not sure what you are suggesting here, but it sounds like a bad idea. Just use lexical scoping, like Pascal does.

      The better option was to not nest your functions and procedures in the first place, so newer languages stopped supported that feature.

      C had two goals: (1) to be almost as useful as assembly language for systems programming (2) writing a C compiler should be easy. Lexical scoping of nested functions is missing from C because it made the compiler more complicated, not for any esoteric philosophical reasons like you suggest.

      Most notably, C didn't include it, and as a result it drastically simplified scoping rules to more or less what we're accustomed to now.

      Well, if you are so retarded that you find nesting of variable-names within functions hard, I can understand why you prefer a system with only two levels of variable-names, local and global. On the other hand, just about any other modern language includes some form of nesting of scopes, in a way that's harder to understand than Pascals nesting of functions. But then again, Pascal was designed for teaching, so it's pretty clear why it's so easy to understand.

    47. Re:Spaghetti-O Code by bdp · · Score: 1

      The problem with nested functions (as in Pascal's scoping) is that in many situations it made it difficult to share values between functions or procedures

      Uh? Say again? What was the problem? Nested functions solve this problem. If the variable isn't local, it's in the containing lexical scope. This simplifies sharing of values.

      Try refactoring a large pascal code base that makes heavy use of nested functions and procedures. When you start needing to pass values to a function or procedure in a way that wasn't originally envisioned, you have 3 choices:

      1. 1) Start rewriting everything. (bad choice)
      2. 2) Start bubbling variables up in scope to the point they are visible to both functions/procedures. (bad choice)
      3. 3) Move all of the functions/procedures to the same scope so they can all see each other. (less bad than the other choices).

      One way to solve that problem is to push variables up in scope, which leads to all the familiar problems with global variables.

      I'm not sure what you are suggesting here, but it sounds like a bad idea. Just use lexical scoping, like Pascal does.

      I'm suggesting that pushing variables up in scope is an option. A bad option, but it is, in fact, and option. It sounds like a bad idea because it is a bad idea. I wouldn't recommend it, and in fact I didn't recommend it. I was mostly using it to set up the second option, which I clearly marked as better.

      The better option was to not nest your functions and procedures in the first place, so newer languages stopped supported that feature.

      C had two goals: (1) to be almost as useful as assembly language for systems programming (2) writing a C compiler should be easy. Lexical scoping of nested functions is missing from C because it made the compiler more complicated, not for any esoteric philosophical reasons like you suggest.

      Err... what "esoteric philosophical reasons" did I suggest? That the feature wasn't worth supporting so it was left out? Nested scopes, such as Pascal's, were the result of academic research into computer science, and from an academic, theoretical point of view they make a great deal of sense. However the benefits of nested scopes didn't translate that well outside of academia.

      To your point though, if K & R had thought nested scopes were valuable enough to include, they would of. Supporting nested scopes does make managing your symbol table more difficult, but not so much more so that they would not have included it if they thought it had value. Clearly, they didn't think it had enough value.

      Most notably, C didn't include it, and as a result it drastically simplified scoping rules to more or less what we're accustomed to now.

      Well, if you are so retarded that you find nesting of variable-names within functions hard, I can understand why you prefer a system with only two levels of variable-names, local and global.

      Right... I disagree with you, therefore I must be a retard. Nice critical thinking skills there...

      I don't find the scoping rules for nested functions and procedures hard, I think they are unnecessary. The reason I prefer scoping rules such as C's and Java's is because they are what ended up getting used anyway. If I were to start writing programs in Pascal or Delphi again, I wouldn't use nested functions or procedures because they add too much complexity without providing enough benefit. I have no use for byzantine structures when simple ones suffice.

      On the other hand, just about any other modern language includes some form of nesting of scopes, in a way that's harder to understand than Pascals nesting of functions.

    48. Re:Spaghetti-O Code by bdp · · Score: 1

      I'm having a little trouble following what you wrote. Could you give an example to clarify? I'm just curious if what you're talking about applies to Delphi (Object Pascal). I think I know what you mean, but I'm not really seeing the difference between having to pass values into nested functions versus passing them into non-nested ones. The only thing nesting gets you is the aforementioned "privacy" of the nested function to it's containing function.

      The real problem occurs when you need to go back later and make changes. You end up with things that can't see each other that now suddenly need to call each other and pass data. Consider this example:

      You get specs for several different types of reports from the business people. The specs are very clear, very straightforward. You implement all of these reports using one main procedure for each report with nested procedures and functions inside that main report procedure. Your code is as clear as it can be, you get the results you expect, they love reports, and you're a hero.

      Later on, they want some modifications to a report. It's a reasonable request; they'd just like to have a section from report A show up as a subsection in report B. At this point you could could just copy and paste all the code that generates that section from report A into report B, but this kind of code duplication is almost always a bad idea. You're only other choice at this point is to move the function or procedure you need up high enough in the scope hierarchy so that both reports can see it. Depending on how much nesting you did in the original reports, this could be pretty painful, since suddenly variables and functions and procedures that you expected to be in scope before aren't any longer, and now you have to pass them all as parameters, and... You get the idea. It just gets messy.

      If you had a code base that needed frequent modifications to allow new or different functionality, what little benefit there was to using nested functions are procedures is gone, and now it's just making your life miserable. You would've been better off if you just had all your functions and procedures at the same scope level from the start. This is essentially the scoping model modern languages use for functions and procedures.

      The big problem I have with nested functions is that yet again they make the code difficult to understand with the eyeballs. Worse yet, you have to define the function between the declaration of the outer function and the body of it. So you get this:

      This is a very good point. It gets difficult to tell just by looking at the code what level something was nested at, and where it could be called from.

    49. Re:Spaghetti-O Code by Maxime · · Score: 1
      Well, private and protected modifiers also come to mind...
      BTW:

      ...introduce a bug because that function was not designed or tested for use in isolation.

      And in the spirit of the topic, such functions become awkward to unit test, since you're extracting a unit of work out of a loop or control structure, that logically lives there. If you face that kind of problem, your function or method is ill designed. It doesn't matter if it's a one time use or a standard API member that you are writing, a function/method should _always_ be self contained.
      Separation of concern is a good practice that can (should) also be applied in non OO languages...
    50. Re:Spaghetti-O Code by stubob · · Score: 1

      I can't believe I have to respond to this, but most languages have a visibility scope modifier to method signatures. In Java and C (for example), you can declare a method "private" to only allow to allow access it from within the enclosing class. There are other levels of access to establish how accessible you want your method to be. PHP has no scoping ability. Everything is global.

      To the GP, if you've already created unit tests for the functionality of the loop, it should be trivial to refactor the tests to match the refactored code. After all, you haven't changed the behavior of the code, just its organization and appearance. Furthermore, by extracting the unit of work into a method, you're creating a single point of maintenance for your code, rather than multiple instances of the same logic.

      The bug you mention is already present. If your method can't handle unexpected data ranges, the method needs to handle it, not the calling method. You'd be more likely to catch it quicker if it was extracted.

      --
      Planning to be moderated ± 1: Bad Pun.
    51. Re:Spaghetti-O Code by real+gumby · · Score: 1

      This is the purpose of nested functions, a common feature of modern lisps and their cousins like scheme. Gnu C used to support them but due to constraints of C calling conventions of various processors (meaning you had to call code that lived on the stack) and because of you assign one to a function pointer you have to create a closure, they have been flushed.

      A shame because they're semantically an excellent modularity tool. It's especially galling since implementation constraints led to their demise.

    52. Re:Spaghetti-O Code by joto · · Score: 1

      While I agree that nested functions were mostly of academic interest, and that that was probably an important reason why they were left out of C, I still disagree with the notion that nested functions are somehow more complicated. As a programmer, I'm pretty used to recursion, so a function inside a function inside a function is pretty easy to handle, thank you!

      You complain that nesting "made it difficult to share values between functions", which is completely ridiculous. Nesting made that sharing possible, and the removal of nesting from e.g. C instead forced you to use hacks, such as passing struct-pointers around.

      While I'm sure you're right about the possibility of abusing nesting (any programming feature can be abused), that doesn't make it a bad feature per se. And neither does the fact that C doesn't have it, make it a bad feature either. More to the point, most good programming language features ever invented, aren't in C!

      Oh, and I fail to see what makes lambdas so different from nested functions. The only difference I can see, is that languages with lambdas are usually garbage collected, so that passing pointers to nested functions around is safer. But other than that, failing to give nested functions a name (in the local scope) is merely a matter of syntax, not of semantics.

    53. Re:Spaghetti-O Code by Anonymous Coward · · Score: 0

      There is a theoretical argument for lambda functions, and it is tied to one of the earliest theories in Computer Science (the Church-Turing Thesis), and the desire for an implementation language in this area leads to the adoption of pure functional languages, of which there are few *truly* pure functional languages. It becomes an exercise in evangelism to try to explain why pure functional languages are desirable, and I don't do evangelism.

      Outside of academic circles, the argument hardly has any meaning anyway, since people tend, justifiably, to be more interested in practical results. On the other hand many of the idealistic goals (such as Knuth's own) sometimes have little genuine value in the practical world, and sometimes are counterproductive. (Who *hasn't* witnessed failure as a result of over-formalism in a software development process?)

    54. Re:Spaghetti-O Code by bdp · · Score: 1

      While I agree that nested functions were mostly of academic interest, and that that was probably an important reason why they were left out of C, I still disagree with the notion that nested functions are somehow more complicated.

      I've never claimed that they are complicated. I've never claimed that they were hard. They do add complexity for essentially no benefit, so I do think they are an unnecessary complication. There is a clear difference between those that I hope you can see

      As a programmer, I'm pretty used to recursion, so a function inside a function inside a function is pretty easy to handle, thank you!

      Oh, you're a programmer...

      Big deal, so am I. In fact I've been one long enough that I've used Pascal in a professional setting, so save your lame appeals to authority. Again, I've never said it was hard to understand.

      You complain that nesting "made it difficult to share values between functions", which is completely ridiculous. Nesting made that sharing possible, and the removal of nesting from e.g. C instead forced you to use hacks, such as passing struct-pointers around.

      Sure, when you wrote a program you never had to touch again (like your computer science homework), nested functions and procedures work just fine. However, they become a burden when you try to refactor things. As far as I'm concerned, making it easy to go in and change things is what good design is all about. If you never need to go back and change anything, it doesn't matter how you wrote it. You could write all your code in a giant chunk and it would make no difference.

      To you're point about sharing values between functions and procedures, nesting your functions and procedures only makes bad practices simple. To share values, you either pass them as parameters (preferred), or you have them high enough in the scope hierarchy that all the functions/procedures that need it can see it (*not* preferred). If you're passing values as parameters all that matters is that the functions/procedures can see the each other, which is made simpler by having everything at the same scope level. If you are passing information around using variables inside nested scopes, all you are doing is using semi-global variables instead of actual global variables. You still have all the problems that come along with using variables that aren't local to a specific block of code, only now it's worse because you have more than one "global" scope that you have to concern yourself with. Once again, more complexity without benefit.

      While I'm sure you're right about the possibility of abusing nesting (any programming feature can be abused), that doesn't make it a bad feature per se. And neither does the fact that C doesn't have it, make it a bad feature either. More to the point, most good programming language features ever invented, aren't in C!

      You're correct, you can abuse any language feature. The difference here is, is wasn't abusing the feature, it was an unfortunate side effect of using the feature as intended

      Oh, and I fail to see what makes lambdas so different from nested functions. The only difference I can see, is that languages with lambdas are usually garbage collected, so that passing pointers to nested functions around is safer. But other than that, failing to give nested functions a name (in the local scope) is merely a matter of syntax, not of semantics.

      On this, I think you're probably technically right. They're intended to be used as little one line, convenience functions, but intent doesn't prevent it from being used in other ways. You could certainly abuse lambdas to write much longer functions and call them the same thing as Pascal's nested functions and procedures.

    55. Re:Spaghetti-O Code by bdp · · Score: 1

      As a programmer, I'm pretty used to recursion, so a function inside a function inside a function is pretty easy to handle, thank you!

      A function inside a function inside a function isn't recursion, it's just a nested function inside a nested function. Perhaps you should review?

    56. Re:Spaghetti-O Code by joto · · Score: 1

      Hiding local declarations in a nested scope is essentially encapsulation. Encapsulation is usually viewed as a GOOD THING among most programmers.

      Now, I haven't worked much with Pascal, given that I'm probably much younger than you. But I have worked a lot with SML, and in SML nested functions are invaluable. In short, you can't get much work done without them, at least if you value somewhat clean and reusable code. Now, of course, you don't put big complicated things nesting inside each other there either, there's a module system to do that kind of encapsulation, but if you need one or two small helper functions inside a function body, local and let are your friends!

      I have a hard time understanding your assertion that using nested functions as intended leads to maintenance nightmare. My experience is exactly the opposite. Failing to use nested functions lead to uglier code, putting huge declarations inside a function is not what's intended (use the module system for that), and lifting stuff out, and adding a paramater is usually easy. But then again, our perspectives might differ.

    57. Re:Spaghetti-O Code by bdp · · Score: 1

      Hiding local declarations in a nested scope is essentially encapsulation. Encapsulation is usually viewed as a GOOD THING among most programmers.

      Encapsulation is a good thing, but remember that Pascal is a procedural language designed for structured programming, not object oriented programming. Pascal has certainly been updated to things like the Modula language family and stuff like Object Pascal (Delphi), but in standard run of the mill Pascal those features just weren't there. Pascal didn't even start out with modules; those came when Wirth designed Modula-2.

      Now, I haven't worked much with Pascal, given that I'm probably much younger than you. But I have worked a lot with SML, and in SML nested functions are invaluable. In short, you can't get much work done without them, at least if you value somewhat clean and reusable code. Now, of course, you don't put big complicated things nesting inside each other there either, there's a module system to do that kind of encapsulation, but if you need one or two small helper functions inside a function body, local and let are your friends!

      Aha! I think I see where our disconnect is. SML is a functional programming language, not an imperative language like Pascal, C, and Java. These are two different language families, and operate in qualitatively different ways. In a functional programming language, the ability to declare a function anywhere is essential, whereas in an imperative language the ability to do so is simply a feature.

      I have a hard time understanding your assertion that using nested functions as intended leads to maintenance nightmare. My experience is exactly the opposite. Failing to use nested functions lead to uglier code, putting huge declarations inside a function is not what's intended (use the module system for that), and lifting stuff out, and adding a paramater is usually easy. But then again, our perspectives might differ.

      Check out this response that I wrote to another post. I'd just give you the same example of how maintenance problems happen. Basically, it just gets messy, and nesting your functions and procedures just makes it a more complicated mess to sort out. In my experience, things turn to spaghetti code during the maintenance phase, so as a general rule I think that anything you can do that simplifies maintenance is probably worth it. To me, having all your procedures and functions at the same scope level makes maintenance much easier, and all other things being equal, it's the trade-off that I would make.

    58. Re:Spaghetti-O Code by Kuros_overkill · · Score: 1

      Oh, I have a whole collection of wtf's saved up. As soon as I leave my current job, they're all getting sent...

    59. Re:Spaghetti-O Code by Kuros_overkill · · Score: 1

      Oh, so you've seen the code then...

    60. Re:Spaghetti-O Code by Anonymous Coward · · Score: 0

      stored procedures... ect...

      "etc.".

    61. Re:Spaghetti-O Code by Anonymous Coward · · Score: 0
      It seems that both you and your parent poster are simply not willing to put up some deep thinking into properly analyzing those loops. "Shorten thee loops" is not a recipe that can be automatically deployed by some mindless simple underpants-gnome business plan type algorithm (extract body of the loop into function, call function from loop, ????, profit!!!). Your loops being too long is just a sign, a symptom, that you thought of them poorly.

      There is also a risk that you or a maintenance programmer might re-use such a "function"

      I see ... , a fellow C programmer ... oh well, if they won't let you use Pascal (local scope subroutines) or C++ (private methods), at least name those auxiliary functions something like caller function name_called function descriptive name, and declare them static, of course. Besides, design your auxiliary functions so that they really mean something, some single atomic operation in the loop pass. Make them reusable, rather then fear them being reused. Perhaps there will be a need for them after all.
    62. Re:Spaghetti-O Code by Eivind+Eklund · · Score: 1
      They're often supported in a slightly different form, a form that I believe is probably better than the "obvious" form of these.

      As for undeclaring a variable, I do not know of any language that support this directly. However, it is common to do this through creating a new scope around the area where you want the variable to be visible. This is standard in C and derived languages, including Java and Perl.

      I often find local functions useful; I less often find smaller scopes useful. They just don't do anything for the kind of code I write anymore. I had a period of maybe 5 or 10 years after I discovered them where I used them heavily, and then my style evolved away from it.

      Eivind.

      --
      Doubting the existence of evolution is like doubting the existence of China: It just shows that you're uninformed.
  42. How is that flamebait? by zullnero · · Score: 3, Interesting

    Seriously, if you're "religious" about unit testing and mock objects, then you really need to revise the way you live your life.

    It's just a good habit to get into, if you take it seriously and don't just create tests that test silly little things like "is my text box centered where I slapped it on the form with gui form tool" type of stuff. That's kind of the point he's trying to make, that you program intelligently in the first place to avoid having an insane amount of redundant tests to pass each time you build.

    I've been doing literate programming (well, as close as you can with C and its derivative languages) for a long time now. I've watched XP coders take that literacy and chop it all up because "it didn't look pretty enough". The idea with making something literate is to make it so clear that you can reduce the total numbers of tests needed to make that code pass to only ones that test the actual expected outputs of that function. That's something that intelligent coders who don't just follow the Agile rulebook, but apply it effectively, can do. I don't know how many times I'd see a piece of code that did one simple task, had one test to test the output of that test, then another coder drops 3 more tests because they "didn't feel comfortable with only one" without specifying WHY. That is how you get into having redundant tests that muck up your test infrastructure.

    1. Re:How is that flamebait? by 12357bd · · Score: 1

      Too much attention to testing indicates poor code understanding, no test can detect architectural-design failures. Is hard to say-it but IMO current testing practices are a clear indication of how low medium programming skills are. Test don't add knowledge, they just check for already know questions.

      It reminds me a tipical source of problems. Libraries being used without proper understanding of what's going on inside the libraries code.

      --
      What's in a sig?
  43. It's the same philosophy that K&R impart... by galimore · · Score: 3, Informative

    I'll forgive you for being a Java developer, but the fathers of C have always cited readability first (The C Programming Language ~1978). They don't call it "literate programming", which is simply a trendy buzzword, but the idea of programming for readability has been around for an extremely long time.

    1. Re:It's the same philosophy that K&R impart... by lekikui · · Score: 1

      Literate programming in the context mentioned refers to a hybrid of a programming language and TeX, designed for the documentation first, and the actual program incidentally. It's not a buzzword by a long way.

      And yes, there is a system for combining it with C.

      --
      "Lisp ... made me aware that software could be close to executable mathematics." - L. Peter Deutsch
    2. Re:It's the same philosophy that K&R impart... by scotch · · Score: 1

      I'm surprised so many in this forum have not heard of "literate programming" to mean what it means in this context.

      --
      XML causes global warming.
  44. Maybe More Like 50-75 Times a Day by eldavojohn · · Score: 5, Funny
    Well, I guess I might as well try to defend myself.

    Well, if you are testing your code 200 times a day, you are almost certainly wasting time. Lets run some numbers:

    Assuming you work an 8 hour day, that means you are testing your code every 2 minutes and 24 seconds. Given that most of your tests will take this long to run (you've got a suite of them right?), that leaves you with zero time to actually do the work you are testing.

    Frankly, if you are using Unit Tests you should be using them after major chunks of work, not in a trial and error fashion. Now if you were using them in a trial and error fashion - "lets change this, run the tests and see if they pass, no that didn't work, lets try this", etc, I could understand how you hit the 200 times per day mark. That is a completely respectable position to take. I used to work in this way during college. My several thousand unit tests do take 2-3 minutes to build. My estimate of 200 times was probably over shot and should be more like 50-75 times a day. I would also like to point out that I can continue developing while the tests run. I use Maven2 as a build tool and enjoy it immensely, it helps me do test driven development. Since you are obviously far superior to me, I will assume you know what this means but point it out to the rest of the idiots like myself. TDD is where you write your unit tests before you code. Then you satisfy your unit tests with code. When you need to change code, you change the tests and then you change the code to fix the tests. Crazy waste of time right?

    If you are coding in a trial and error fashion and using unit tests that way, I'd advise getting some tuition or changing career. Thanks, I love you too.

    But the thing is that my employer loves my work and my code rarely breaks. Now why is that? Perhaps because I'm regression testing at all times? Perhaps it's because I take the time to think about things before I do them and, as a result, I really begin to understand what it is that I'm writing.

    An added benefit is that I've found I can look at my or others unit tests and really understand what was going through their mind when the first wrote the method that I am expanding. It's quite interesting, but I'm sure you are a supreme being like Knuth and don't bother with such trivialities.

    I'm a highly productive individual ... Congratulations, I'm glad that you view yourself in such light while being able to cut me down with a few keystrokes. I'm also glad I don't work with you. Really glad. I would sacrifice all productivity in the name of being able to come into work and not feel like shit.

    Making the unit tests part of the build process is like requiring a roadworthiness test for you car every one mile you drive it. Sure the car is safe, but its not very productive at getting you from A to B, you could walk faster. I respect your decision to use a car analogy here although I find it flawed as I most often do.

    Here's a question: how much time do you spend working out what happened when your code breaks? TDD is a trivial amount of time compared to that. I am concerned about my software in the present and future. I wish others were also.

    What counts is that when you run the unit tests, they pass, and that they accurately test the conditions that need testing. I disagree with you. I run unit tests that fail all the time--on purpose.

    I know it will most likely result in a swift abrasive response but I implore your highness to really spend some time understanding how unit tests can help the really stupid coders (like me).
    --
    My work here is dung.
    1. Re:Maybe More Like 50-75 Times a Day by PipingSnail · · Score: 1

      Well, I guess I might as well try to defend myself.

      Why? I wasnt' attacking you. I was commenting on the 200 times a day. Something that you've revoked.

      then you change the code to fix the tests. Crazy waste of time right? Yes, if you are coding trial and error. You should be coding what you know to be right, then testing that. There is a huge difference in approaches.

      If you are coding in a trial and error fashion and using unit tests that way, I'd advise getting some tuition or changing career.

      Thanks, I love you too. You are more than welcome. Trial and error is not the way to go about building a successful career.

      Here's a question: how much time do you spend working out what happened when your code breaks? Practically none. Because I don't do trial and error. You don't need to do trial and error to beleive in unit tests.

      What counts is that when you run the unit tests, they pass, and that they accurately test the conditions that need testing. I disagree with you.

      You disagree that what matters when you run unit tests is that you run them at the right time, that they test the right thing and that they pass? Then why are you using them? If you don't care about the quality of them, what is the point?

      I know it will most likely result in a swift abrasive response

      Hardly, unlike you, I haven't personalised my response. You should try re-reading my first post. It was an attack on a possible method (trial and error), not an attack on you, as a person. It was filled with caveats (if statements) to cope with multiple conditions. You have self-selected yourself as a trial and error coder and you are proud of it (based on your reply). Amazing.

      It is quite plausible that I am highly productive. Its also highly plausible that other people are too, some of which will be more productive than I. Its also highly plausible that, you should choose to accept those statements, perhaps my observations are correct. The instant I read 200 I knew you were wrong.

      As to your comment that you can work while the tests are running - how in that case can you decide what to do next if you don't yet know what you last did worked. Thats the blind leading the blind.

      Flame away if you want. I'm not entering in a flame war with you. Your methodology is wrong. Unit tests work, TDD works, but not the way you describe you use it, trial and error is NOT how to use Unit tests or TDD, design and test is. Huge difference. If you can't implement your design without guessing, that is trial and error.

    2. Re:Maybe More Like 50-75 Times a Day by bit01 · · Score: 1

      I know it will most likely result in a swift abrasive response but I implore your highness to really spend some time understanding how unit tests can help the really stupid coders (like me).

      Ok, here's my abrasive response :-) : Unit tests, as tests, are an almost complete waste of time.

      They do nothing more than get a hopefully independent test programmer to replicate exactly the same logic as part of the original program, typically in an incompatible, unstructured language not designed for large systems, and than compare to see if there's any inconsistency in the outputs of the two programs. All the examination, handling and verification of special cases the test programmer does should've been done by the original programmer anyway.

      In other words unit testing is just a bastardized version of the explicit n-way programming sometimes done in the aerospace industry. It may be marginally useful but it's costly and those resources are probably better spent on the original program. Or from another point of view unit tests are just a form of bureaucratic oversight, useful to make sure the original programmer toes the line if they're likely to be slack, such as in verifying formal contract requirements. That doesn't work if the two programmers are one and the same.

      I rarely unit test. But I do write programs that are paranoid at every step of the way about their inputs and outputs, including the handling of boundary conditions, parallel process coordination and system call status', I don't pretend that a one in a thousand chance is no chance (like many poor programmers do e.g. disk full or inconveniently timed interrupt, race condition or garbage collection; incidentally unit tests rarely cover those) and I do verify and do one-off tests of my code until I am sure I understand it. In a sense I put the units tests in the programs themselves. I don't waste time with pretty but incompatible test languages and frameworks because they add almost no value.

      "Unit tests", the terminology, is a partial example of an all too common failing in the software profession, that of confusing terminology with reality. Just because something has a different name (unit test != program) doesn't mean it's a different object. Unfortunately because of the amorphous nature of software, with no well defined boundaries, it's far too easy to create and be confused by such terminology.

      ---

      Don't be a programmer-bureaucrat; someone who substitutes marketing buzzwords and software bloat for verifiable improvements.

    3. Re:Maybe More Like 50-75 Times a Day by Anonymous Coward · · Score: 0

      Ok, here's my abrasive response :-) : Unit tests, as tests, are an almost complete waste of time.

      Attention people.. I present to you the worlds one and only 100% bug free, 100% requirements meeting single build coder! Right to production everytime! Come on.. you have got to be kidding me right? Are you seriously telling me that you code 100% dead on for every piece of code you put out? You never miss 1 item? Sorry, but I call BS of the highest quality.
  45. Re:To test code for literate programming complianc by lekikui · · Score: 1

    There is. It's called WEB, and, while it was originally written for Pascal code, has been extended to a variety of languages. Derivatives exist in several more languages, and more general systems for any language you like.

    Incidentally, guess who's the author. A hint, you just read an interview with the guy.

    --
    "Lisp ... made me aware that software could be close to executable mathematics." - L. Peter Deutsch
  46. I agree, sort of by Kupfernigk · · Score: 1
    I think the real problem is still, as you say, that many programmers do not think about boundary and error conditions, and furthermore they do not write comments about the right things.

    Unit testing has its place when designing bits of code for the first time, but experienced programmers will know how to deal with things like (for instance) missing parameters on returned web forms, passed-in classes that have not been initialised, and possible arithmetic overflow/divide by zero.

    The commonest problems that I see in the field are:

    • Comments that tell me things that are absolutely obvious, while awkward workarounds are uncommented.
    • Excessive levels of abstraction, where overlaid interfaces and extended classes are used to conceal the fact that the programmer has really done almost no work and is in fact just passing some data straight into a library.
    • Overly complex error handling methods that actually confuse the real source of an error (e.g. in Java creating loads of Exception classes that still just end up writing a short comment to stdout).
    • Error handling that is not around properly modularised code blocks so that the trapped error is not actually relevant to the main business of the block.

    I suspect that anybody intelligent enough to have ideas about how code should be documented and tested that make any kind of sense, is also likely to produce readable and testable code. People without those skills will not use testing and documentation efficiently.

    At the end of the day there is no substitute for designing a proper end of the line test suite, and applying it to the application as a whole, with sufficiently good error handling that bugs can be traced.

    --
    From scarped cliff or quarried stone she cries "A thousand types are gone, I care for nothing, no not one."
  47. Out of favor by illegalcortex · · Score: 3, Interesting

    It's also out of favor because of how much of the real world of programming works. My very small company does a lot of work for a very, very large company. At my small company, we have one layer of management - the owner of the company. Everyone else is in the level of "not an owner of the company."

    At the large company, there are a multitude of layers of management. Any software they build require extensive specifications and documentation far in advance of laying down any code. The decide all the aspects of the software before it's written. At my company, the boss just gives us a general outline of what he's thinking about and ask us to feel out the idea. We use a RAD environment and will often have a first iteration within a week. This version tends to get completely, sometimes multiple times. We do not document any of this in advance because the usable version may differ so much from the original ideas.

    At the large company, their projects tend to take years and years, go far over budget and typically are much less useful than they had originally hoped. As a bonus, they are usually bug-ridden and unstable. Many times they just eventually get canceled by the new layer of management, who then get awards for this "cost saving measure." At my company, our projects are typically finished far in advance for a tiny price. They are typically of very high quality, with very minor bugs which we fix rather quickly.

    This large company frequently hires our company to build software rather than trying to do it internally. They are usually amazed at the things we can do.

    Something like "literate programming" is completely anathema to how our company works. If we started trying to write specifications in advance of figuring out what product our clients actually want (as opposed to what they think they want at the start of the process).

    Now, I will state that our company only works because we don't hire idiots or slackers. Also, I am fully aware that this is not a good way to, for example, design nuclear power plant software or a baggage control system. But for businesses, all that documentation and "thinking" can just cloak that fact that the people building the software don't know what they are doing.

    1. Re:Out of favor by Coryoth · · Score: 2, Informative

      I think, perhaps, you're missing the point. Go ahead, build a prototype and try out ideas. Do the Brooks thing, and build one to throw away. Work out exactly what it is you want to do via experimentation. None of that contradicts literate programming, or "thinking first": the prototypes, the messing around, that's part of the thinking (stage one really). Once you've gone through your iterations and want to finalise something... well at that point you do have some specs, you should know what you want to build; and at that point you can use literate programming, and you can do some design by contract, and make the finalised version robust, well documented, and easily maintainable and reuasable. Building prototypes is not failing to "think first"; not "thinking first" is shipping the nth iteration of the prototype as is and calling it done.

    2. Re:Out of favor by illegalcortex · · Score: 1

      No, actually I'm not missing the point. I think perhaps you are. We get to the final system through iterations. But you can't build some half-assed mock up of the system and actually get the same results as building real versions of the system. So you do all the work of making a working system. So at that point, you can start over, abstracts some specs and build again. OR, you can take the perfectly working versions and ship it. Which do you think is more likely to happen in a business situation where time is money? What about if you plan on selling a new version next year? Can you now see my point about why the latter is "out of favor" because of real world considerations?

    3. Re:Out of favor by kalidasa · · Score: 1

      Good god, you think that is a good practice? Keep debugging and rewriting until you stumble upon a working implementation?

    4. Re:Out of favor by jadavis · · Score: 1

      Keep debugging and rewriting until you stumble upon a working implementation?

      It works great for user interfaces. It's terrible for systems with long term consequences.

      Unfortunately, there are many people who can't distinguish between the two.

      --
      Social scientists are inspired by theories; scientists are humbled by facts.
    5. Re:Out of favor by zippthorne · · Score: 1

      In fact, that's precisely what he's saying you're doing.

      He's saying you're shipping the product one generation away from finished. One, basically complete rewrite of the "final" iteration, but formally and in a documentation-first way, using the lessons you learned producing that last iteration.

      It may be that you simply don't have the resources to actually finish, and that's the reason you're calling prototype0.9f the finished product, but he's saying you're really not quite done until your "code" is basically one big academic paper with examples, and wherein the examples constitute the entirety of the project.

      If you don't understand why you have different opinions about "done-ness" then you are missing the point, and you will never understand as long as your mind is closed. Hint: is != ought.

      --
      Can you be Even More Awesome?!
    6. Re:Out of favor by tpz · · Score: 1

      Who said anything about stumbling upon a working implementation? We're talking about iterative development here.

      The problem with the concept of literate programming is simply this: Literate programming is for all intents and purposes incompatible with iterative development methodologies, the use of which vastly outstrips the use of non (or barely) iterative development methodologies.

      That's it, there's nothing else to it.

    7. Re:Out of favor by Coryoth · · Score: 2, Insightful

      One would hope that you get to the final system design by iterative prototyping, which you then clean up, refactor, and rewrite into a nice codebase that doesn't have the evolved and iterative cruft, and is suitably documented (it's this last step where literate programming an come, though you can introduce some incrementally as modules and subsystems get frozen and rewritten). Who knows, maybe you do just ship the first thing you can get to work. What I do know is that in the business world where time is money, the clean well documented final version is going to involve a lot less time (and hence a lot less money) to maintain and debug and patch. And what if I want a new version next year? Well I would certainly prefer to have a clean readable well documented codebase to work from than "whatever worked" code. Maybe that's just me though. Different people work differently, and I'm sure you do what works best for you.

    8. Re:Out of favor by Coryoth · · Score: 1

      Well it's only incompatible if you just ship whatever the last iterating happened to be, rather than taking away all the lessons learned from those iterations (including, potentially, large chunks of the code) and writing a nice clean final version with good documentation (the documentation can, of course, include many of those "lessons learned", particularly why various design decisions wwere made etc.); that version can make good use of literate programming. In that sense literate programming is actually pefectly complementary to iterative/agile design. The other complementary technique that many agile/iterative/TDD fans seem to think is incompatible for some reason is lightweight formal methods -- it's actually very nicely complementary and goes espcially well alongside TDD. Google "lightweight formal methods" + "agile" sometime.

    9. Re:Out of favor by Tony+Hoyle · · Score: 1

      It's a rare manager who won't ship a working, but crufty version over waiting another 3 months for a 'pretty' version. Next year be damned.... the manager will be manager of someone else by then.

      Personally I do the iterative thing but it's over a longer period than a release cycle - it tends to go mockup/demo (show the poss I'm not making it up and I can write this stuff.. he invariably then goes off with that and tells all the customers it's the finished product but 'needs a few bugs working out'). Second iteration is the first release and has to be done to a deadline (boss sells something, he's happy). Then I continue to refactor parts of the code as time allows until over time eventually I have something I'm happy with.

      Of course for the third stage to work I have to write in a highly modular fashion... typically I can rip entire layers out of the code without disturbing the operation of the rest of it. I'd hate to try that on anything even slightly monolithic.

    10. Re:Out of favor by illegalcortex · · Score: 1

      As many people have pointed out, you seem to be a bit mistaken about what I'm talking about. When the client start out not really knowing what they want (as is the case in a large number of situations), it's impossible to sit down and design a solution from the beginning. It's also sometimes very shortsighted to design an interface when you don't even know all the functionality that will be in it yet.

      If you work only with clients that know everything they want before you build it, more power to you. I'll continue to cash in on the other 99% of the market.

    11. Re:Out of favor by FishWithAHammer · · Score: 1

      I agree with much of what you're saying, and I'd love to see literate programming in more common use.

      But you haven't answered the critical question: why would a company "waste time" going through the song and dance of literate programming if they aren't going to realize any tangible benefits from it? Yes, yes, I know, easier expansion and all of that--but why would that factor into the decisions of a manager who isn't likely to be managing the same project two, three years down the road?

      --
      "You can either have software quality or you can have pointer arithmetic, but you cannot have both at the same time."
    12. Re:Out of favor by Coryoth · · Score: 1

      Unfortunately there's not much you can do with a short term, next quarter, driven outlook that fails to do any accounting for maintenance and expansion. If your managers are that stupid then yes, you probably are screwed.

    13. Re:Out of favor by jcast · · Score: 1

      Where I work, the software changes fast enough, I can already show my manager the results of design improvements I put in only a few months ago. That's one way to do this: stay in communication, incrementally improve things, and make sue the next layer up knows every time an improvement made your life easier or got a feature added or bug squashed sooner.

      I also make a point of reminding them, every time we see a bug caused by a system issue I want to fix. That helps them see the ROI, too.

      --
      There are reasons why democracy does not work nearly as well as capitalism.
      -- David D. Friedman
    14. Re:Out of favor by elronxenu · · Score: 1
      I think the salient point is that each successive iteration of the code already contains the lessons learned from the previous iteration. There is no need to go away and redesign the system because it's design has already been morphed through the iterations.

      In fact, a further redesign might have the effect of undoing some of the lessons learned, and itself require one or two improvement cycles before it is good.

    15. Re:Out of favor by Coryoth · · Score: 1

      Unless you are doing a rewrite at several iterations you are still ending up with "evolved" code, which is almost always a lot less pretty and a lot less maintainable than the same design written cleanly with the ultimnate final design decisions in mind right when you start.

    16. Re:Out of favor by Anonymous Coward · · Score: 0

      Methinks you just don't know what "literate programming" is - the idea is that you should be able to read code the way you read a book and understand it without having to cross-reference umpteen dozen other documents.

      Literate code has variables that make sense and aren't stupid things like "i", or "obj" or "tmp". Literate code uses proper indenting and values readability. Literate coding uses comments to describe WHY a routine does something, being as the HOW is already explained in the code.

      Your company probably practises literate programming and isn't even aware of it.

    17. Re:Out of favor by illegalcortex · · Score: 1

      No, I know all about literate programming. A friend was forced to study it in college, and I was interested enough that I checked it out.

      Rereading your post a few times, I'm actually beginning to wonder if you know what literate programming is. It's not just well written, well commented code. That's just called "well written, well commented code."

      Literate programming is a lot more involved than just that. People were doing that long before Knuth came along and coined the term "literate programming" for his idea of the "programs as documentation with occasional code."

    18. Re:Out of favor by ratboy666 · · Score: 1

      If a client doesn't have a clear idea, I help them by working through a process. I will help develop a "Requirements Specification". We need to be able to isolate what we will build.

      This needs to be known, because we need to know the problem we are addressing. After this is settled, we work on a "Design Specification". That will tell us how we will go about building that thing.

      Simply jumping in and coding is, well, wrong. Without understanding where you want to go, how will you know what direction to go in?

      Of course GUIs can actually promote this. If all applications look the same, you can produce an application that looks like all the others. What it does may be of little concern to you (and, given your methodology, it probably isn't). You can then fill in "functionality" fed from the client. This will, of course, model around the GUI (and not the actual problem domain). There will be little choice of unifying concept. There will be a lot of "duplicated" code, which will make you think that a "reuse" policy would be a good idea.

      I would suggest that you supply a higher level of service to your client. Supply a real design service. This will benefit your coding as well -- you will know what you need to code.

      --
      Just another "Cubible(sic) Joe" 2 17 3061
  48. Worst Summary Ever by TerranFury · · Score: 5, Insightful

    The summary sounds like it was written by the headline-producing monkeys at Fox, CNN -- or hell, at the Jerry Springer show. Donald Knuth is not "playing hardball." Nobody needs to call the interview "raw and uncut," or "unplugged."

    The interview has almost nothing to do with unit testing and the little Knuth does have to say about the practice is hardly "ripping."

    When will people stop sullying peoples' good names by sensationalizing everything they say?

    Knuth is a well-respected figure who makes moderate, thoughtful statements. From the summary, you'd think he was a trash-talking pro-wrestler.

    1. Re:Worst Summary Ever by eldavojohn · · Score: 1, Insightful

      Worst Summary Ever Thanks. I really appreciate the amount of respect and appreciation I get from this site.

      Donald Knuth is not "playing hardball." Nobody needs to call the interview "raw and uncut," or "unplugged." Wow, where exactly did I (or CmdrTaco) use any of those phrases?

      Calling something a "complete waste of time" is, in my book at least, "ripping" on something. I didn't "sully his good name," I posted what I found interesting. You should also point out he has prostate cancer and I left that out. God, what horrible spin I used! You'd think I was talking about someone whose life wasn't at risk, the way I spun that summary!

      Knuth is a well-respected figure who makes moderate, thoughtful statements. I happen to disagree with his stances on multi-core chips and unit testing. I didn't find anything thoughtful about what he said and really wish he would have elaborated on why unit testing is a complete waste of time.

      From the summary, you'd think he was a trash-talking pro-wrestler. Actually, after reading the article, I did find him to be a bit preachy. Apparently you and everyone else find him unquestionably correct in all his statements from that interview.

      And also, people are claiming he said these things "in passing." Which I find to be a phrase used when you want to avoid owning up to something you said. If I call you a "whiney bitch in passing" that doesn't lessen it one bit. Knuth claims no one should listen to him. Why is he publishing books if no one should listen to him?

      The guy said some inflammatory comments. If you read the following posts, you'll realize that I wasn't the only one that found them inflammatory or controversial.
      --
      My work here is dung.
    2. Re:Worst Summary Ever by sholden · · Score: 1

      Donald Knuth is not "playing hardball." Nobody needs to call the interview "raw and uncut," or "unplugged."

      Wow, where exactly did I (or CmdrTaco) use any of those phrases?

      I would assume he was just playing the same game as claiming Knuth said "waste of time", which has a completely different connotation than "lots of time is wasted on activities that I simply never need to perform or even think about".

      Knuth is a well-respected figure who makes moderate, thoughtful statements.

      I happen to disagree with his stances on multi-core chips and unit testing. I didn't find anything thoughtful about what he said and really wish he would have elaborated on why unit testing is a complete waste of time.

      It's Knuth, Mr. "Beware of bugs in the above code; I have only proved it correct, not tried it." Unit testing is the anti-thesis of proving the code is correct before even asking the compiler if it compiles. But again, with "waste of time" - that is not what he said. He even gave the situation he thinks it's useful in...

      . Why is he publishing books if no one should listen to him?

      Please point me to Knuth's books on multi-core processors and unit testing.

    3. Re:Worst Summary Ever by lekikui · · Score: 2, Interesting

      Worst Summary Ever Thanks. I really appreciate the amount of respect and appreciation I get from this site.

      Donald Knuth is not "playing hardball." Nobody needs to call the interview "raw and uncut," or "unplugged." Wow, where exactly did I (or CmdrTaco) use any of those phrases? Calling something a "complete waste of time" is, in my book at least, "ripping" on something. I didn't "sully his good name," I posted what I found interesting. You should also point out he has prostate cancer and I left that out. God, what horrible spin I used! You'd think I was talking about someone whose life wasn't at risk, the way I spun that summary! Well, speaking for myself, I did find the summary fairly heavily spun. In general, it seemed to take statements out of context somewhat, turning "I generally don't find unit tests useful" into "Knuth rips on unit tests". He mentions that there are definite applications for multicore work, but that he's not in that field. Basically, the summary struck me as being spun to make his statements seem more controversial.

      Knuth is a well-respected figure who makes moderate, thoughtful statements. I happen to disagree with his stances on multi-core chips and unit testing. I didn't find anything thoughtful about what he said and really wish he would have elaborated on why unit testing is a complete waste of time. Look, shall we quote what he said about unit testing?

      As to your real question, the idea of immediate compilation and "unit tests" appeals to me only rarely, when Iâ(TM)m feeling my way in a totally unknown environment and need feedback about what works and what doesnâ(TM)t. Otherwise, lots of time is wasted on activities that I simply never need to perform or even think about. Nothing needs to be "mocked up." That doesn't look like he ripped on it. He said, basically, that he doesn't find it useful, and that it tends to waste time because of the sort of work he's doing.

      In other words, he considered the question, and provided the answer that described what he found for his work. Not what you'll find for your work, or anything like that. Just what he finds works for him.

      From the summary, you'd think he was a trash-talking pro-wrestler. Actually, after reading the article, I did find him to be a bit preachy. Apparently you and everyone else find him unquestionably correct in all his statements from that interview. I'll admit to having generally found him right. When he's talking about a subject he's not an expert on, he mentions that. He says why his opinion isn't the best on all topics. He seems to be generally careful about what he's saying.

      Where what he says is likely to be personal bias, he mentions that. So weight it as you think is relevant, given who he is.

      Yes, there's stuff in there I reckon is probably wrong. There's also an awful lot that's probably right, and he's generally been careful and thoughtful about what he's saying.

      And also, people are claiming he said these things "in passing." Which I find to be a phrase used when you want to avoid owning up to something you said. If I call you a "whiney bitch in passing" that doesn't lessen it one bit. Knuth claims no one should listen to him. Why is he publishing books if no one should listen to him? No, he said, quite regularly, that his opinion on some things wasn't going to be very useful, as he wasn't that good at them. His books are about the topics he is good at. He doesn't write them about software development best practice, or economic, or parallel computation. He deals with the topics he knows, and that's all he expects to be listened to about.

      The guy said some inflammatory comments. If you read the following posts, you'll realize that I wasn't the only one that found them inflammatory or controversial. No. Knuth generally was cautious about his statements. Do please find me some actually inflammatory comments from there. Go on, direct quotes, not just rephrasings or spin.
      --
      "Lisp ... made me aware that software could be close to executable mathematics." - L. Peter Deutsch
    4. Re:Worst Summary Ever by kramulous · · Score: 1

      Read your 'right of reply' and still agree with the GP. Posting was far too biased and will be illustrated by a large response in comments.

      Having read a little more of Knuth than some random interview, there is a lot more to back up his dislike of unit testing. It's a philosophy thing. You do some pen and paper work about the algorithm your working on, structuring and compartmentalising it into functional sections. Proving that it will work rather than coding some random code up and hoping that your [possible non-exhaustive] testing will reveal the 'bugs' (quoting because the answers may be correct, just using the wrong algorithm).

      --
      .
    5. Re:Worst Summary Ever by TerranFury · · Score: 1

      Worst Summary Ever

      Thanks. I really appreciate the amount of respect and appreciation I get from this site.

      Actually, I think I'd assumed that you'd been borrowing heavily from another source in your summary, so I'm surprised to find you replying personally. I don't think I'd have been quite so undiplomatic if I'd realized I was commenting on a fellow slashdotter's summary, and not the cut-and-pasted writing of a staff writer at informit. I probably wouldn't have used quite so provocative a title as "Worst Summary Ever," for instance.

      Let me say that there are some very good things about your summary. I'm serious here. First, you introduced Donald Knuth; that was good. A quick topic introduction is something easy to do yet too-often left out of Slashdot summaries; I appreciate that you took the time to include one. Your cross-references to other slashdot stories were also good, as was your link to a definition of 'literate programming.'

      Donald Knuth is not "playing hardball." Nobody needs to call the interview "raw and uncut," or "unplugged."

      Wow, where exactly did I (or CmdrTaco) use any of those phrases?

      OK, you've got a fair point. I was projecting a bit. I see that, very often, the mainstream media spins what people say to make for a better story, and in the process get the public unfairly angry at someone who was simply misrepresented.

      That said, I still do get a little bit of that taste from your summary -- of a tendency to sensationalize the unsensational to make for a better headline, without much concern for what it means to the people who are being represented. This is a mistake I make too sometimes, but I've gotten rather sensitive to it, and I think we should avoid it.

      Calling something a "complete waste of time" is, in my book at least, "ripping" on something. I didn't "sully his good name," I posted what I found interesting.

      See, that's what I thought was out of context. But some other posters have replied on this topic, so I won't repeat them.

      You should also point out he has prostate cancer and I left that out. God, what horrible spin I used! You'd think I was talking about someone whose life wasn't at risk, the way I spun that summary!

      I wasn't aware of that; that's really too bad. I'm not sure what your point is here, though. Although it's conceivable that you could have tastefully included a reference to Knuth's health problems, I think it's probably for the best that you left that out, as, I agree, it's not relevant.

      Knuth is a well-respected figure who makes moderate, thoughtful statements.

      I happen to disagree with his stances on multi-core chips and unit testing. I didn't find anything thoughtful about what he said and really wish he would have elaborated on why unit testing is a complete waste of time.

      Again, I'll try to avoid repeating what other posters have said, but I'll say that that's not at all what I get from the interview. He was asked to comment on unit testing and multiple cores, but generally acknowledged that these were topics outside of his area of expertise, and said that he'd continue to focus on serial algorithms for combinatorial problems, as that's what he's good at.

      From the summary, you'd think he was a trash-talking pro-wrestler.

      Actually, after reading the article, I did find him to be a bit preachy. Apparently you and everyone else find him unquestionably correct in all his statements from that interview.

      Preachy? He's a professor; it's almost his job. Even so, I didn't find him annoyingly so. He seemed pretty up-front about what topics he was expert on and what topics he wasn't -- and both of the topics you seem particularly interested in (multithreading and unit testing) were areas he explicit

    6. Re:Worst Summary Ever by lysse · · Score: 1

      When will people stop sullying peoples' good names by sensationalizing everything they say?

      When it stops selling newspapers / making it to the front page of Slashdot?
    7. Re:Worst Summary Ever by discord5 · · Score: 1

      You should also point out he has prostate cancer

      I could make a remark here about testing your unit, but that would be wrong

    8. Re:Worst Summary Ever by zestyping · · Score: 1

      I am in complete agreement with #23208332. Your summary is an unfair exaggeration of Knuth's position; he mentioned that unit testing was rarely useful for him, in an interview that was mostly about many other topics. To make "rips on unit tests" the main headline is a wild distortion of what he actually said. For shame.

    9. Re:Worst Summary Ever by Anonymous Coward · · Score: 0

      > I happen to disagree with his stances on multi-core chips and unit testing. I didn't find anything thoughtful about what he said and really wish he would have elaborated on why unit testing is a complete waste of time.

      You're a complete idiot. He didn't say unit testing is a complete was of time. He said unit testing didn't appeal to him because it wastes his time on activities that he simply never needs to perform or think about.

  49. heresy by tsotha · · Score: 3, Insightful

    After initially being a proponent, I've come to the same conclusion about unit tests myself. I don't think they're worthless, but the time you spend developing or maintaining unit tests could be more profitably spent elsewhere. Especially maintaining.

    That's my experience, anyway. I suppose it's pretty heavily dependent on your environment, your customers, and exactly how tolerant your application is of bugs. Avionics software for a new jet fighter has a different set of demands than ye olde "display records from the database" business application. More applications fall in the second category than the first.

    1. Re:heresy by owlstead · · Score: 1

      In my opinion, Unit testing an interface is much less productive than Unit testing a new data structure or inner component. When I use Unit testing (not too much) it's always for core components within a system or for data structures.

      Of course, I don't do Unit testing for test applications either. So all in all it does have to do with the system you are developing the application for, as well as the role of the component that you are creating within the application.

  50. Heck maybe only once a month... by mikelieman · · Score: 1

    Someone brings you a complaint ( bug report ).

    Write test which produces output exhibiting bug.

    Fix bug.

    Test passes, as bug has been fixed -- provably.

    Keep test around. If you're into the CB-thing, ( Continuous Build ) then you'll already have a testing infrastructure to examine reports, email the person who checked in the code which broke the build, etc and you *will* build every hour... If you're not, you have a test suite to ensure no future changes will regress the code to the old bug.

    --
    Technology -- No Place For Wimps! Grateful Dead and Jerry Garcia Chatroom -- http://www.wemissjerry.org
  51. In other news: (La)TeX sucks! by Anonymous Coward · · Score: 0
    Example 1: Tables

    \begin{tabular}{ l | c || r | }
    \hline
    1 & 2 & 3 \\
    4 & 5 & 6 \\
    7 & 8 & 9 \\
    \hline
    \end{tabular}
    WTF? You have to type shit like l | c || r | to tell LaTeX how many columns you want and how to format them? This is ugly, especially for large tables. |||||||||| my ass!

    Example 2: Content mixed with Presentation
    We know how stupid it was to write things like

    <font size="12" color=#FF0000>I'm annoying!</font>
    In LaTex it's even worse. No support for stylesheets and defining or even getting colors is a pain in the ass. Just look at that:

    \definecolor{red}{rgb}{1.0,0.0,0.0} % this is frickin' floating point!
    \large \textcolor{red}{I'm annoying!}
    My Eyes!

    Example 3: Compiler Warnings aren't helpful
    Okay, I lied, no example here. But trust me: If you ever had difficulties interpreting the output of validator.w3.org you will hate LaTeX.

    I really don't get why LaTeX is still so popular among students, especially with those who don't have to type formulas all the time. It's not like there were no alternatives. DocBook looks nice for exampe.
    And now you can mod me flamebait or even troll, I don't care. That's why I'm posting anonymously after all ;)
    1. Re:In other news: (La)TeX sucks! by Nicolas+Roard · · Score: 1

      In LaTex it's even worse. No support for stylesheets and defining or even getting colors is a pain in the ass. Just look at that:

      the WHOLE point of LaTeX is to provide stylesheets. Sure you can go back to mix content and presentation, you can even write TeX code if you so wish. But LaTeX is all about separating your content from its representation! Beside it's entirely YOUR problem if you choose to write {\large \textcolor{ref}{I'm annoying!}} rather than the more succing and more accurante \moron{I'm annoying!} ...

      And now you can mod me flamebait or even troll, I don't care. That's why I'm posting anonymously after all ;)

      It probably have more to do with the fact you're giving stupid reasons to dislike LaTeX.

    2. Re:In other news: (La)TeX sucks! by lekikui · · Score: 1

      Example 1: Tables

      \begin{tabular}{ l | c || r | }
      \hline
      1 & 2 & 3 \\
      4 & 5 & 6 \\
      7 & 8 & 9 \\
      \hline
      \end{tabular}
      WTF? You have to type shit like l | c || r | to tell LaTeX how many columns you want and how to format them? This is ugly, especially for large tables. |||||||||| my ass!
      Yes, you do. You tell LaTeX what the key parts of your table are, and then it goes and formats them. If you want lines between columns, you tell it about that. Personally, I find it a heck of a lot nicer than having to mark up every table cell bit by bit, like HTML.


      Example 2: Content mixed with Presentation
      We know how stupid it was to write things like

      <font size="12" color=#FF0000>I'm annoying!</font>
      In LaTex it's even worse. No support for stylesheets and defining or even getting colors is a pain in the ass. Just look at that:

      \definecolor{red}{rgb}{1.0,0.0,0.0} % this is frickin' floating point!
      \large \textcolor{red}{I'm annoying!}
      My Eyes!

      No, you do have stylesheets. At the top of the document, that \documentclass{something} command? That's loading a style file. Which defines the fonts, text size, all sorts of layout stuff, etc. If you want to change it, you can produce your own style files, or you can define your own commands in the preamble. In web lingo, it's like making a stylesheet, or including CSS in the header. It's just that in TeX most people use one of a bunch of prewritten stylesheets, and tweak them as necessary.

      Example 3: Compiler Warnings aren't helpful
      Okay, I lied, no example here. But trust me: If you ever had difficulties interpreting the output of validator.w3.org you will hate LaTeX.

      I really don't get why LaTeX is still so popular among students, especially with those who don't have to type formulas all the time. It's not like there were no alternatives. DocBook looks nice for exampe.
      And now you can mod me flamebait or even troll, I don't care. That's why I'm posting anonymously after all ;) The compiler warnings are generally useful, in my opinion. If I'm working on a book, for instance, the compiler happily warns me about lines it's had to mung in order to make things work, and I can go find them and check them. If there's a major error in something, it'll fail to compile, and tell me where and why. Much better than HTML, where I see the document is broken, and then have to comb through it to find the error.
      --
      "Lisp ... made me aware that software could be close to executable mathematics." - L. Peter Deutsch
    3. Re:In other news: (La)TeX sucks! by Anonymous Coward · · Score: 0

      Yes, you do. You tell LaTeX what the key parts of your table are, and then it goes and formats them. If you want lines between columns, you tell it about that. Personally, I find it a heck of a lot nicer than having to mark up every table cell bit by bit, like HTML.

      I think it's a fugly syntax and way too many magic characters. And about the telling it if you want lines: That would belong into a stylesheet IMO.

      No, you do have stylesheets. At the top of the document, that \documentclass{something} command? That's loading a style file. Which defines the fonts, text size, all sorts of layout stuff, etc. If you want to change it, you can produce your own style files, or you can define your own commands in the preamble. In web lingo, it's like making a stylesheet, or including CSS in the header. It's just that in TeX most people use one of a bunch of prewritten stylesheets, and tweak them as necessary.

      Okay, so I probably was wrong there, sorry. The way I'm describing it is how LaTeX was told to us and how my colleagues use it.

      The compiler warnings are generally useful, in my opinion. If I'm working on a book, for instance, the compiler happily warns me about lines it's had to mung in order to make things work, and I can go find them and check them. If there's a major error in something, it'll fail to compile, and tell me where and why.

      In my experience this isn't always true. For example: Once I forgot to put a \end{something} somewhere in the middle of the document and the compiler told me about an error at the bottom. Sure, I see why this happens but dang, HTML validators can do it right.

      Much better than HTML, where I see the document is broken, and then have to comb through it to find the error.

      Then you're doing it wrong. There are many tools out there (like http://users.skynet.be/mgueury/mozilla/)that help you find errors exactly where they are.
    4. Re:In other news: (La)TeX sucks! by lekikui · · Score: 1

      Yes, you do. You tell LaTeX what the key parts of your table are, and then it goes and formats them. If you want lines between columns, you tell it about that. Personally, I find it a heck of a lot nicer than having to mark up every table cell bit by bit, like HTML.
      I think it's a fugly syntax and way too many magic characters. And about the telling it if you want lines: That would belong into a stylesheet IMO. Hm, to each their own. Note, however, that the LaTeX way allows you to have lines on some but not all of the columns and rows, and double it up on others if you want. Which is a little more flexible than 'lines or no lines'

      No, you do have stylesheets. At the top of the document, that \documentclass{something} command? That's loading a style file. Which defines the fonts, text size, all sorts of layout stuff, etc. If you want to change it, you can produce your own style files, or you can define your own commands in the preamble. In web lingo, it's like making a stylesheet, or including CSS in the header. It's just that in TeX most people use one of a bunch of prewritten stylesheets, and tweak them as necessary.
      Okay, so I probably was wrong there, sorry. The way I'm describing it is how LaTeX was told to us and how my colleagues use it. Yeah. The main reason for that is that there are a large number of very well written stylesheets already around. For most minor changes, such as an extra command, the way to go is to just use \newcommand in the preamble. For something more major, fully replacing the fonts or adding a bunch of extra stuff, the way to go is generally a \usepackage command, for stuff someone else has already produced.

      Having said that, I do know a bunch of people who roll their own packages/document classes with all their personal commands in. So a bunch of extra mathematical commands, or stuff you use a lot. Generally, however, these are done by modifying something like article.

      The compiler warnings are generally useful, in my opinion. If I'm working on a book, for instance, the compiler happily warns me about lines it's had to mung in order to make things work, and I can go find them and check them. If there's a major error in something, it'll fail to compile, and tell me where and why.
      In my experience this isn't always true. For example: Once I forgot to put a \end{something} somewhere in the middle of the document and the compiler told me about an error at the bottom. Sure, I see why this happens but dang, HTML validators can do it right. Hm. In general, when that happens it will suggest why, or so I've found.

      Much better than HTML, where I see the document is broken, and then have to comb through it to find the error.
      Then you're doing it wrong. There are many tools out there (like http://users.skynet.be/mgueury/mozilla/)that help you find errors exactly where they are. I've never come across that before. I don't tend to write particularly complex HTML, but that will still be useful. Thank you.
      --
      "Lisp ... made me aware that software could be close to executable mathematics." - L. Peter Deutsch
    5. Re:In other news: (La)TeX sucks! by Anonymous Coward · · Score: 0

      Hm, to each their own. Note, however, that the LaTeX way allows you to have lines on some but not all of the columns and rows, and double it up on others if you want. Which is a little more flexible than 'lines or no lines'
      I think you can do the same in html (and docbook) without having to use arcane symbols. For example you could define the bottom border of a table header to have two lines instead of one in css just fine with something like

      .myspecialtable th {
      border-bottom-style: solid double;
      }

      But okay, each to his/hear/its own :)

      Hm. In general, when that happens it will suggest why, or so I've found.

      If you make a simple syntactical mistake like writing \textfbf{i'm bold} it does, right. But we had some problems tracking down mistakes that stretch over several lines (like the \end{xy} thing or a \\ too much after a list (IIRC)).

      I've never come across that before. I don't tend to write particularly complex HTML, but that will still be useful. Thank you.

      Don't mention it. But if you install it make sure you disable it (in the context menu of the icon down right). No need to validate all pages you come across.
  52. Mod parent up too!! by strcpy(NULL,... · · Score: 1

    Knuth doesn't go out of his way to promote his ideas or anything. The interviewer asks him about literate programming and he answers. I don't understand the reason for anti-knuth zealotry. Anyone care to comment?

    --
    echo 'cat sig | sh' > sig
  53. That's not literate programming! by TerranFury · · Score: 2, Informative

    That's a mischaracterization of literate programming.

    The whole idea of literate programming is to basically write good technical documentation -- think (readable) academic CS papers -- that you can in effect execute. What many people do with Mathematica and Maple worksheets is effectively literate programming.

    It has nothing to do with what language you use, and is certainly not about making your code more COBOL-esque.

    Maybe think of it this way: Good documentation should accurately describe what your code does. In literate programming, the computer code is just the "comments" you add to your documentation so that the computer can execute it.

    See this post, for instance.

  54. Unit tests != TDD by heffrey · · Score: 1

    It was TDD that he was having talking about rather than unit tests. And what he actually said was that he didn't find TDD appropriate for the sort of things he did.

    But why let the facts get in the way of a sensationalised headline here on Slashdot, the respectable face of tabloid technology journalism!

  55. Nonsense by MarkusQ · · Score: 2, Interesting

    Making a program parallel will always be too hard for most programmers.

    Nonsense. The problem isn't with the programmers, it's with the languages. Writing object oriented code in Fortran is too difficuiltr for most programmers, but that doesn't mean that the programmers aren't up to the task, but that the language they are using isn't well suited to the job.

    Learn a little erlang, or Haskel to see how easy writing massively parallel programs can be. p.--MarkusQ

    1. Re:Nonsense by cryptoluddite · · Score: 1

      Learn a little erlang, or Haskel to see how easy writing massively parallel programs can be. p.--MarkusQ Massively parallel programs are not very relevant, since the vast majority of programs that people actually use cannot be massively parallel because they generally have a lot of dependencies and sequences.

      Erlang and haskel have not caught on precisely because they are not suited well for the kind of programs people generally write or use. So while they may make parallel programming easy for programs that are easy to parallelize, this doesn't really help that much.
  56. Re:he's from another era by rawler · · Score: 2, Insightful

    "my dualcore laptop really has no problem with that"
    Moore's law says (well, indirectly at least) that machines from 2007 should be roughly 256 times as powerful as machines from 1995.

    Somehow, the actual performance difference (starting the computer, starting a web-browser, editing text etc.) in running Win95 on hardware from it's time, compared to running Vista on todays hardware, seems to be nowhere near a 256-times improvement.

    I can only conclude that while the hardware-industry have improved itself again and again, the software industry have ate almost all of those improvements, instead of giving it to the users.

  57. Knuth dismisses multicore but MMIX is poor design by pslam · · Score: 2, Insightful

    I expected much, much more from Knuth than what I've just seen in that interview and after reading the design of MMIX.

    Knuth dismisses multi-core and multi-threading as a fad and an excuse by manufacturers to stop innovating. I'm amazed someone of his intelligence has managed not to read up on exactly WHY this is happening:

    • Faster single-thread processing means faster clocking.
    • Faster clocking means smaller feature size.
    • Eventually you run into the limit of your process, shrink further and continue.
    • Finally, you run into the thermal limit of your process, and you cannot go faster in the same area.
    • To go faster you have to go sideways - more parallelism.

    So he dismisses the technical problems that manufacturers have been falling over for the last few years as merely a lack of imagination. No - parallelism is here to stay, and people need to realise it rather than just wishing up some magical world where physics aren't a problem.

    He dismisses multi-threading as too hard. It isn't, if you're not unfair to the concept. Nobody is getting 100% out of their single-threaded algorithms. You always have stalls due to cache misses, branching, the CPU not having exactly the right instructions you need, linkage, whatever. Nobody EXPECTS you to get 100% of 1 CPU's theoretical speed. So why do people piss all over multi-core/multi-threading when it doesn't achieve perfect speed-ups?

    If you achieve only a 50% speed-up using 2 cores compared to 1, you're done a good job, in my opinion. That means you could have dual-core 3GHz CPU or a single core 4.5GHz CPU. Spot which of those actually exists. Getting a 25-50% speed-up from multi-core is easy. The 100% speed-up is HARD. If you stop concentrating on perfection, you'll notice that multi-threading is a) actually not hard to implement, and b) worthwhile.

    Then there's MMIX. Knuth thinks that simplicity has to work all the way down to the CPU design. Yes, but not simplicity by way of having instructions made up of 8 bit opcode and 3x8 bit register indexes. A CPU doesn't give a crap how elegant that looks. It's also BAD design - 256 registers makes for a SLOW register file. It'll either end up being the slow critical path in the CPU (limiting top clock speed) or taking multiple cycles to access. There's also no reason to have 256 opcodes. He should have a look at ARM - it manages roughly the same functionality with much less opcodes.

    It almost pains me to see the MMIX design and how it's a) not original, b) done better in existing systems already on the market, e.g ARM, and c) doesn't solve any of the performance limit problems he complains about. What's going on with Knuth?

  58. Declining populary means nothing by Anonymous Coward · · Score: 1, Insightful

    C and C++ only seems to be declining because they are the de facto standards and everyone knows how to use them. There is no need for news articles, blog entries, etc. They may not be hip but they power everything and are more used than anything else.

  59. That's impossible by sholden · · Score: 1

    You can not have heard of Knuth without also hearing of literate programming. Well OK, you can't have read his work anyway.

  60. Re:MMIX is poor design by bunratty · · Score: 2, Informative

    Remember that MMIX is not designed to be a practical hardware computer architecture. It's designed to illustrate algorithms written in assembly language. It's optimized for humans to read and write, not for computers to execute quickly. I'm glad that he's keeping assembly as part of his books, and that's he's updated them to a 64-bit RISC architecture. Reading MMIX assembly programs is the closest to hardware that some readers will ever get, so he has one chance to show those readers how computers actually work. It had better be as simple as possible for people to understand.

    --
    What a fool believes, he sees, no wise man has the power to reason away.
  61. Re:Knuth dismisses multicore but MMIX is poor desi by WeirdJohn · · Score: 1

    I think you're missing the point of MMIX. It was never intended to be an example of great processor design. It was intended to be a construct for teaching how to program, without being an Intel, or ARM, or Motorola, with the way these "lock you in" to the patterns that make most sense for that platform.

  62. foreach is a parallelism killer by Estanislao+Mart�nez · · Score: 2, Insightful

    To be fair, I find that a lot of high-level (business layer) code I write today consists of "foreach (...) { ... }". It would seem that there are quite a few opportunities to parallelize there.

    ...which the compiler can't discover, because foreach describes a mechanism (looping through a sequence, in order), and not a high-level transformation.

    Compare foreach with map. Map is a higher order function that takes a function and a collection, and results in a collection of the same size and structure as the original, but with each element replaced by the result of applying the supplied function to it. Note that the value of each element in the result depends only on the corresponding element of the input. It's trivial to parallelize map.

    You can parallelize map easily because it has a favorable contract that specifies the relationship between its inputs and its outputs, and it just so happens that this contract is amenable to parallel execution. A smart compiler, upon seeing a use of map, can trivially tag it as a parallelism candidate.

    But since foreach specifies a sequential looping mechanism, there are no guaranteed relations between the input and output (in fact, not even any simple way to determine what should be treated as inputs and outputs). When you write a foreach loop to perform the equivalent of a map, you're underspecifying the transformation you're performing on your collection, and overspecifying the mechanism. That's bad programming.

    You mention Parallel LINQ, and this is very relevant. LINQ is based on operations similar to map, that transform sets into sets. LINQ queries, since they abstractly describe the relation between an input and the desired output, can be executed in a number of ways: (a) the system can translate them into SQL queries and send them to a database server to execute; (b) the system can execute them serially; (c) the system can execute them in parallel.

    1. Re:foreach is a parallelism killer by shutdown+-p+now · · Score: 1

      ...which the compiler can't discover, because foreach describes a mechanism (looping through a sequence, in order), and not a high-level transformation.
      Not really. "Sequentially" is not inherent to the meaning of "foreach" - it's really just "do some action for each element of the sequence". Most of those can be parallelized.

      You can parallelize map easily because it has a favorable contract that specifies the relationship between its inputs and its outputs, and it just so happens that this contract is amenable to parallel execution.
      In a language with side effects, such as C#, it's just as easy to write a non-parallelizable map as it is to write a non-parallelizable foreach - you just have to rely on the result of the previous iteration (and who said the mapping function can't have side effects?).

      You can, of course, say that side effects (or rather, relying on such from one call inside another) are not allowed in the mapping function, but you can put the same restrictions on foreach. That's precisely what PLINQ does, for example.

      You mention Parallel LINQ, and this is very relevant. LINQ is based on operations similar to map, that transform sets into sets.
      Not really. LINQ is a foundation used in .NET to provide operations such as map, fold, and filter, but it is not by itself restricted to such. By the way, PLINQ does provide parallelizing foreach, only they call it "forall":

      var list = Enumerable.Range(1, 10);
      list.AsParallel().ForAll(x => Console.WriteLine(x)); // one thread per write, unspecified ordering
      On the other hand, in Fortress, foreach is parallelized by default, and you have to use the "sequential" keyword explicitly if you need it.

      On a side note, plain LINQ code does not demand the function arguments to be side-effect free, so you can't just take an existing C# program with LINQ queries and convert it to PLINQ without expecting some breakage. The only way to be transparent to parallelization is to be functionally pure - Haskell is there, but no mainstream language is.

    2. Re:foreach is a parallelism killer by Estanislao+Mart�nez · · Score: 1

      Not really. "Sequentially" is not inherent to the meaning of "foreach" - it's really just "do some action for each element of the sequence". Most of those can be parallelized.

      Suppose I need to write a function that takes an ordered list of strings, and concatenates them in the order in which they appear in the list. The normal manner of writing this fucntion does the following things: (a) initialize a string buffer the build up the result; (b) use foreach to loop over the list elements, and append the contents of each string to the result buffer.

      Are you seriously telling us that this is an incorrect implementation of the algorithm, because the program is allowed at runtime to process the elements in any order?

      Foreach does assume order and sequence, and imperative algorithms have always relied on this. But it's even worse, because it's not just order and sequence: foreach also allows for completely unrestricted communication from early runs through the loop to later ones. The partial result produced in a later iteration through a foreach loop is allowed to depend in any way on the result from the previous iterations through the same loop. The example algorithm above is an example: each iteration through the loop relies on previous iterations having appended each previous string to the buffer, and having done so in the order in which they occur in the string.

      In a language with side effects, such as C#, it's just as easy to write a non-parallelizable map as it is to write a non-parallelizable foreach - you just have to rely on the result of the previous iteration (and who said the mapping function can't have side effects?).

      The contract for map is so. If you're using map and your mapping "function" is stateful, then the result is undefined. If you wrote such a mapping function, your code has a latent bug, even if it shows the correct behavior in the current implementation of the language. The whole point of map, again, is to perform a computation where there are no data dependencies between elements.

      If you must transform a collection in a way where the processing each element depends on the results from processing other elements in the same collection, you shouldn't use map; you should use a higher-order operator that codifies what information each step of the computation receives from the rest. This is the whole point, and the whole problem with foreach; every time you process a collection, there is a structural relation between the input, the correct output, and the computations that may be performed on the input to produce that output. Each higher-order function encodes one such structural relation. With a programs written to use such functions, therefore, it at the very least much easier to discover opportunities for reordering and parallelism.

    3. Re:foreach is a parallelism killer by shutdown+-p+now · · Score: 1

      Suppose I need to write a function that takes an ordered list of strings, and concatenates them in the order in which they appear in the list. The normal manner of writing this fucntion does the following things: (a) initialize a string buffer the build up the result; (b) use foreach to loop over the list elements, and append the contents of each string to the result buffer. Are you seriously telling us that this is an incorrect implementation of the algorithm, because the program is allowed at runtime to process the elements in any order?
      It depends on the language, naturally.

      Foreach does assume order and sequence, and imperative algorithms have always relied on this.
      Unless you can reference this definition of foreach, I'm going to disagree and say that the way it behaves is as defined by the language. It is fairly obvious that there are two possible behaviors - sequential iteration, and parallelizing one. Which one of those is identified by keyword "foreach" is not set in stone (but you'd want both to be available, naturally). I've already given one example where "foreach" means "parallel" - Fortress.

      But it's even worse, because it's not just order and sequence: foreach also allows for completely unrestricted communication from early runs through the loop to later ones.
      This isn't "worse" - it's just a natural consequence of defining foreach as sequential.

      The contract for map is so. If you're using map and your mapping "function" is stateful, then the result is undefined.
      Again, depends on a particular implementation of map. LINQ Select(), for example - which is otherwise precisely the same as map - does not require the function to be stateless.

      To wrap it all up - it's all about the terminology, really, and there is nothing really standardized there. I wholeheartedly agree with you that being stateless, and preferrably functionally pure, is the key to automated parallelization.

  63. "Bug" is a relative term... by SEMW · · Score: 3, Insightful

    If you define "bug" to mean "unexpected undocumented behaviour", as Knuth seems to, then it's not surprising that there have been very few bugs claimed, since TeX is so very well documented.

    But most people -- and certainly the majority of open source projects these days -- define "bug" as "undesirable behaviour"; and by that standards, TeX is chock full of bugs. To pick a couple of obvious examples, incorrect handling of ASCII 0x22 quotation marks, and treating "etc." as the end of a sentence. These aren't "bugs" to Knuth since the incorrect behavious is well documented, but by many people's standards they are.

    --
    What's purple and commutes? An Abelian grape.
    1. Re:"Bug" is a relative term... by SanityInAnarchy · · Score: 1

      I suppose it depends how reasonably you could actually fix the incorrect behavior, or whether it makes more sense to document it explicitly and move on. For example, I might consider it a bug that I can't easily type an apostrophe as part of a contraction in a single-quoted string, but I'm fairly sure I'm happier with the explicit, simple, and predictable behavior than any hack which would allow the compiler to always detect when a ' was meant to be quoting a string, or to be an apostrophe in a string.

      Take, for example, Ubuntu's Bug #1 -- certainly undesirable behavior, but really not trivial to fix. Undocumented behavior can always at least be easily fixed by documenting it.

      --
      Don't thank God, thank a doctor!
  64. One sentence summary by greg_barton · · Score: 0

    Donald Knuth said, "Get off my lawn!"

  65. Knuth v'- unit testing implied by kramulous · · Score: 1

    I can see why Knuth doesn't like unit testing. Reading his books you see that you really need to understand your algorithm properly and identify all key sections. You need to spend a bit of time by sitting down with pen and paper and draw the flow; derive what happens at limits rather than guess or 'have faith in the gods'. By designing your algorithm properly, the unit test is kinda implied.

    --
    .
  66. Can we tag the summary "flamebait"? by daffmeister · · Score: 1

    Donald Knuth does not rip on unit testing. He says unit testing is of no value to him. That's a completely different statement.

    1. Re:Can we tag the summary "flamebait"? by kramulous · · Score: 1
      --
      .
  67. Functional tests. by SanityInAnarchy · · Score: 1

    Unit tests, strictly speaking, are only the beginning. You're also going to want functional tests, and in general, you're going to want to test everything you can, unless you have a good reason for believing it doesn't need testing -- for example, you probably don't need to test things that are built-in to the language; not only is it probably better tested than any code you could write, but there's not a lot you could do if it somehow failed.

    And after a "unit" of code is written "correctly", you may not be done. You may still refactor it at some point, or rewrite it with a different algorithm, and unit tests help you do that without having to worry as much about whether you broke it. More importantly, unit tests (and functional tests) also mean that you avoid the situation where you change some completely unrelated code, and it breaks your test.

    They're not going to protect you 100% of the time, but they don't have to. Any bug they catch is probably going to save you enough time to be worth it -- especially because it will catch that bug early.

    And then there's test-driven design -- first write a test to describe how the system is supposed to work, and then write the code that passes that test. Here, it helps you know when you're done with that particular piece of code -- that is, it prevents you from writing too much at once.

    --
    Don't thank God, thank a doctor!
  68. "Titanium" or "Itanium"? by Baldrson · · Score: 1
    TFA says:

    I won't be surprised at all if the whole multithreading idea turns out to be a flop, worse than the "Titanium" approach that was supposed to be so terrific -- until it turned out that the wished-for compilers were basically impossible to write.
    Note that the link is to the Wikipedia article on "Itanium", not "Titanium". Is this a misprint? Did Knuth misspeak?
    1. Re:"Titanium" or "Itanium"? by bunratty · · Score: 1

      It's a joke, son. Itanium. Titanic. Titanium. Get it?

      --
      What a fool believes, he sees, no wise man has the power to reason away.
    2. Re:"Titanium" or "Itanium"? by tytso · · Score: 1

      The joke works much better if you say "Itanic". I used to say that a lot but I try not to if their are people from Intel in the room; they can get a little touchy when you rip on the Itanium. :-)

      Titanium makes people think of the metal that expensive geek watches tend to be made out of, so I find it's less likely people will get the joke.

  69. Re:MMIX is poor design by pslam · · Score: 1

    Remember that MMIX is not designed to be a practical hardware computer architecture. It's designed to illustrate algorithms written in assembly language. It's optimized for humans to read and write, not for computers to execute quickly. I'm glad that he's keeping assembly as part of his books, and that's he's updated them to a 64-bit RISC architecture. Reading MMIX assembly programs is the closest to hardware that some readers will ever get, so he has one chance to show those readers how computers actually work. It had better be as simple as possible for people to understand.

    But that's the problem - it's illustrating an architecture that's impractical. It gives the false impression that you don't have to worry about register spillage, a slightly non-orthogonal instruction set or most of the other issues that real world CPUs have to deal with. That's exactly the point of teaching people about a CPU in the first place, and unfortunately MMIX hides you from it.

    And worse still - he DOES keep referring to MMIX whenever he talks about how multi-core or multi-threading is bunk.

  70. Nonsense by MarkusQ · · Score: 1

    Erlang and haskel have not caught on precisely because they are not suited well for the kind of programs people generally write or use.

    This is circular reasoning at its finest. The main reason the program that people write and use aren't written in a style to which a language such as Haskel or Erlang are suited is that the people who programed them wrote them in a style more suited to the languages in which they were written.

    There's nothing about the tasks themselves that make them unsuited for massively parallel solutions; the actual dependency and sequences in the problems (as opposed to in the programs that are currently used to solve them) are few and far between.

    For a few examples:

    1. Anything dealing with screen displays or graphics generally has massive opportunities for parallel execution
    2. Searching and sorting are suitable to parallel solution (this is the secret to Google's success, for example)
    3. Many scoring / filtering applications (such as spam filters) could benefit from at least a hundred cores if written properly
    4. Servers and middle tier software that handle asynchronous requests
    5. Databases (being mostly a combination of the preceding three cases)
    6. Spread sheets
    7. ...and so on and so forth

    It may be easier to turn the question around: what exactly are the "kinds of programs that people generally write and use" that couldn't benefit from massively parallel solutions because the problems are full of "dependencies and sequences"?

    --MarkusQ

  71. Our fearless editor... by MoeDrippins · · Score: 1

    > He pitches his idea of "literate programming" which I must admit I've never heard of...

    Wow. Simply, wow.

    --
    Before you design for reuse, make sure to design it for use.
    1. Re:Our fearless editor... by chromatic · · Score: 1

      That wasn't the editor. That was the story submitter.

    2. Re:Our fearless editor... by MoeDrippins · · Score: 1

      That wasn't the editor. That was the story submitter.

      You are of course correct. My apologies (seriously).

      Would it help to mention I'm old? =)
      --
      Before you design for reuse, make sure to design it for use.
    3. Re:Our fearless editor... by chromatic · · Score: 1

      Hey, I'm embarrassed too. I stuck up for Taco.

  72. Re:MMIX is poor design by bunratty · · Score: 1

    Those might be valid criticisms if his books were about assembly language programming or computer architecture. But they are not. They are about algorithms, and his MMIX programs illustrate how those algorithms are implemented by a computer in terms of the instructions it executes, and the registers, cache, and memory. If a reader wants to learn about real-world CPUs, they can read Hennessy and Patterson.

    --
    What a fool believes, he sees, no wise man has the power to reason away.
  73. Literate programming by pikine · · Score: 2, Informative

    I think most people who post here don't know what literate programming is. It's more like writing a textbook explaining how your code works, but you can strip away the text and actually have runnable code. This code can be in any language of your choice. It makes sense from Knuth's point of view, but for many of us, we don't write textbooks for a living.

    Knuth also doesn't need unit testing because he probably runs (or type checks) the program in his head. Again, for most of us, seeing the program run provides additional assurance that it works. Unit tests also provide a specification of your program. It doesn't have to be just b = f(a). For example, if your code implements a balanced binary search tree, a unit test could check the depth of all subtrees to make sure the tree is balanced. Another unit test would check if the tree is ordered. You can prove by the structure of your program that these properties hold, but a lay-man doesn't want to write proofs for the code he writes, so the second best alternative is to use unit test.

    About parallel programming, Knuth is actually right. Many high-performance parallel programs are actually very involved with the underlying architecture. But we can write a high-level essentially-sequential program that uses libraries to compute things like FFT and matrix multiplication in parallel. This tends to be the trend anyways.

    --
    I once had a signature.
    1. Re:Literate Programming by Gkyluig · · Score: 1

      Try Inform 7. Just to show you how literate programming can be, check out these poems that are compilable Inform 7 games.

  74. We do not have infinite CPU power by dbIII · · Score: 1

    Remember that some things in engineering and geophysics are still fully CPU bound and that even a 1% improvement saves you more than an hour per process per week - if it's only running a dozen times that saves twelve hours. With 3D graphics a fairly small improvement with a clever tricks or fast algorithm it can also be a difference between whether the thing can be done acceptably on the hardware or not. With encryption it makes a big difference especially if you are doing something like talking to a heart pacemaker that only has a Z80 to run the code on (an example from a far better programmer than myself). Then there's the increasingly important mobile device space - they are getting more cabable but still don't have fast hardware or a lot of memory. In a lot of situations the library can not be treated as a black box and may be designed to run in different conditions to what you want.

    1. Re:We do not have infinite CPU power by nguy · · Score: 1

      Remember that some things in engineering and geophysics are still fully CPU bound and that even a 1% improvement saves you more than an hour per process per week

      And there are a small number of specialists that deal with that sort of thing, just like there are specialists for Thai localization or GPU design. You can be a programmer and be such a specialist as well, but programmers in general aren't.

    2. Re:We do not have infinite CPU power by dbIII · · Score: 1

      And there are a small number of specialists that deal with that sort of thing

      There is an entire feild called numerical programming which every engineer and I assumed every computer programmer had heard of. They may look like "specialists" to some but there are quite a few of them and there are also other feilds where a bit of optimisation can give you a very large improvement.

    3. Re:We do not have infinite CPU power by Anonymous Coward · · Score: 0

      There is an entire feild called numerical programming which every engineer and I assumed every computer programmer had heard of.

      Calling it a "field" doesn't make it a big part of programming; probably less than 1% of all programmers are doing numerical work, and only a small fraction of those are doing optimization.

      They may look like "specialists" to some but there are quite a few of them and there are also other feilds where a bit of optimisation can give you a very large improvement.

      Most people doing numerical programming neither do, nor understand, optimization, and they usually don't know much about non-numerical algorithms and data structures either; they rely on highly optimized libraries (BLAS, ATLAS, etc.) and for the rest rely on tools that try to do the optimization for them (Fortran, MATLAB).

      Trying to support Knuth's arguments about literate programming and unit testing by pointing to such a small, specialist population is simply stupid.

      For the vast majority of programmers, literate programming is a waste of time and unit tests work are extremely useful. Anybody who claims differently simply is out of touch with reality.

  75. Comment removed by account_deleted · · Score: 1

    Comment removed based on user account deletion

  76. Literate Programming by wdr1 · · Score: 1

    Uh, if you're never heard of literate programming & you're surprised by what Knuth said, it's because you're not listening very closely.

    -Bill

    --
    SlashSig Karma: Excellent (mostly affected by moderatio
  77. There is no "final" version by Gorimek · · Score: 2, Insightful

    I've never seen any interesting and useful software that is ever "finished". You always need to add and change things, and there is always far more functionality wanted than you can produce.

    If you clean up and refactor as you go, rather than at "the end", what you have described is Agile/XP development.

    1. Re:There is no "final" version by Coryoth · · Score: 1

      Sure, if you like, just stick "document properly" in the "clean up and refactor" step and you can happily include literate programming. As much as you like to talk about being completely agile, a great many software projects do have distinct milestones and aren't simply in a constant state of flux. Not every software project is like the projects you work on.

  78. Dude, if you do TDD it doesn't mean to be anal by Anonymous Coward · · Score: 0

    If you have to continuously re-run your tests then something is wrong, even with TDD.

    You write tests up front. Fine. For this you need to know the API and/or the interfaces you are working against. This is normal and good.

    You make those tests reasonable and small, and functional. That's good too.

    Then you develop your feature/functionality.

    Then when you've hacked about some hours and think it's ready, you re-run the tests.

    If something is broken, you fix it.

    Otherwise it works as it should.

    Yes, TDD is good and you need to run the tests, but don't be anal about it. Running the tests too often (like your 200 or even 50 times a day) is just a waste of time.

  79. Nightmare on Core Street by owlstead · · Score: 1

    What a very distasteful article which seems only about bragging rights about his own very experimental system. Only the last paragraph seems to be getting to the point. The system this guy is devising does make an interesting read, but it unleashes many questions about the feasibility of such a system. It's certainly not something that AMD or Intel can currently adopt as a strategy. Actually, it seems a bit about bragging rights about -your- very experimental system. In the kill file with you.

  80. Knuth Works.... exercise in Esoterics? by tulsaoc3guy · · Score: 1

    Why do you think Knuth's work should be relevant to getting your day-to-day tasks done as a programmer? Ever tried to read any volume of Knuth's "Art of Programming"... I tried as a CS/Engineering Student at University and found them very esoteric... been a professional programmer for 10+ years and never used or heard of anyone else using his books as a reference. Bill Gates said: "If you think you're a really good programmer. . . read [Knuth's] Art of Computer Programming.... You should definitely send me a resume if you can read the whole thing." -Bill Gates

  81. Knuth is God.. by strangeattraction · · Score: 1

    nuf said..

  82. Re:Knuth dismisses multicore but MMIX is poor desi by btakita · · Score: 1

    And worse still - he DOES keep referring to MMIX whenever he talks about how multi-core or multi-threading is bunk.

    That presents him as unqualified to have a convincing opinion on parallelism.

  83. Yes, But by Anonymous Coward · · Score: 0

    There is a time dimension to the unit test. You start with the tests that look like they meet requirements and don't cost too much to write. Over time, as users of the code complain about broken boundary cases, the unit tests are upgraded. Eventually, every boundary case that anyone has demanded your code handle correctly is covered.

    At this point, marketing will decide it is time to completely rewrite the product.

  84. Absolutely essential for "framework" development by mbessey · · Score: 1

    If you're developing a library that other people depend on, then unit testing is invaluable. It's difficult to know in advance which ways other people will try to abuse your code. Unit testing (including all the obvious boundary cases) makes for much more reliable code. The unit tests are also handy when the code needs to be re-factored - which will happen eventually, to pretty much any code that is used for more than one application.

  85. Re: Wanted Features by some+guy+I+know · · Score: 1

    I'm not aware of any languages that offer either of these features.
    C++ and Python:

    create a function that could only be called from a certian other function.
    In C++, create a class with one private function, then make the "certain other function" a friend of the class.

    a way to undeclare a variable.
    In Python, you can delete a variable using "del", which is pretty much the same as undeclaring it.
    --
    Those who sacrifice security to condemn liberty deserve to repeat history or something. - Benjamin Santayana