Slashdot Mirror


Literate Programming and Leo

jko9 writes "First proposed almost 20 years ago by Donald Knuth, the idea of Literate Programming is basically that of making program documentation primary, and embedding code in the documentation, rather than vice versa. Despite some obvious advantages apparent to anyone who has struggled to understand a poorly documented program, literate programming never really caught on. That all could change, however, with the release of a new program called Leo, written by Edward K. Ream. Leo supports standard literate programming languages like noweb and CWEB, but with a crucial difference - Leo adds outlines. The effect is striking: overall organization of a program is always visible and explicit. Much of the narrative of the documentation gets placed in the outline, making documentation simpler, and allowing viewers to approach the code at various levels of detail. Screenshots and tutorials for Leo are here - if that site gets slashdotted, you can download the visual tutorials in .chm form or html form from Leo's Sourceforge site. Leo is an open source program written in Python. Any current practioners of Literate Programming techniques out there? People who have tried it and given it up? Can the addition of outlines to Literate Programming make it more powerful / popular?"

160 of 358 comments (clear)

  1. Literate Programming by bigjocker · · Score: 4, Interesting

    My previous employer had a strict rule concerning code: you first write the JavaDoc for all the project, then implement it. It's useful as hell ... and if you mix that with UML design before the documentation, its a killer technique.

    --
    Life isn't like a box of chocolates. It's more like a jar of jalapenos. What you do today, might burn your ass tomorrow.
    1. Re:Literate Programming by bigjocker · · Score: 3, Interesting

      In that scenario (and in my school's freshman CS classes, which is where I got the idea), what would be useful would be a utility that parses valid JavaDocs, and outputs a subsequent Java class with all of the data members declared, and the methods stubbed out, like reversing the javadoc util.


      Try XDoclet for that. Its still in beta, but a lot of people (including me) use it for production.

      --
      Life isn't like a box of chocolates. It's more like a jar of jalapenos. What you do today, might burn your ass tomorrow.
    2. Re:Literate Programming by smagoun · · Score: 2
      In a similar vein, take a look at the Sandboss project . It's an open-source implementation of something called "Structs and Nodes Development"; it makes heavy use of javadoc + code generators to drastically simplify programming large distributed systems.

      While the implementation isn't complete (yet), the concept works amazingly well (I used a previous iteration at my last job) and saves literally man-years of development on large projects. Very cool stuff...

    3. Re:Literate Programming by ctrimble · · Score: 3, Informative

      Actually, it was completeness and consistency that Godel tackled, and he proved it (rather than implied it). Complete = all true statements have a proof. Consistent = p & ~p is not a theorem of the system. This is for all systems strong enough to support the Peano axioms (and some weaker systems, I believe). However, 1st order logic is both complete and consistent.

    4. Re:Literate Programming by SerpentMage · · Score: 4, Insightful

      Being a professional engineer this is not how you approach the problem whatsoever. No engineer in their right mind writes the documentation ahead of time. Actually there are engineers that do that, but they work for the government.

      Real engineering is tinkering and logging what you did. In engineering there are three phases, which involve tinkering and experimenting and doing simulation. The second phase is coming up with a game plane. With the last phase being the implementation.

      And engineers do just jump in and do something when they know what they are doing. An engineer is an engineer because they know how to guess-estimate. That is why an engineer goes to school for 4-5 years to learn what engineering is. They when you need to tinker and when to jump in!

      The problem in IT is that you have people who do not have enough engineering education to know what they are doing. And by education I do not simply mean school education, but training or simply good mentoring.

      --

      "You can't make a race horse of a pig"
      "No," said Samuel, "but you can make very fast pig"
    5. Re:Literate Programming by iabervon · · Score: 2

      The problem, of course, is that you don't know what features your code will need to have until you write the code that uses it. If you do too much design in advance, you'll have a wonderfully designed project which is impossible to implement (and now I use some information which I haven't been provided access to...) or which has lots of methods which aren't actually useful.

      The only reasonable way to write code is to document it at the same time as you're implementing it: afterward, you've forgotten how it works, and before you don't yet know how it works. Of course, you'll want to do higher-level design beforehand, but be aware that your design must be flexible, in case it turns out not to work that way.

    6. Re:Literate Programming by ipjohnson · · Score: 2, Insightful

      Actually there are many ... many different ways to measure software one of the ones we use is "McCabe Complexity" along side a handful of other metrics. Hell CMU came up with a rating system for software engineering groups called CMM that evaluates your process as well as your process to change your process (defect reduction and what not).

      I'm not saying I agree with them but they are out there. I personally feel coding is a craft and not a science ... but management doesn't like to hear that because it means results are less reproducable. Thats a whole other can of worms.

    7. Re:Literate Programming by ipjohnson · · Score: 2, Insightful

      The trick is to have the requirements laid out. I know thats not possible some of the time but for the most part you should not be writting production code until most everything is nailed down. That said pathfinding (i.e. writting code to test theory) should be done before sitting down to write the real code.

    8. Re:Literate Programming by Kiwi · · Score: 2
      The only reasonable way to write code is to document it at the same time as you're implementing it

      I find that I write better code when I first put out a basic sketch of the design. Basically, the data structures used, the names and arguments for the functions, and what the functions do. Once this is sketched out, I go about actually writing the code in question. I will generally actually making up more functions than what I sketeched out, and will change some of the arguments that the functions receive.

      I find that the code I write while designing the strucutre is more bug-prone and difficult to maintain; "play it by ear" is not a good way of working for projects of any significant complexity.

      Since Slashdot has zapped signatures (in the defulat config), I will referer people to my main software project. This project is my most ambitous project to date; it currently has over 24,000 lines of code (including comments).

      My experience with looking at the source code for projects is that the main problem is not how people comment the code, but that people generally do not comment their code at all.

      - Sam

      --

      The secret to enjoying Slashdot is to realize that it should not be taken too seriously.

    9. Re:Literate Programming by jaoswald · · Score: 2

      To expand on your point:

      Programmer's create mental "things" which are just as expensive, in terms of mental effort, to tear down and rebuild as it is expensive, in a material sense, to tear down and rebuild a house.

      If a programmer screws something down, someone else may have read it and written other code that depends on it. Any changes need to be broadcast to the other developers who might have used it, causing them to have to relearn what they have done and rewrite their code. That's potentially a huge cost in developer effort and frustration.

      Why else is "backward compatibility" is such a byword?

    10. Re:Literate Programming by ebbe11 · · Score: 2
      Real engineering is tinkering and logging what you did. In engineering there are three phases, which involve tinkering and experimenting and doing simulation. The second phase is coming up with a game plane. With the last phase being the implementation.

      Thank God bridges aren't built that way!

      --

      My opinion? See above.
    11. Re:Literate Programming by SerpentMage · · Score: 2

      I think you were not reading my post or you read the first line and not the rest. There are 3 phases

      1) Tinkering, experimenting and get an idea of what is going on.
      2) Putting together a game plan
      3) Implementing the game plan

      In fact my approach works better because it gives you an idea before you know what is going on. Then when you have an idea what is going on then you implement. When I said a game plan I mean formal definition, which could be documentation, models, etc.

      Those that document ahead of time actually waste time because you are going to change your mind anyways until you actually know what you are going to do.

      Nowhere did I say just do it and then say there it works.

      --

      "You can't make a race horse of a pig"
      "No," said Samuel, "but you can make very fast pig"
    12. Re:Literate Programming by SerpentMage · · Score: 2

      Excuse me, but they are... Nobody in their right mind is going to let you build a bridge without having built a small model ahead of time. Models, simulations, tinkering are the heart and sole of engineering. Civil engineers will go out and plop down some concrete to test some ideas to see if they work. If you design a bridge solely by paper you get the same error that occured with the Tacoma bridge and the harmonics.

      --

      "You can't make a race horse of a pig"
      "No," said Samuel, "but you can make very fast pig"
    13. Re:Literate Programming by iabervon · · Score: 2

      I like to just start writing code, but what I'm actually doing is a sketch of the design; it's just that I'm using a programming language rather than something less formal and more ambiguous. Generally, my first version won't remotely compile; it's not to actually be run, but rather to show data structures and flow control. I actually sometimes write it in a different language (Scheme is good for designing some things; Java is great for deciding where you need function pointers). If I've written it in the language I'm going to use, I avoid mistakes in translation.

      I think the code you write while designing the structure should be either thrown away and replaced with code written after the structure is designed or should be essentially pseudocode (but in the language you're using: it should have comments or function calls instead of any non-trivial operations, and only idiomatic control structures).

    14. Re:Literate Programming by ebbe11 · · Score: 2
      Civil engineers will go out and plop down some concrete to test some ideas to see if they work.

      That's right - but they won't call it the real bridge afterwards. They call it a test, an experiment and throws it away when they're done with it.

      No so in SW-development where the kluged-up prototype often becomes the Application 1.0 because management don't think there is time to do it right.

      --

      My opinion? See above.
  2. Programs as flat text files - why? by Animats · · Score: 4, Interesting
    It's wierd, when you think about it, that programming is still done in flat text files. Almost nothing else is still done that way. One could argue for programs in HTML, with the code bracketed in XML so that the compiler could find it.

    Few systems even allow multiple fonts in program text, although the original Bravo editor for the Xerox Alto did.

    1. Re:Programs as flat text files - why? by Hard_Code · · Score: 2

      "One could argue for programs in HTML"

      HTML is still fat text files.

      A more novel idea would be to keep a "live" database of code modules at the method-level, and programs would be an aggregation of such modules.

      --

      It's 10 PM. Do you know if you're un-American?
    2. Re:Programs as flat text files - why? by GusherJizmac · · Score: 3, Interesting

      Because it works. It is a logical and physical way to break up your code. Why else would it be in use for almost the entire existence of programming? Also, you say "Almost nothing else is still done that way". HTML is done in flat files. You just break it up according to however you want. XML files are just "flat text files" when you get down to it. The few things that aren't "flat text files", are binary proprietary formats to the detriment of everyone. MS-Word isn't a flat text file, and as such, it's very difficult to read.

      And furthermore, what does putting code in XML give you that you can't do now? Why do you need different fonts? Fonts are for layout and presentation, not for communicating instructions to the computer. Most editors support syntax highlighting, which is all you need.

      --
      http://www.naildrivin5.com/davec
    3. Re:Programs as flat text files - why? by mystik · · Score: 3, Funny

      program in html/xml? Lisp/scheme lends itself nicely to this, witness:

      (display (+ 4 (+ 3 4)))

      becomes

      <display> <+>4 <+>3 4</+></+></display>

      --
      Why aren't you encrypting your e-mail?
    4. Re:Programs as flat text files - why? by joto · · Score: 2

      I would probably say the opposite. Lisp/scheme is a much more useful data-representation than XML. My eyes hurt by seing the lower expression :-)

    5. Re:Programs as flat text files - why? by mystik · · Score: 2

      Definatly agree. Which begs the question, why is html still tag based, and wastefully duplicating information?

      --
      Why aren't you encrypting your e-mail?
    6. Re:Programs as flat text files - why? by krogoth · · Score: 2

      Because no one has come up with a better way. Show me a way that tags, colours, and fonts can make things easier for me and I'll use it.

      --

      They that quote Benjamin Franklin on liberty and safety deserve neither.
    7. Re:Programs as flat text files - why? by Mr.+Sketch · · Score: 2

      Along these lines, I agree. My general argument is that the storage of the files should be independant of the way it's viewed by my editor. Just some small examples:
      1) It shouldn't matter if the file has spaces or tabs, but if I like seeing things indented 2 spaces, and the guy next to me likes seeing it indented 4 spaces, then when I open the file, I should see 2 space indents and when they open the file, they should see 4 space indents.
      2) If I like seeing pointers declared:
      int* a;
      and they like seeing
      int * a;
      then when I open the file I should see the former and they should see the latter.
      3) If I want to see:
      for (int i = 0; i < 10; i++)
      {
      cout << i;
      }
      and they want to see:
      for (int i=0;i<10;i++) {
      cout<<i;
      }
      etc.

      I hope I'm making my point clear that the way code is seen by each person should be a property/configuration of their view, not related to how the physical file is stored on the disk. That way when I'm looking at someone elses code it won't matter how they format it or if they mix tabs and spaces for indents and I have my tabs length configured differently it won't look terrible, etc.

      The cpp file could be stored in some flat XML/HTML format as long as each view knows how to display it for each person, is all that matters.

    8. Re:Programs as flat text files - why? by rabidcow · · Score: 2

      It's wierd, when you think about it, that programming is still done in flat text files. Almost nothing else is still done that way. One could argue for programs in HTML, with the code bracketed in XML so that the compiler could find it.

      Ok, first of all, the actual storage method is irrelevant. As someone else mentioned, XML/HTML is still flat text files, at least as far as source is. (is it really flat if it's got nested namespaces?) Databases can be stored to flat text files.

      What you're really interested in is how you find a piece of code and its documentation, whether you have to scan through that flat text file yourself to find it, or if there's some other access method. There *is* another access method, it's called an IDE. Ever use MS DevStudio? You can browse the source by objects, by project, "flat text file" groups, all sorts of things. You can jump from a call of a function to its implementation very quickly, or to the definition of a variable. I think it's probably the best Microsoft product ever.

      Now, as for why flat text files (despite the fact that it's irrelevant), it's easier for the current tools to work with, it's backwards compatible, it's easy for the programmer to understand if the sugar on top fails to work right, it's portable. There is no good reason to *not* use flat text files. (well, ok it fails the buzzword test.)

    9. Re:Programs as flat text files - why? by Ed+Avis · · Score: 3, Informative

      Programs are not stored in 'flat text files', at least not unless 'flat text' also includes XML. Programs follow a particular structure and syntax which can be automatically checked and parsed, just like any particular XML format.

      Think about it. You could have a programming language with a ... construct. Or you could have exactly the same logical structure using { and } instead. XML or non-XML is mostly a red herring.

      Some very weird languages like Unlambda or Forth might qualify as 'flat text', but almost all languages used today have a hierarchical tree structure in each file.

      --
      -- Ed Avis ed@membled.com
    10. Re:Programs as flat text files - why? by Tablizer · · Score: 2

      (* It's wierd, when you think about it, that programming is still done in flat text files. *)

      It is odd that *files in general* still uses hierarchical directories. I agree that trees are (initially) conceptually easy to understand than the alternatives, but being easy to understand is not necessarily the same as being productive. It is time we byte the bullet and grow up from trees to sets. Sets are more general-purpose and handle orthogonal organizational criteria much better.

      My rant on altnerativges

      Sometimes I put code in tables also.

    11. Re:Programs as flat text files - why? by Tablizer · · Score: 2

      (quote) If I like seeing pointers declared:
      int* a;
      and they like seeing
      int * a;
      then when I open the file I should see the former and they should see the latter. (end quote)

      One problem with on-the-fly reformatting is that some things cannot be managed by a code parser.

      For example, being somebody who likes to see stuff organized by row and column, I sometimes do something like:

      inputBox("name", r.name, conText, 40)
      inputBox("rank", r.rank, conText, 10)
      inputBox("serial#", r.serno, conFmt, 11)

      Reformatting would de-align such because the parser does not know what we intended.

    12. Re:Programs as flat text files - why? by swagr · · Score: 2

      (Lisp/Scheme) are base on "S-Expressions".
      But you are 100% accurate. S-Expressions save space, eliminate redundant information, and any programmer worth his salt can easily write a simple S-Expression parser in under an hour.

      Take a look at this if you want some reading material. It's by Ron Rivest (the R in RSA).

      --

      -... --- .-. . -.. ..--..
    13. Re:Programs as flat text files - why? by judd · · Score: 2

      Dave Winer's Frontier (http://userland.com) uses outlines combined with a block-structured language (think Python-flavoured C). It's a very nice environment.

    14. Re:Programs as flat text files - why? by Tablizer · · Score: 2

      (* Has any OS ever implemented a set/predicate-oriented filesystem, instead of a heirarchical one? *)

      The IBM AS/400 allegedly has, but there is some debate about how to classify it.

    15. Re:Programs as flat text files - why? by krogoth · · Score: 2

      "Prettify" or indent? vi has excellent automatic indenting, and KDevelop (which I use most of the time) is decent - nearly every advanced/programming editor has some form of auto-indenting.

      --

      They that quote Benjamin Franklin on liberty and safety deserve neither.
    16. Re:Programs as flat text files - why? by Mr.+Sketch · · Score: 2

      Hence why I said it could be stored that way, but as you pointed out, it doesn't have to be. I don't know why VS doesn't do it, but there might be a plugin for it, however, I doubt it'll be natural/seamless, maybe like having to run a macro upon opening the files, instead of being automatic, etc.

    17. Re:Programs as flat text files - why? by Spy+Hunter · · Score: 2
      Why do you need different fonts? Fonts are for layout and presentation, not for communicating instructions to the computer.

      This is EXACTLY the attitude that literate programming tries to discourage. The philosophy of literate programming is that the most important thing to do is communicate the intent of the code to the reader. Communicating things to the computer is secondary (though still important of course). It sounds funny at first (I hear you saying "but the whole *point* of programming is..."). But if everyone who reads the code can figure out exactly what it is supposed to be doing, it becomes much easier to modify and debug.

      If you make a mistake in the code, it is much easier to find if you can compare the code to its documentation to find the discrepency. If you make a mistake in the documentation, it is much easier to find than a mistake in code because it is spelled out in plain english. It makes sense if you think about it.

      --
      main(c,r){for(r=32;r;) printf(++c>31?c=!r--,"\n":c<r?" ":~c&r?" `":" #");}
    18. Re:Programs as flat text files - why? by Tablizer · · Score: 2

      (* Well, in that vein, I found these ramblings [reiserfs.org] about ReiserFS rather interesting... *)

      Interesting. At least we both agree that "sets" are where it is at and trees are limiting. As far as its funky new syntax, well that's another matter.

      It declared relational technology "legacy" more or less. That is the first I ever heard that (other than the now silent OODBMS crowd.) A set-based system can use existing database engines. I don't see a need to reinvent yet-another database engine being that relational thinking is partly based on set theory. However, relational databases may not be fully optimized for file systems (being that they are somewhat general purpose in nature.)

  3. Just giving it a name... by wiremind · · Score: 4, Insightful

    Did ANYONE learn (sic.) pseudo code ???

    When i learned programming writing pseudo code was SUCH a big deal to the teacher that by the end of the year without even thinking i would write out the whole program in pseudo code, then, under each line of english add one line of code.

    And has it ever paid off!

    Now when I want to look at my own documentation, I just grep my java files and pull out all lines that begin with '//'

    now when I am writing 20 pages of java code, and all my boss see's are comments I can tell him i'm am just writing Literate code!

    Good day to you sir.

    1. Re:Just giving it a name... by jgerman · · Score: 4, Insightful
      Ugh, there is certainly such a thing as over-commenting, and from the sound of it you have contracted this disease. If I were reading someone's code and saw:

      // set min equal to max

      min = max;
      // increment i

      i++;


      I'd rip his (or her) head off. There's a balance involved in commenting. Comments are only needed when program flow isn't obvious. Though a comment block summary in front of subroutines is certainly a good idea.

      --
      I'm the big fish in the big pond bitch.
    2. Re:Just giving it a name... by gorilla · · Score: 5, Insightful
      That's not overcommenting, that's commenting wrong. You should be commenting why you are doing something, not what the code does.

      // Default Minimum to be same as Maximum
      min = max
      // We have finished this data cell, Move onto next data cell
      i++;

      Is good commenting, even though it's the same number of comments.

    3. Re:Just giving it a name... by wkitchen · · Score: 2, Insightful

      Pseudo code works especially well with languages that are inherently hard to read. Thanks to pseudo code, I can still easily understand PIC assembly language programs I wrote 10 years ago. Without it, it can be hard to comprehend something I wrote 10 days ago.

      The assembler uses a semicolon to identify comments. For my pseudo code lines, I put a slash immediately after the semicolon so I can extract the pseudo code but ignore other miscellaneous comments.

      Funny thing is, having no formal training as a programmer, I hadn't heard of pseudo code before I reinvented it for myself. I even called it by that name, well before discovering that it was already a common technique.

    4. Re:Just giving it a name... by DataPath · · Score: 2

      That kind of commenting usually only results when someone is told that they need to comment their code after the fact. If you write out in english (or whatever or your native language may be) the process that you'll be using for this method or class or whatever, and then develop the code within your outline, then you don't get extraneous code. And then of course there's the plain and simple need to explain certain not-so-obvious constructs or the reasoning behind solving a problem a certain way, but just think of the questions you ask yourself when you read someone else's code -
      "What is he doing here?"
      "How does this work?"
      "Why did he do that?"

      and try to answer them yourself when you're coding.

      --
      Inconceivable!
    5. Re:Just giving it a name... by Tablizer · · Score: 4, Funny

      If I were reading someone's code and saw:... // increment i ... i++; I'd rip his (or her) head off.

      I feel that punishment should mirror characteristics of the crime itself.

      Tie them to the ground, get a perm marker and write "eye" on their eyelids, "nose" on their nose, "neck" on their neck and so forth, and for a good summarizing comment, "STUPID!" on their forehead, and finally "Brain" on their ass.

    6. Re:Just giving it a name... by j7953 · · Score: 3, Insightful
      // Default Minimum to be same as Maximum
      min = max

      I'm not sure if this is a good comment. Of course it depends on the context, but if I read this comment, I'd immediately wonder why the default minimum is the same as the maximum. Imho it would be much better to explain the complete algorithm at the beginning of the routine, and then have only few comments within the code. However, as I said, this depends on the context and in some situations the above comment might be useful.

      // We have finished this data cell, Move onto next data cell
      i++;

      This is not a good comment, imho. Or at least an unnecessary one. If it is not clear from the context (e.g. the loop is short enough) what the variable i is being used for, you should give it a more explanatory name. Your example could be much better written as

      cellIndex++;

      Using too many comments instead of self-explaining code is not only unnecessary, it often also causes the problem of the comments not being updated when the code is modified.

      --
      Sig (appended to the end of comments I post, 54 chars)
    7. Re:Just giving it a name... by budgenator · · Score: 2

      I was taught to use psedo-code in COBOL class and try to still use it, but I notice that as a learn a language better, the pseudo-code is less pseudo and more code.

      as for greping out the comments I did something like that in FORTRAN, I sorted out all of the comment cards and ran them through the card reader seperately, saved typing stuff twice

      interesting that you use psuedo-code in java, UCSD pascal compiler outputed what they called p-code or pseudo-code that was supossed to be interpereted., just like java compiles to byte-code to be interperted.

      --
      Apocalypse Cancelled, Sorry, No Ticket Refunds
  4. good code is... by jukal · · Score: 3, Insightful

    literate, without literate programming :)

    1. Re:good code is... by RailGunner · · Score: 2
      Actually, I'd have to agree. There is such a thing as comment overkill. If you can't understand the language to a certain degree, then you need to study it harder. Comments are mainly useful to me when I'm looking at source and trying to determine the algorithm behind a function. I understand the language enough to where I really don't need every line commented. For example, I really don't need to see stuff like this:

      // increment the counter

      i++;

      Also, it's my personal preference, but I don't want to have to wade through line after line of comments to find that the person who checked in the source file wrote:

      if (n = 0)

      instead of

      if (n == 0)

      Overcommenting like this just slows me down, and as a professional developer, I HAVE DEADLINES.

    2. Re:good code is... by smagoun · · Score: 2
      Also, it's my personal preference, but I don't want to have to wade through line after line of comments to find that the person who checked in the source file wrote:

      if (n = 0)

      instead of

      if (n == 0)

      That's a good example of why more + better comments are necessary. Perhaps the author meant to write "if (n = 0)". Without some indication of intent, nobody knows which is correct without some detective work. The comments are there to verify that the code wasn't mistyped. As a professional developer, I'd rather know for sure what the code is supposed to do than have to guess (and potentially introduce a regression if I guess wrong).

    3. Re:good code is... by ceswiedler · · Score: 2

      An obscure (though syntactically correct) usage like if (i = 0) definitely should be commented. A real world example would probably be

      if (i = SomeFunc())

      where you want to set the variable and test it at the same time. I prefer

      if ((i = SomeFunc()) != 0)

      which clearly indicates that you're setting the value, and then testing it as well. Whether you agree with this convention or not, this is what people mean when they talk about "self-documenting code." Make things obvious, not clever.

    4. Re:good code is... by SerpentMage · · Score: 2

      Exactly....

      When I lead teams I always enforce the coding style that code should be readable like a book. After all does that not make sense since we are paid to read code for a living.

      I hate code like the following:

      if( i++)

      or

      ++i = ++ n;

      Stuff like that annoyes me because it is like short hand notation. Sure any competent programmer should be able to read that, but it is short hand that requires just an additional thought. As an example:

      On the weekend we went swimming and it was bad.

      Sentence says everything and is compact, but is still not a good sentence. A novelist would write:

      On the weekend we went swimming in the lake at our cottage in Canada, and the water was too cold, which made it unbearable.

      This sentence says everything that needs to be said. Sure it is verbose, but anybody who can read that will understand immediately what is being referred to.

      Likewise I prefer the notation

      destCounter = srcCounter;
      destCounter ++;
      srcCounter ++;

      Easier to read...

      --

      "You can't make a race horse of a pig"
      "No," said Samuel, "but you can make very fast pig"
    5. Re:good code is... by jukal · · Score: 2
      > In fact, Leo makes organization primary, not either code or documentation.

      Well, you make a lot of sense :) . My first comment was intentionally provocative. Especially from design (and architecture) point of view, Leo seems very interesting.

    6. Re:good code is... by RailGunner · · Score: 2
      Why anyone would want to write

      if (i = 0)

      is beyond me, and it's also beyond the creators of C#.. C# will actually catch this mistake at compile time.

      I can't think of any reason to do this. Any reason that anyone else can come up with can be argued that there's a clearer, cleaner way to accomplish the same task. But my point remains, it's quicker for me to find that bug if I'm not wading through line after line of useless comments. If the code is written is a good style, preferably using Hungarian notation, then I don't need over-commenting.

    7. Re:good code is... by belroth · · Score: 2
      I hate code like the following:
      if( i++)
      or
      ++i = ++ n;
      Likewise I prefer the notation
      destCounter = srcCounter;
      destCounter ++;
      srcCounter ++;
      Shouldn't that be
      destCounter ++;
      srcCounter ++;
      destCounter = srcCounter; ?

      I prefer the fromer as I can see more code on the screen at once.

      --
      I hereby inform you that I have NOT been required to provide any decryption keys.
    8. Re:good code is... by PythonOrRuby · · Score: 2
      destCounter ++;
      srcCounter ++;
      destCounter = srcCounter;
      Except of course that this could be more concisely, and yet literately written as:

      srcCounter ++;
      destCounter = srcCounter;

      Since the assignment makes the incrementing of destCounter irrelevant. ;-)

      Of course, in all seriousness, the key issue here is operator precedence, and programmers have to figure that out eventually.
  5. i dont get it.. by Anonymous Coward · · Score: 2, Interesting

    what does leo do for me?

    it looks like the oldschool windows help browser with code samples pasted into it.

    I'm not trolling - I really want to understand how this makes for better code? And my employers definition of better is faster/cheaper - they could give a rats ass about structure and good documentation. They couldn't read a program design in english any better than they could in the most cryptic C syntax I can muster.

    Something like this could help a beginner or student break down code and learn to think logically, but unfortunately I had to move to the 'real world'..

    Sometimes I can't document something until I figure out how its going to be done.. And I figure out how to do it by writing code that works. Then I document the code.

    So far this brand of rapid prototyping is the only thing that gets results fast enough to keep my bosses happy. They care not for proper technique and well-structured code and attention to detail at the design phase. 'Design' around here is no more than a vague definition of the problem to be solved. They just want it out the door.

    I'm sure I'm not alone.. How does leo help me?

  6. must use his nifty GUI ..... by Shaleh · · Score: 3, Interesting

    Yuck. Leo is a "nifty" GUI which helps you do the outline. As I comment on another thread -- we programmers like our text editors thank you very much. I am ok with a visualization program but not one which takes over my workflow.

    1. Re:must use his nifty GUI ..... by jgerman · · Score: 2
      yeah that doesn't quite work work those of use who use vim, and not gvim, but command line vim.


      I still think that there are people out there (probably calling themselves "usability experts") who seem to think that a GUI is the answer to everything, and that a GUI based app is inherently better than a command line app.

      --
      I'm the big fish in the big pond bitch.
    2. Re:must use his nifty GUI ..... by Chundra · · Score: 2

      If you use emacs check out speedbar.

    3. Re:must use his nifty GUI ..... by jgerman · · Score: 2
      Hah nice try, give you credit for that. However, it's not that the features are only possible in a GUI, it's that they were only implemented in a gui. Although the question of whether or not command line vim is a gui could be considered a bit fuzzy (other command line apps as well). It's just a different kind, most importantly to me one where I don't have to remove my hands from the keyboard to move around a silly little mouse ;). Well that and I prefer a text based app when writing code, I actually fired up gvim today and was going to attempt to use it but it just didn't do it for me.


      The point I was trying to make was that the best UI is the one that you work the fastest with which varies from person to person.

      --
      I'm the big fish in the big pond bitch.
  7. A good example: by El_Smack · · Score: 3, Interesting


    The main.cf config file of Postfix. Without the comments it's maybe 30 lines of actual settings. With comments its 540 lines, and it's clear enough that a relative n00b like myself got it up and running in 1 hr with minimal trips to the website. Good documentation was a major factor in my picking Postfix over Sendmail. No dis to Sendmail, you understand. :)

    --


    There are 01 kinds of cars in the world. The General Lee, and everything else.
    1. Re:A good example: by Reziac · · Score: 2

      That's exactly why I like detailed comments. As a non-programmer who sometimes has to root thru source code looking for whatever, piling on the comments does wonders for my understanding of what's going on in there.

      I can understand how Q&D coding doesn't have time for it, but IMO source aimed at relative newbies should be commented both generously and explicitly, even for "obvious" functions -- which may not be so obvious to a beginner.

      It also helps a lot when the code is self-documenting. I have some Pascal source that's entirely comment-free, yet anyone can figure out what's going on because of how everything is named and laid out. Reading the source is like reading comments!!

      ISTM that Q&D code, where commenting goes by the wayside because there's just not time for it, is even more in need of being self-documenting, if only so when you look at it again next week you can get a clue what you were thinking.

      --
      ~REZ~ #43301. Who'd fake being me anyway?
  8. Inline Documentation is evil by lkaos · · Score: 3, Interesting

    If your code requires massive documentation within the code to make it understandable, then your code likely needs to be rewritten.

    With most languages, the code itself is ample documentation. For instance:

    Person &p = Person::findPerson("Harry");

    cout p.name() endl;

    Is pretty self-explanatory. Anyone can tell the output of this code. It's not that programmers need more documentation, rather they need better abstraction and encapsulation (insert your favorite argument for object oriented programming here).

    --
    int func(int a);
    func((b += 3, b));
    1. Re:Inline Documentation is evil by lkaos · · Score: 2

      yeah, there should be two sets of insertation operators (<<). Stupid /.

      --
      int func(int a);
      func((b += 3, b));
    2. Re:Inline Documentation is evil by Anonymous Coward · · Score: 3, Funny

      Anyone can tell the output of this code

      Yes, it is :-


      error C2143: syntax error : missing ';' before 'constant'
      error C2146: syntax error : missing ';' before identifier 'endl'
      warning C4551: function call missing argument list

    3. Re:Inline Documentation is evil by Da+VinMan · · Score: 2

      I agree to some extent. However, you're assuming that the developer will start with a good design. That may not be the case. Literate programming helps you get the design sorted out in an easily changed format, with or without code present. Think of it as re-factoring, but in the detailed design stage.

      Now, one could argue that you really ought to have a design before you start coding. However, there seems to be no end to people who seem incapable of this and there seems to be no end to customers who are unable to articulate requirements well enough to make this possible.

      --
      Please mod this post only if you think others should/n't read this. I have enough ego^H^H^Hkarma. Thanks!
    4. Re:Inline Documentation is evil by rgmoore · · Score: 2

      Not necessarily true. While it is true that code should be written so that it's easy to understand what it's doing, you will frequently need comments to let people know why it's being done that way. When I make changes to my code to fix any non-obvious bug (frequently a result of the inputs it's processing not being quite as well formatted as promised) I always try to put in a comment about what subtle problem that code is fixing. I know that this is important because when I've looked back on code months or years later I haven't been able to figure out why certain things are done without the hints provided by those comments. For particularly bug-addled problems, that may result in a lot of comments.

      --

      There's no point in questioning authority if you aren't going to listen to the answers.

    5. Re:Inline Documentation is evil by gwernol · · Score: 5, Insightful

      If your code requires massive documentation within the code to make it understandable, then your code likely needs to be rewritten.

      I think you're missing the point. All code can be described at several different levels. At the highest level, you might describe a program as (for example) "an online banking application", which is a complete description of the app. However there are obviously a lot of details below this level of description :-)

      Different people need to understand a program at different levels of description. The CEO may only need to know the highest level description. At the other end of the spectrum, someone working on the optimal algorithm for maintining user session should be isolated from the implementation details of other parts of the program. The architect should be concentrating on the interconnection of modules within the code, not the implementation itself.

      The code itself is good at describing some levels of description and very poor at describing others. The example you give doesn't need any documentation to understand what those two lines do, but it will need documentation to understand their relevance to the higher levels of the system.

      Programmers tend to see the details and often miss the larger context. This can lead to unstated and often false assumptions about what role the code fulfills and how it interacts with the rest of the system These are the hardest bugs to find and fix.

      There are many ways to solve this "levels of description" problem. Inline documentation is one very valuable tool. Of course it shouldn't be:

      // Adds two numbers together
      a = b + c;

      It should describe the functional role of the code in relation to the higher-level components of the system.

      As you point out, abstraction and encapsulation are good mechanisms for constructing higher-level descriptions of functionality. Why stop there? Why not try to build up beyond these levels as well? Perhaps we will evolve to high-level languages that can express these high-level designs. Until then inline docuemntation and literate programming are excellent tools to help you achieve these goals.

      --
      Sailing over the event horizon
    6. Re:Inline Documentation is evil by Stonehand · · Score: 2

      Not if you're going math, it isn't. At the very least, if you're implementing a non-incredibly-obvious algorithm such as Strassen's matrix multiplication or solving the integrations and nonlinear systems required to do maximum-likelihood estimation of a normal distribution with two unknown truncation points, you should cite a source so that the reader can figure out the logic behind it all.

      Likewise, many equations may have seemingly standard parameter names that are non-intuitive to the layman. For instance, 'lambda' is a fairly common name for the power in an exponential distribution pdf, if memory serves -- but to somebody who doesn't know that distribution, it's a completely meaningless term. So you either go with the "common" name a statistician would use and recognize, or you go with something non-standard.

      Sure, basic data manipulation can use self-documentating code very well. But do anything that is intrinsically non-obvious to your potential audience, and you /need/ to document more.

      --
      Only the dead have seen the end of war.
    7. Re:Inline Documentation is evil by Viking+Coder · · Score: 5, Insightful

      I can't tell what your code should do if it can't find a person named Harry.

      I can't tell what your code should do if it finds multiple people named Harry.

      I can't tell how to use your code to find a person whose name requires Unicode to represent it.

      I can't tell if .name returns a char * that I'm supposed to free or delete [], if it returns a const char *, if it returns a string that I can modify but won't modify the original Person, if it returns a string reference which I can use to modify the original Person's name, if it returns a wstring reference which I can use to modify the original Person's name, if it returns a const string reference, or if it returns a const wstring reference, or if it uses some other string representation like a Qt one, or some custom one - heck, it could even use an MFC-style CString.

      I don't like that the function you've called is named "findPerson" - wouldn't it be far better to call it something like "findPersonByFirstName"? Or "findFirstPersonWithFirstName"? For that matter, why am I calling "Person::findPerson"? Isn't that slightly redundant? Wouldn't "Person::find" be just as clear, and less verbose? Therefore, the function should be something like "Person::findFirstWithFirstName". Wouldn't that be much more highly documented than what you've got?

      While we're on it, if it is returning the "first", by which method is it sorted? Shouldn't I be able to pass in a parameter which describes the order in which I want the results returned? And shouldn't you get an iterator instead of a reference, anyway?

      Back to "name", is that their entire given name? Is it a nickname? Is it in last-name first format? Is there some additional identifier in the name if two people have the same name?

      And I still don't know if I'll get a special Person which is supposed to be a Non-Person, if it can't find "Harry", or if this is going to throw an exception.

      I don't like that your code uses a hard coded-value, "Harry".

      I don't like that your code has the variable "p". Granted, you've got a pretty amazingly short scope in your example, but code tends to grow. It would be better if the variable had a slightly longer name.

      There are all sorts of things to nit-pick about, that a new coder could be confused about, or bugs which might be on the verge of instantiation, even in code as simple as yours.

      But my real point is this :

      If I've just walked in to your code, I don't know what behavior it's SUPPOSED to have, since you haven't documented that. All I can tell is what it DOES do. And since code changes over time, it's impossible for me to distinguish between the two, unless you document it.

      --
      Education is the silver bullet.
    8. Re:Inline Documentation is evil by SanLouBlues · · Score: 2

      What if I wrote a library with functions that take flags as arguments? You're assuming all code I use will be open source.
      Even worse, what if I'm a mantainence programmer (and I am)? Say there's an inefficient block of code which is self-explanatory, but had to be done as such to get around some esoteric bug in a system library. Documentation would allow me not to repeat said bug.
      And what about complicated algorithms (3d navigation with quaternions)? Should math books remove explanatory text about theories and the derivation thereof because "the code itself is ample documentation"?

    9. Re:Inline Documentation is evil by shaper · · Score: 3, Insightful

      Nope. You've given an example that is far more simple than any real-world situation where you might encounter uncertainty about code functionality. But I'll match you strawman for strawman. Same code sample...

      Person &p = Person::findPerson("Harry");
      cout p.name() endl;

      Questions: what do you do when findPerson() doesn't find Harry? Come to think of it, what are the preconditions for using the Person class in the first place? Do you have to set up a JNDI datasource first? Or maybe it uses an LDAP server so you need to have one for it to work? Why in the world is it looking for "Harry" in the first place? Who is this Harry person and why do we care about him at this point in the code? Should we send him a page if we can't find him? Is it the responsiblity of the caller of the code to use alternate means to locate the mysterious Harry or do we just give up and look for Jane? Uh oh, Harry quit last week! Now what?

      Oh and too bad for me that you quit last week and moved to Mongolia with Harry so I can't ask anyone these questions about the code that you failed to document and that I now have to support in my copious spare time.

    10. Re:Inline Documentation is evil by Usquebaugh · · Score: 2

      Rubbish.

      Why is the question code documentation should address not how. In your example does the line of code explain why you are looking for a person called Harry? No it merely shows that you are looking.

      Self explanatory, what a joke. Nobody can tell the output of this code. Big deal we've looked for Harry now was that because we like Harry or because Harry is catch all for bad guys?

      I'm not sure who I'm more annoyed at, you for this lame brain amateur idea or the idiots who modded you up. grrr

    11. Re:Inline Documentation is evil by starbirdman · · Score: 2, Interesting

      I agree with the overall point that you are trying to make. However, your main argument against this snippet of code seems to boil down to you don't know how the function is supposed to behave. Shouldn't that be commented on the function itself and not the function call?

    12. Re:Inline Documentation is evil by Viking+Coder · · Score: 2

      its too hard to update comments when you are updating code,

      I think you're the one who needs to find a different job. If your argument is that the benefits of updating comments are far outweighed by the costs, then make that argument. Don't whine about "too hard".

      if you have a code that has a chain of things to be changed for it to work right ... you will end up breaking your thought process if you update the comments while updating the code;

      Fine - update the comments immediately after you update the code. Your thought process isn't interrupted, changing the comments isn't really all that hard, and you're left with good documentation that you can use as the basis of your work, the next time there's a problem in the code.

      however if you do not update the comments a month or year later when it is used again and needs to be changed someone will have to go though a massive debugging because they beleive the comment is correct

      That's why I think you should update the comments. You seem to be switching sides in your argument, here.

      problems like that happen a lot when you comment a large project, which is why in the long run it is easier to just not comment, in the short term as well.

      There turns out to be no actual logical argument to what you've said. Your argument boils down to two points: it's hard to modify the documentation, and bad documentation is misleading. Well, it's not hard to modify the documentation, and bad (or no) documentation IS misleading - that's why coders should put effort into creating and maintaining good documentation.

      I will offer several points as the converse to your arguments: it's far easier to document code immediately after writing it than it is to document it several months down the line - and it's very hard to understand the INTENDED behavior of bad code without any documentation.

      --
      Education is the silver bullet.
    13. Re:Inline Documentation is evil by Viking+Coder · · Score: 2

      *shrug* I was trying to knock the wind out of the implied argument that the code was so simple, there's no reason for anyone to complain.

      So, I complained.

      As to your point, yes - documentation on an API is far more valuable than documentation in the usage of an API. But, I think I've made it clear that the intended behavior of that code was not at all clear.

      --
      Education is the silver bullet.
    14. Re:Inline Documentation is evil by maiden_taiwan · · Score: 2, Insightful

      Most of your criticisms are questions about the behavior of findPerson. These properties should be documented within findPerson, not in the caller.

    15. Re:Inline Documentation is evil by Viking+Coder · · Score: 2

      *shrug*

      If your argument is that documentation is worthless, then make your case. I'm not really that interested in the original code. I'd rather debate the topic at hand. What was offered was a concrete example - so I tried to knock it down.

      Even if you resolve all of my complaints, though, I think the intended behavior of the code is still unclear, without documentation.

      --
      Education is the silver bullet.
    16. Re:Inline Documentation is evil by Viking+Coder · · Score: 2

      If a Person has two attributes with the same type, function overloading doesn't help you document behavior at all. You still need to name the attribute you're looking for.

      I don't know if Person::find("June 26, 1975") is looking for date of birth, or date of death, date of marriage, date of hire, etc.

      "even the ones that really should be defined at the function definition"

      Keep in mind, this poster thought that NOTHING (not even function definitions) needs documentation.

      --
      Education is the silver bullet.
    17. Re:Inline Documentation is evil by Matthew+Weigel · · Score: 2

      Blockquoth lkaos:

      If your code requires massive documentation within the code to make it understandable, then your code likely needs to be rewritten.

      There are two very big reasons why in line documentation is good. First, having user documentation in the source (as with PerlPOD or javadoc) makes it easier to maintain documentation that reflects the reality of implementation.

      Second, algorithm description is important. If you ever try to read 500 lines of uncommented, complicated code, with your only reference is a vague explanation of the algorithm in a book: you'll see what I mean.

      Algorithm description is probably the most important part of literate programming, at least in my view. Particularly when you have to make changes to the general algorithm, or the steps of the algorithm are lost in memory management and error-checking.

      And for mathematical programming, equation formatting (either automatically and in line how CWEB does it or manually the way noweb lets you do it) is essential to bug hunting. With noweb, you can compare raw TeX and C fairly easily, and you can do so with the knowledge that the TeX is a correct expression of the equation.

      --
      --Matthew
    18. Re:Inline Documentation is evil by astroboy · · Score: 2
      If your code requires massive documentation within the code to make it understandable, then your code likely needs to be rewritten. [...stupid example deleted ...]

      I work on an academic simulation code. It's 300KLOC; small by commercial standards, sizable by academic standards.

      It might be (but isn't) true that each and every line of the code is self-documenting; that at every line, it's clear what's happening.

      But you know what?

      There's three hundred fscking *thousand* of them! Sure, it might be clear that two lines do a matrix multiplication, but *why* is it doing it, and what are the implications for the remaing 299,998 lines of code?

      Hell, without documentation running through the entire code, and probably alongside in manuals, how would you even know how to look at those particular 2 lines of code - constituting 0.0007% of the total code base?

      Anyone who thinks that clear code doesn't need to be documented has never written a program more than a few hundred lines long.

    19. Re:Inline Documentation is evil by Viking+Coder · · Score: 2

      I agree with you that I overstated. But I disagree with you that overloading on classes solves the general case problem. For instance, if I want to find everyone who was hired before a certain date, overloading find on some "HiredBeforeDate" class is pretty absurd.

      I think using functors is a much better approach. Wouldn't you agree?

      --
      Education is the silver bullet.
    20. Re:Inline Documentation is evil by Viking+Coder · · Score: 2

      Your post is not really relevant to what we were discussing, as we were not directly discussing Leo.

      I was asserting that documentation is good and necessary, in response to the other poster saying that documentation is never necessary. I don't really think that "inline or not" comes close to describing what we were debating.

      --
      Education is the silver bullet.
    21. Re:Inline Documentation is evil by lkaos · · Score: 3, Interesting

      I can't tell what your code should do if it can't find a person named Harry.

      Good point. The code was a quick example. It likely would have expanded to included error checking if the item wasn't found.

      I can't tell what your code should do if it finds multiple people named Harry.

      Assume that the list is unique.

      I can't tell how to use your code to find a person whose name requires Unicode to represent it.

      And indeed your shouldn't know how. I don't see how commenting would help this situation. If the code snippet supported Unicode, then there would be special Unicode handling classes that likely would be explanatory.

      I can't tell if .name returns a char * that I'm supposed to free or delete [], if it returns a const char *, if it returns a string that I can modify but won't modify the original Person, if it returns a string reference which I can use to modify the original Person's name, if it returns a wstring reference which I can use to modify the original Person's name, if it returns a const string reference, or if it returns a const wstring reference, or if it uses some other string representation like a Qt one, or some custom one - heck, it could even use an MFC-style CString.

      Of course, this is C++ and therefore would return a std::string as all C++ programs should.

      I don't like that the function you've called is named "findPerson" - wouldn't it be far better to call it something like "findPersonByFirstName"? Or "findFirstPersonWithFirstName"? For that matter, why am I calling "Person::findPerson"? Isn't that slightly redundant? Wouldn't "Person::find" be just as clear, and less verbose? Therefore, the function should be something like "Person::findFirstWithFirstName". Wouldn't that be much more highly documented than what you've got?

      Again though, how would commenting help this? This only goes to prove my point that properly written code doesn't need commenting. It also reenforces the idea that commenting may lead to laziness on the part of symbol naming.

      While we're on it, if it is returning the "first", by which method is it sorted? Shouldn't I be able to pass in a parameter which describes the order in which I want the results returned? And shouldn't you get an iterator instead of a reference, anyway?

      Your assuming that the container is not unique. That is a bad assumption.

      I don't like that your code uses a hard coded-value, "Harry".

      Life's a bitch. Constants are only good if they are going to be used multiple times and represent some abstract concept. To have a constant HARRY or something similiar would be silly.

      I don't like that your code has the variable "p". Granted, you've got a pretty amazingly short scope in your example, but code tends to grow. It would be better if the variable had a slightly longer name.

      There are a certain set of variables reserved for local semi-anonymous operations. For me, these are things like ptr, i, p, j, etc. It makes more sense to an experienced programmer to use variables like this since it is obvious that the variable isn't important.

      There are all sorts of things to nit-pick about, that a new coder could be confused about, or bugs which might be on the verge of instantiation, even in code as simple as yours.

      Why must we always write code to be indestructable by a "new coder"?


      If I've just walked in to your code, I don't know what behavior it's SUPPOSED to have, since you haven't documented that. All I can tell is what it DOES do. And since code changes over time, it's impossible for me to distinguish between the two, unless you document it.


      The code is the behavior its SUPPOSED to have. The maintainability nightmare arrises when there are two sources of behavior (i.e. a comment says code should be doing one thing was the code is doing something else). The code is always describing what the programs doing whereas noone really knows what the comments mean or were meant to mean.

      Comments are inferior to code because 1) they are not syntatically verified by a compiler 2) are not tested in anyway 3) and have no effect on runtime behavior.

      The real problem isn't that experience programmers don't comment well enough, its that beginner programmers expect comments to allow them to not learn the underlying language. A new-hire programmer is going to learn more (and be less productive in the short term) by reading code without any comments. In the long term, this translates to higher-productivity. The question is are we going to make this investment in our industry?

      --
      int func(int a);
      func((b += 3, b));
    22. Re:Inline Documentation is evil by Viking+Coder · · Score: 3, Interesting
      It likely would have to be expanded to include error checking if the item wasn't found.

      That task would either have to be performed by the original coder, or by someone else. In either case, documentation would help. Something along the lines of:

      // TODO : error check if it can't find a person named Harry.

      Wouldn't you agree?

      Assume that the list is unique.

      Well, that would be a good thing to document, now, wouldn't it? Otherwise, when a new coder comes in, they'll be all paranoid about the possible existence of other People with the same first name. And if the requirements of your program change to encompass the possibility of multiple People with the same name, wouldn't it be good to have a comment along the lines of:

      // ASSUMPTION: assumes uniqueness of Person

      Granted, your code could be bloated to actually test all of these conditions in each use case - but I'm just asking for comments at the top of the Person class, for instance. I think it would be more useful to document in each function that you're making such an assumption.

      And indeed you shouldn't know how.

      I agree with another poster that you could potentially overload each function that takes a string to take both a string and a wstring, for instance, in order to handle Unicode input. What I was actually suggesting was that it would be better to call your function like this:

      Person::findPerson(L"Harry")

      Of course, this is C++ and therefore would return a std::string as all C++ programs should.

      Actually, I would argue that your function should return either a "const std::string&" or a "const std::wstring&", so that it's clear that you can't modify the output, and so that less useless byte-copying is performed. Granted, string is pretty light-weight, but it's a good coding practice to get into.

      Again though, how would commenting help this?

      Doing away with comments doesn't magically make existing code better. Many people have argued with me - saying that adding comments does make code worse. I think they're crazy. Code will always have mistakes, but documentation gives you insight into the mind of the coder like code cannot. Especially when you see something like "// FIX THIS" sprinkled around. =)

      This only goes to prove my point that properly written code doesn't need commenting.

      I would argue that by your definitions the only "properly written code" would be code that meets at least one of these two criteria:

      1. It was written by someone with total recall. (In other words, they could recall the initial requirements perfectly, and had no need to write them down for posterity.)
      2. It can be proven to contain no bugs.
      Since neither criteria is very common, I would argue that almost no code is "properly written". I use your initial snippet as an example. Even something as simple as that had, in my mind, many problems. And you even agreed with one of my complaints! Therefore, your code was not properly written! COMMENT IT!

      It also reenforces the idea that commenting may lead to laziness on the part of symbol naming.

      Bad habits will always exist. One good habit is documenting unfinished code. Another good habit is documenting the design of any code, and the expected results under outlier conditions.

      Your assuming that the container is not unique. That is a bad assumption.

      If you'd documented your code better, I would have realized that. That sounds like a communication problem between two coders. One way to address that (not "solve", but "address") is that each coder try to document their assumptions, where it makes sense to do so. "At least once" would be nice.

      Constants are only good if they are going to be used multiple times and represent some abstract concept.

      Or, if their value ever needs to be changed in the future. (Such as making it Unicode compliant.) Or if the existence of the constant itself needs to be documented. Or if the constant itself comes from an original source, such as a paper describing an algorithm, or requirements specifications. Or if the constant needs to be translated into multiple languages. Or if the behavior of the constant needs to be checked by regression tests. I could go on, but I think that I've shown that your statement was rubbish.

      There are a certain set of variables reserved for local semi-anonymous operations.

      Who reserves them? Oh, you do. What about every other coder who'll have to look at your code? Do they get reserved variables, too?

      If you've ever written code like this:

      for (int i=0; i<max_i; i++)
      { ...
      } ...
      for (i=0; i<max_i; i++)
      { ...
      }

      Then you're guilty of writing non-portable code. The variable "i" is neither reserved by the compiler, nor do all compilers check to make sure that "i" is properly in scope in the same manner.

      ...since it is obvious that the variable isn't important.

      I believe you meant to say "since it is obvious that the variable name isn't important."

      I kind of like the rule that the length of a variable name should be proportional to the log of the length of its scope. *shrug* I know what you're getting at, but you must agree that as soon as the usage conditions on "p" become greater, it should probably be renamed. *shrug* Not really one of my main arguments.

      Why must we always write code to be indestructable by a "new coder"?

      Good code is a journey, not a destination. I think everyone should at least make an attempt to constantly improve their technique. If I didn't care what other people think or do, I wouldn't bother to argue with you.

      The code is the behavior its SUPPOSED to have.

      Wait just a minute. Let me go back and quote you to you, again:

      It likely would have expanded to included error checking if the item wasn't found.

      Well, WHICH IS IT? That code was either SUPPOSED to crash, if the item wasn't found, or it "likely would have to be expanded to include error checking."

      This really pisses me off. Can't you see how dumb you sound, here? I know that you're an intelligent person - you're making pretty good arguments - they just happen to be incorrect. But these two statements here, more than anything else, prove that your argument contains inconsistencies.

      The maintainability nightmare arrises when there are two sources of behavior

      Let me list sources of behavior:

      1. What the user thinks they want
      2. What the user really does want
      3. How the conditions will change in the future
      4. How the coder meant to type in the code (typing in an algorithm it's possible to have typos - it's VERY useful to CITE your sources, so they can be checked, later. Otherwise, I have to figure out, by hand, what's wrong with the code you typed in.)
      Since there are always multiple "sources of behavior", I think it would be far better to document the choices that the coder made, than to leave them up in the air, undocumented.

      Comments are inferior to code

      Code without comments is inferior to code with comments.

      Granted, I'm expecting a certain level of maturity in the people writing the comments, but your assertion seems to be that the code is somehow BETTER if you intentionally REMOVE intelligent comments. That is an untenable position.

      I disagree with your summation of "the real problem", in your parting paragraph.

      I think "the real problem" is that it's impossible for the computer to understand the intention of a coder. It is only possible to verify the intended behavior of code, by having another human read the code. That process is aided by good documentation. I agree with your assertion that bad documentation is misleading. However, code with documentation is guaranteed to be AT LEAST AS GOOD as code without documentation. It is always possible for a human to remove documentation, and look at just code. At the very least, cite your sources for algorithms that you implement - that alone would dramatically improve the quality of a lot of code.
      --
      Education is the silver bullet.
    23. Re:Inline Documentation is evil by Viking+Coder · · Score: 2

      Actually, I back-peddled too far, in my original response to this message.

      You're still naming the attribute you're looking for - you're just using a different mechanism to do it. (New classes instead of new functions.)

      And, like I originally responded, functors are a better general mechanism.

      --
      Education is the silver bullet.
    24. Re:Inline Documentation is evil by harlows_monkeys · · Score: 2
      If your code requires massive documentation within the code to make it understandable, then your code likely needs to be rewritten.

      Or you are doing complex problems, using algorithms that you developed or that are otherwise likely to be unfamiliar to the reader.

      Read the examples in Knuth's book. His system makes it much easier to understand what is going on, AND makes it much easier to write correct code.

    25. Re:Inline Documentation is evil by MajroMax · · Score: 2
      I don't like that the function you've called is named "findPerson" - wouldn't it be far better to call it something like "findPersonByFirstName"? Or "findFirstPersonWithFirstName"?

      Actually, I think it should be called findTheFirstPersonWithTheFirstNameThatIsSpecificed ByTheFirstArgumentToThisFunctionCallAndThereAreNoM oreArguments_TheFunctionThrowsPersonNotFoundExcept ionIfItCannotFindThePersonWhoseFirstNameYouSpecify

      There is something to be said for short function names.

      --
      "Evil company X is threatening to restrict our rights! Let's all get together to stop--OOOH! SHINEY!!!" -- AC
    26. Re:Inline Documentation is evil by Viking+Coder · · Score: 2

      Okay, let's call it "f".

      Or, better yet, how about if we just overload operator() on the class to make it into a functor, and overload it for every possible function - using new classes to specify the types of parameters.

      I think you're onto someting. *chuckle*

      --
      Education is the silver bullet.
    27. Re:Inline Documentation is evil by civilizedINTENSITY · · Score: 2

      f? I thought functions were all named "lambda"!

    28. Re:Inline Documentation is evil by lkaos · · Score: 2

      That task would either have to be performed by the original coder, or by someone else.

      The code I used in the example was a quick snippet to illustrate a point. In this circumstance, I would have to say that implementing error checking would have been as difficult as writing the TODO comment. I have been known to use TODO comments though and I agree that they are useful.

      Assume that the list is unique.

      Well, that would be a good thing to document, now, wouldn't it?


      Well, that documentation would be at the class level, not at the usage level. Notice I didn't include the class. API references are much different than the kind of documentation discussed in this thread IMHO.

      I agree with another poster that you could potentially overload each function that takes a string to take both a string and a wstring, for instance, in order to handle Unicode input.

      Unicode and ASCII aren't the only types of character sets... For most applications, that doesn't matter though. It definitely is outside the scope of this program (and most programs for that matter).

      Actually, I would argue that your function should return either a "const std::string&" or a "const std::wstring&",

      boost::call_traits::param_type

      Much more portable (and accurate in the long term) since you can change the behavior on a per-type level throughout your program (if for some instance, you have a class where a function that should be const isn't, that you can't modify, you can specialize call_traits to return just a reference).

      call_traits will likely end up in the next standard too.

      Doing away with comments doesn't magically make existing code better.

      So, I assume we've all had the project managers or have been in the code review where some entry-level person starts complaining because in college, pseudo-code was included with the regular code. Stuff like.

      int iIterator = 0; // initialize iIterator
      const int LOOP_LENGTH = 10; // loop length constant // write Hello World ten times to the screen
      for (iIterator = 0; iIterator Who reserves them? Oh, you do. What about every other coder who'll have to look at your code? Do they get reserved variables, too?

      They're not officially reserved. It's just the common variables that anyone who's done software developer for any length of time is used to. I don't think I have to explain myself here.

      Good code is a journey, not a destination.

      It's amazing, and I'm saying a prayer for the desperate heart tonight ;-) Sorry, couldn't resist.

      Well, WHICH IS IT? That code was either SUPPOSED to crash,

      Perhaps like a map, if the item isn't found, an element is created and a reference is returned (with a default name derived from what's being searched for). There's no reason to assume the function could fail or even that the results are undefined in the event that the person couldn't be found.

      Granted, I'm expecting a certain level of maturity in the people writing the comments, but your assertion seems to be that the code is somehow BETTER if you intentionally REMOVE intelligent comments.

      Not at all, but rather that I believe it is harder to write and maintain good comments than to write and maintain good code. Far to much emphasis is put on commenting and documentation IMHO and not enough on coding style itself. Just look at the typical new-hire. They tend to lack any kind of useful design skill or coding style but have been engrained with this over commenting nonsense as if it was necessary to have detailed psuedo-code with all code that is written.

      IMVHO, a software project is more maintainable is strict design reviews are enforced along with strict style guides than if strict comment guides are enforced. In fact, I have not found that strict commenting guides have helped make any project I've worked on more maintainable.

      In fact, they have typically done the opposite which of course resulted in my writing nice little scripts to s/\/\/*^//. I'm sure you have experienced this. Header files that are 70% comments of which, nothing is particular useful ("This file implements the MyClass class" type things).

      --
      int func(int a);
      func((b += 3, b));
    29. Re:Inline Documentation is evil by Viking+Coder · · Score: 2

      Let me just go back, one more time, and point out how inaccurate and inconsistent your arguments are. This statement is inaccurate:

      The code is the behavior its SUPPOSED to have.

      For instance, if you code a bug, by your axiom, the buggy behavior is the behavior the code is SUPPOSED to have.

      So, sometimes there is a need to distinguish between what code says (and literally does), and what it means (and what it's supposed to do). One truly excellent way to express that code has meaning beyond the actual text of the code is to comment it.

      And here's an example of your inconsistency:

      Inline Documentation is evil

      And then you said:

      I have been known to use TODO comments though and I agree that they are useful.

      Maybe it's naive of me, but I guess I thought that "evil" and "useful" were complete opposites, in the framework of this discussion. Although, I guess I believe that Microsoft is evil and can be useful, so I guess I can't completely mock your opinion on this point. =)

      Thanks for bringing boost::call_traits::param_type to my attention. I'll look into it.

      --
      Education is the silver bullet.
  9. Questions. by bons · · Score: 3, Insightful
    When programming in a literate system do you describe the objects and methods from a programming viewpoint, a business viewpoint, or from a metaphor viewpoint?

    When we build systems, we work directly with the client and we are able to describe the system in three equal, but very different ways. Depending on the documentation required and the target audience, we can describe the system in a way that allows everyone involved to communicate effectively. This is an advantage I don't want to lose.

    From what I've read, literate programming seems to be a discipline that works best when the programmers are isolated from the client. How it works when the programmers and the client closely interact is something I simply don't understand.

    1. Re:Questions. by Matthew+Weigel · · Score: 3, Insightful

      Blockquoth bons:

      When programming in a literate system do you describe the objects and methods from a programming viewpoint, a business viewpoint, or from a metaphor viewpoint?

      At its heart, literate programming creates multiple documents from a single master document. The common case is creating two documents - a document that is a paper on a program, and a document that compiles to the program - from the master document; but it's entirely possible to create more than just the two documents with a tool like noweb.

      As an example, you could produce API documentation, algorithm descriptions, a description of the interaction of the whole schebang, and the program source itself from a single set of master documents.

      And, again, the gain of literate programming is that you can keep all these forms of documentation close to each other and close to the code, which is a win.

      Now, noweb isn't perfect: it's optimized for creating just one set of documentation, so the other documentation would have to be treated as code. It would be a lot better if you could name documentation blocks just like code blocks, but oh well...

      --
      --Matthew
  10. Curing unmaintainable code by gwernol · · Score: 5, Interesting

    Roedy Green has written an excellent, humorous online article on writing unmaintainable code. This relates directly to Literate Programming, especially Roedy's points about maintaining existing code. He writes (here): "[the maintainence programmer] views your code through a toilet paper tube. He can only see a tiny piece of your program at a time. You want to make sure he can never get at the big picture from doing that. You want to make it as hard as possible for him to find the code he is looking for. But even more important, you want to make it as awkward as possible for him to safely ignore anything. "

    Literate programming in general, and Leo in particular, would be the ultimate cure for this. It allows you to easily navigate between multiple levels of description of a program. This is critically important if you are coming fresh to an existing piece of code. You need to constantly cross-reference the high-level design and low-level implementations (and the various levels of description between these extremes).

    --
    Sailing over the event horizon
    1. Re:Curing unmaintainable code by edream · · Score: 3, Informative
      Thanks for this comment!

      A lot of people seem to feel qualified to comment about Leo after just reading the original slashdot article. Most have no clue about what Leo is or isn't. I've spent seven years working on Leo. I'm getting pretty annoyed about people commenting about Leo without even taking seven minutes to play with it.

      Leo really isn't all that much about either literate programming or documentation. I explain what Leo is in my posting, "The creator's view of Leo."

      Edward K. Ream

  11. It still won't take off.. by Da+VinMan · · Score: 3, Interesting

    I've tried Leo in the past, and while I support the author's ideas and the idea of literate programming in general, I do not believe that the practice will become significantly more common in the near future.

    There are two reasons I believe this:

    1. More and more modern IDEs support the idea of folding sections of code at multiple levels. Combine this with some well placed comments, and you achieve a very high degree of readability. This nullifies the primary benefit of Leo and ensures that most developers won't ever look at literate programming tools.

    2. Changing over to literate programming is, at least superficially, a large change. It's a large change because it requires that developers switch their primary environment. That's a big deal. Even if developers had the tools for literate programming in their preferred programming language already in their hands, they probably wouldn't use it.

    I do hope I'm wrong about the above though. I think a shift in the industry (even for a relatively short time) to literate programming would give us new ways of thinking about systems design, development, and would greatly ease long term maintenance.

    --
    Please mod this post only if you think others should/n't read this. I have enough ego^H^H^Hkarma. Thanks!
    1. Re:It still won't take off.. by Da+VinMan · · Score: 2

      I would say that IDEs do not support outlining at all. My observation was just that code folding (such as that provided in Visual Studio.NET) would provide everything that most developers think they need. Of course, it's not the same as literate programming, but it does bear a superficial resemblence.

      More importantly though and FWIW, I think we all owe you a big "Thanks". You've brought the literate programming discussion back to life for everyone and I'm sure we're all better off for it.

      And a quick question: Do you think you'll ever put together a commercial version of Leo that functions within mainstream IDEs? I can see how Leo's features would be particularly useful within the context of products like VS.NET, Eclipse, etc.? I'm just curious on this count, but I know what a big effort this represents.

      --
      Please mod this post only if you think others should/n't read this. I have enough ego^H^H^Hkarma. Thanks!
    2. Re:It still won't take off.. by Louis_Wu · · Score: 3, Insightful
      Combine this with some well placed comments, and you achieve a very high degree of readability.
      [sarcasm]

      Good writers know how to spell, and will catch spelling errors while proofreading for content and style. Besides, all good writers have dictionaries sitting on the desk for clarification of subtle meaning of words, and thesauri to remind them of better ways to express the idea. Knowing this, spellcheckers are unnecessary, and often counterproductive. I can't tell you how many times I've been writing a technical paper and had some stupid spellchecker choke on acronyms or technical terms! A good writer's skill nullifies the primary benefit of a spellchecker.

      [/sarcasm]

      But seriously, the problem isn't that it is IMpossible to write good, well documented code with Your-IDE-Of-Choice, but that Literate-Programming + Leo might make it easier to write well documented code. Hmm, sounds like the language selection process for a project; text manipulation in Perl, sound driver in C. You could write your text mangler in C, but Perl makes text processing easier. That's the point of Leo, make documentation easier.

      Consider any spelling errors intentional. :) BTW, I tried to post this two hours ago, but /. disappeared from the net. Since the discussion continued, I can only conclude that it's the computers at work which were being stupid.

  12. Been there, done that by devphil · · Score: 4, Funny
    It's wierd, when you think about it, that programming is still done in flat text files.

    Every compiler vendor who has sold a mainstream language compiler/IDE using a "program database" or some other such approach has tanked. (Note that I mean program database as the primary means of storing the code -- a replacement of flat files, not an addition to them.) So far, it's not really been a technological lack, it's just that programmers don't like it.

    I recall reading some papers written by the major language guys a decade ago, and one of the things they all wanted to see was per-function recompilation (instead of per-translation-unit), better program information (like "where is this function used?") and other things that would require a more database-like format. Still hasn't happened except in research environments. (Pity.)

    One could argue for programs in HTML, with the code bracketed in XML

    One could, but one would be a lunatic.

    (I'm too tired to write it all down now, but I'll just summarize by saying that XML is not a silver bullet.)

    --
    You cannot apply a technological solution to a sociological problem. (Edwards' Law)
    1. Re:Been there, done that by kawika · · Score: 2, Interesting

      Every compiler vendor who has sold a mainstream language compiler/IDE using a "program database" or some other such approach has tanked.

      Well, except for Microsoft. Visual Studio 6 didn't go far enough in that direction, but it was a start.

      Visual Studio.NET does a lot more. In addition to its own use of the database, the IDE is built so that third parties can hook into it and add their own functionality. For example, one vendor will be releasing an add-in that takes UML and creates source for the appropriate C# or VB classes. If you later change the classes in source, it updates the UML.

      Sorry to sound like a marketing pitch.

    2. Re:Been there, done that by Tablizer · · Score: 2

      (* I wouldn't wish it on anyone except an ex-dotcommer who needs a job really bad. *)

      What is wrong with ex-dot-com-ers????

      I got into web stuff because I saw it as a decent solution to some fat-client problems, not because I was a gold-digger. (And, I was in the computer biz long before the craze hit.)

      I think what you have in mind is somebody who jumped into web stuff when it was big bucks (or at least big promises).

    3. Re:Been there, done that by RelentlessWeevilHowl · · Score: 4, Interesting

      IBM's Visual Age for Java used something similar, adapted from their Visual Age Smalltalk. My problem with VAJ was that you couldn't do anything in their environment except what they had specifically designed for you to do. If you have files in disk, you can run whatever tools you want on them. But in VAJ or Visual Studio .NET? "I dunno, what's in the context menu?"

      To avoid flat text files, you'd need an interactive scripting language powerful enough to perform any task you'd care to think of (viz., Emacs). Plus you'd need enough support libraries available to you to interact with third-party utilities, and finally bindings for the abstract syntax trees of all the languages you want to program in, so you could manipulate them programatically.

    4. Re:Been there, done that by jerryasher · · Score: 2

      ;;; lisp is not a research environment ;;; http://www.orbitz.com ;;; http://store.yahoo.com

      t

    5. Re:Been there, done that by Tablizer · · Score: 2

      (* You were a "dot comer" because you have no real technical expertise. You code VBScript and talk out of your ass on several forums about your misunderstandings of computer science. *)

      I will pit my programming skills for real applications against yours anyday, AND they will stand up to change at least as well!

      I am good and I can kick your ass at software design any day!

      OOP is an unproven fad and you know it because there is no fricken evidence that it is better for common domains.

      No
      God
      Damned
      Fricken
      Real
      Evidence, Just fan noise.

    6. Re:Been there, done that by pacc · · Score: 2

      Yup, the proposal was to edit in HTML code to be able to see the results while coding, not to get a lot of brackets all over the place. XML lets you do that, the other alternative is to create a totally new standard to store all the extra information...

      Though I admit that editing XML raw without any auto-completion, syntaxchecking etc is pretty useless.

  13. Re:COX by unicron · · Score: 2

    No, you're more than a posting newb if you think just because your house is wired with fiber that you're going to get speeds like that. Because from the nearest CO, that shit is all coax, so unless your running fiber all the way there, which can be some distance away, you're full of shit.

    --
    Finally, math books without any of that base 6 crap in them.
  14. The Problem With Literate Programming by raytracer · · Score: 4, Insightful

    The biggest problem with literate programming is that most people don't write programs that are worthy of exposition. Most programs are written under extreme time constraints to solve immediate or practical problems, and their complexity arises from handling exceptions, special cases, and last minute or ill conceived extensions. Documenting these with prose actually doesn't help very much, as the prose reads pretty much as the code does: as a set of ill conceived exceptions rather than bold themes. Making the prose flow well is just work that could be used to make the code better.

    If your code doesn't have these faults, then the code is already an expression of the program ideas, and one that you can excecute, so in that case literate programming techniques are needed to a much smaller degree.

    There is no doubt that literate programming (like extreme programming) has its benefits, but their principal benefits are to encourage an attitude of critical evaluation to your coding efforts. This criticism is encouraged in literate programming
    but not a unique feature of that approach.

  15. Re:COX by unicron · · Score: 2

    Yeah, but do you honestly think you're "pulling one over" on Cox?

    --
    Finally, math books without any of that base 6 crap in them.
  16. Even more Bogus... by Midnight+Ryder · · Score: 2

    Hey Jack - I think your example is actually more bogus than what you are complaining about. Let me yank this one section out, and put things in perspective...

    The goal of a programming language is to provide a machine with a set of instructions, not to sit down and read it a story. Do you expect your car to be made of parts which have little embedded notes explainging how they were engineered? Of course not, that's just silly

    And, when you look at your compiled program, you don't see comments or documentation inside of it either. The compiler strips it out, as it should. However, when you code, you document. When a car builder designs a machine, they document it into such detail level it makes programming documentation look sparse (most of the time - I've seen it be overdone before ;-) It doesn't matter what you do, building cars, wiring offices, or programming, you better be documenting what you do - and those who don't regret it later, and lack of planning up front causes serious issues.

    I probably shouldn't pick on your example - but it was a really nasty example.

    Now, I don't completely disagree with your opinion that it's gimmicky, but, this provides yet another process for people to adopt if they so choose to. Any method that people feel comfortable with for software engineering or documentation that gets them to DO IT, well, sounds like a good idea to me.

    --

    Davis Ray Sickmon, Jr - looking for something to read? Check out my three free novels at MidnightRyder.org

  17. More focus on API Doc and Unit Testing by one9nine · · Score: 3, Insightful

    I don't think what he has is bad, but I think there a better ways to achieve cleaner code.

    Many people have mentioned that writing cleaner code is the best form of documentation. This is definitely true, unfortunately you still have people who use letter for significant variables (i.e. not loop indexes) and who don't format their code or try to do too much in one line of code.

    I think a better approach to documentation is the test driven approach that is used in XP and with packages such as JUnit and Cactus. Basiclly, you write your test cases first, which will force you to pin down the exact functionality for your components. These unit tests are essenailly doecumentation on how your components should work. Granted, this doesn't document the specific code but I think that one of the reasons why so much code is hard to read is because the functionality was not clearly thought through.

    I also think API documention is more important. Alot of times I am trying to use an open source package and I have a hard time understanding how to use the API to achieve certian fucntionality. I can read the code just fine but it isn't clear how to use the objects themselves.

  18. The right balance by teetam · · Score: 4, Interesting
    Too much documentation is just as bad as too little documentation, even when the documentation is good. It is very difficult to strike a balance.

    For example, many of the core java apis are well written and well documented. If you see the HTML javadocs, you can get a pretty good idea of the class.

    However, when you open the source code of the same class, it is not good looking anymore. Why? Because each method is preceded with dozens of lines of javadoc, each of which is embedded with HTML markup. That is good when the javadoc HTML pages are finally generated, but not so good when you look at the source itself. C# is worse with its XML based documentation!

    When I look at the source code, I want to see the flow of the code easily. All the documentation in the source should only aid this and not hinder this. Javadoc does both. The explanation part of the javadoc can be very useful in understanding what the author's intent was when he/she wrote the method, but I am not so sure about the rest. The param, return and exception tags are no doubt useful, but often developers don't explain these very well. Plus, these are the tags that can easily become outdated.

    I would prefer short and succint pieces of information documenting the code, preferrably close to the line of code that it documents.

    --
    All your favorite sites in one place!
    1. Re:The right balance by e2d2 · · Score: 2

      I agree with the idea of having it both hinder and help at the same time. When you see 30-50 lines of comments for each method it can sometimes get in the way. I (partially) like the way Microsoft has handled this with their C# compiler, allowing the developer to generate xml a meta document similiar to JavaDoc or the developer can choose to place the comments in an external file and reference them from within the code comments using the tag. But I did not like the way it outputs only xml, so if I want an html document I have to either use VisualStudio's tool to output html comments based on their templates (poo poo) or parse the xml myself.

      A standard for Literate Programming certainly wouldn't kill any of us.

    2. Re:The right balance by e2d2 · · Score: 2

      doh, it ripped out the include tag in my post above for obvious reasons. The C# include comment tag is what I was talking about.

  19. Another Idea... by Sj0 · · Score: 2

    Another idea which would work well in this respect would be altering the language used to be more reader freindly. Much C code is written whose syntax is a greater barrier to understanding the code than any concept underneath. Seperating some aspects of the language from regular syntax (such as pointer notation -- Sure, it's simple in theory, but in practice, it takes a fantastic long-term memory to remember whether you are witnessing a pointer being set to a memory address, or a value being placed into a variable without flicking around the source code or using a third party utility, which just slows you down and interrupts your thought process). Sure, an experienced coder can decipher obusficated(spelling?) code, but if the language makes it one step easier, that's a little bit of brain power to the question of "Why the hell did the original code do that?", and takes a bit away from the question "what the hell does this code do?".

    --
    It's been a long time.
  20. Outlining and LitProg by DarkMan · · Score: 2

    One of the advantages of Literate Programming is (at least from my experinece) is that one can start with a general idea of what is needing done, and then fill down to the end, as it suits the programmer. For example, when writing a sorting routine, at some point I know I'll need code to swap the contents of two pointers. I can (in CWEB) just put a place holder in, and write it later, or, if I've got the code in my head, just write it down directly.

    This method models the way that (for me at least) code is thought about. That's the key idea in LitProg - to put the source code / documentation down in a manner that models the thought processes of the programmer.

    I don't have a full, firm, outline in mind right at the start. That's not to say I don't think about it - but it's not final. Using an outliner at the start would not work well with me. CWEB forces me to document the thought behind each step of the algorithm, and presents it in logical order, even though it was not written in that order.

    Maybe if I had a cast in stone plan for the code before I start, I'd write better code. But I work well enough with CWEB &c that I don't see the addition of an outliner assisting.

    Frankly, looking at the web page, it looks just like an outlining code editor - nothing that dramatic, and I'd rather stick to vi + CWEB.

  21. Works transparently with other tools by jko9 · · Score: 3, Informative

    Something I didn't put in the original notice but now regret that I left out - Leo has another new feature more difficult to describe, but that which solves the problem that several people have mentioned about not wanting to abandon an existing text editor or tool. Leo can embed an outline structure in comments, so that one programmer can work with the file in JBuilder or EMacs, and a third programmer can still work with the program(s) in Leo. In effect, Leo is a meta-text editor. When Leo opens an outline containing a file that has been edited with another editor, all of the edits are retained. This is a further extension of LP because you are getting code read back into the documentation, which means that LP techniques can be used for understanding and/or teaching existing programs. It also means that Leo allows LP to be a secondary technique to add additional structure and documentation, rather than necessarily being the primary technique. This is explained in more detail in the tutorials and Leo docs.

    It is true that there are other IDEs that allow folding, e.g. Visual Studio .NET, but this ability to separate the outline from the program is something new, as far as I know. Also, unmentioned in the original article is the idea of having clone nodes, which means your outline can put the same code section into different branches simultaneously.

  22. Why this doesn't work. by FreeLinux · · Score: 4, Insightful

    The following statements will be highly inflamatory to many people. They are not intended to be inflamatory but, rather a simple observation.

    Basically, Leo is yet another tool to automate the documentation of programming code. There are dozens, possibly hundreds, of programs available for this task. Yet, the problem that these tools were designed to solve remain very prevalent, if not pervasive.

    The reason that the problem remains and that Leo will not solve the problem either is relatively simple. Simply put, the problem is garbage-in, garbage-out (GIGO). These tools are not able to determine the purpose of the code or the intent of the programmer that is writing it. These tools cannot read the minds of the programmers. The tools rely on the programmer to write out their thoughts and the intended purpose of the code.

    Most programmers are unwilling or incapable of performing this critical step thoroughly. All too often, they use shorthand and expect the reader to understand what they mean. Or, they believe that the reader should be able to understand their thought process by reading the code itself. Furthermore, they assume that if the reader can't do this, they are simply not a good programmer (1337).

    To go a step further, many programmers are not capable of clearly expressing their thoughts in their native tongue. These people are quite brilliant and can do amazing things with their code but, they can't express their thoughts to another person unless that person is indeed, able to read and comprehend the code itself.

    Now, in fairness to the programmers, we have to look at what they do and what they are taught. Most programming languages are all about efficiency. They rely heavily on abreviations and aliases, why do you think it's called code? They are designed to require a minimum or typing while providing a maximum of functionallity. The programmers themselves are always striving for increased efficiency both in their code and in the way they get the code done. They always try to put out more which leads to further shortcuts and abreviations. This all tends to make programmers minimalists and their documentation clearly reflects this.

    So, Leo is unlikely to provide any documentation breakthroughs. The old rules still apply, garbage-in, garbage-out. The best idea I've seen was an earlier post, where the documentation is written first and then the code is developed to match the documentation. But, honestly, which of us going to do it that way. That's a lot of work and our ingrained habits are going to be hard to break.

    1. Re:Why this doesn't work. by PigleT · · Score: 2

      "Furthermore, they assume that if the reader can't do this, they are simply not a good programmer".

      Well, as an asumption as you mention this would be bad. Note, however, that there's a very prevalent half-way state: those who really shouldn't be looking at a program because they don't know the language with its idioms, but still somehow declare it to be "illegible", more because of their own shortcomings than any other.
      IOW, ability to *read* source is a distinctive feature of a good *programmer*. I've experienced folks who can spew code like the proverbial curry after a few pints, but were strangely unable/unwilling to look in any detail at it to debug it later...
      Just a point to raise in your considerations...

      "why do you think it's called code?"

      I absolutely hate calling a good program "code", and therefore don't. I suggest you confine your use of the word to garbage that the compiler can understand and your Typical Average Humanoid, even one well-versed in the language, can't (at second inspection).

      "This all tends to make programmers minimalists and their documentation clearly reflects this."

      By and large, I'll agree, although I think minimalism can be a form of elegance in the program itself.

      FWIW (karma whoring, no doubt), <a href="http://haskell.org/">Haskell</a> has had a "literate" mode (*.lhs instead of *.hs sources) since the get-go as well. Leo is definitely not the first.
      And the rest of the language is pretty darn' minimal too - the "list composition" [expr | condition ] stuff reads almost like Perl-meets-SQL to me ;)

      --
      ~Tim
      --
      .|` Clouds cross the black moonlight,
      Rushing on down to the circle of the turn
  23. Re:Bogus by joto · · Score: 2

    This wouldn't be so bad if you actually was funny, Jack. But regrettably, you are not, and if someone laughs, it is you they are laughing off.

  24. Re:Bogus, truly! by alienmole · · Score: 4, Insightful
    I've been a Q1 member of the IOOC 911.11 committee for programming languages since the early 90's

    IOOC 911.11? Would that be the International Olive Oil Council, or the Iranian Offshore Oil Company?

    Not to feed the troll, but for the benefit of any impressionable young programmers:

    The goal of a programming language is to provide a machine with a set of instructions, not to sit down and read it a story.

    Programming languages intended for use by humans (as opposed to languages intended primarily for machine generation) have multiple goals, three of which are to be human-writable, human-readable, and human-maintainable.

    Literate programming may not be a perfect solution, but it's addressing a real issue. Current programming languages tend to be pretty horrible at expressing abstractions in a human readable way. The ideal programming language would be one that allowed you to express abstractions at the level of the problem domain, yet was able to translate that into something as efficiently executable, or close to it, as something written in a lower-level language. Literate programming allows you to do something along these lines, although it still involves a fair amount of "manual intervention" on the part of the programmer.

  25. Dunno how literate I am, but here's what I do... by smartfart · · Score: 2
    IANAP, but I've slipped into a mode of typing what I'm trying to make my program do in comments, then I'll dig through my PHP book to figure out how to implement it. Once I get some bit wortking, I'll add another comment saying, "ok, I can make that array work, but now I need to figure out how to put this data into it from a form or something...".

    Its ugly, but it seems to help me out.

  26. Amen by ArcSecond · · Score: 4, Insightful

    I am more of a technical writer than a programmer (well, really, I'm not much of a programmer at all), but it was always clear to me that 90% of the software development headaches I lived with at various companies could have been resolved with minimal effort early in the project.. IF anyone cared about using a methodical approach to project documentation.

    But nobody likes documentation. Writing it. Reading it. Just the word makes some people itch. For some reason, this is something that BOTH business managers and programmers don't get: documentation saves work. It is a way to produce a testable set of requirements, then a testable architecture/design, then a way to match up features and metrics in production and testing.

    I mean, why does everybody think writing the manual is the LAST thing you do when you make software? With all the snarky "RTFM" comments I hear from geeks, I should start a new variant...

    "PUHLEASE! BEFORE YOU START CODING, WTFM!"

    --

    I've got a bad attitude and karma to burn. Go ahead. Mod me down.

    1. Re:Amen by G-funk · · Score: 4, Insightful

      The reason geeks don't like writing too much documentation is simple. It's not laziness (well not always), it's just one simple thing.

      Documentation written before the project completion is wrong.

      Always.

      Full stop.

      No matter how good your documentation is, people in charge will look at it, and go "great!" then half way through, they look over your shoulder and say "that's not how i want that to work" and they make a "simple" change that creates a whole new use case, or sends an existing one off on a tangent. Or, a programmer half way through will come up with a better idea himself, and discuss it with the boss, and so it changes from spec again.

      And the worst thing in the world definitely isn't no documentation, it's wrong documentation.

      --
      Send lawyers, guns, and money!
  27. Literate programming versus continuing development by Phronesis · · Score: 5, Interesting
    Although literate programming has a lot of potential, all too often literate projects become completely ossified. M.D. McIlroy's criticism of Knuth's literate programs (CACM 29, 471-83 (1986)), that they tend to be like "industrial strength Faberg eggs" as opposed to reusable tools, is still quite valid.

    For a project I am working on, I needed to extend CWEB to do some things Knuth hadn't thought of, and I found that excessive cleverness in the data structures made it much more difficult to extend than it should have been, so that Knuth could demonstrate clever data structures that probably add a few percent to the performance over what he could have achieved with more prosaic ones (Knuth does not document why he made these excessively clever design choices, nor whether the performance advantages they offer were significant).

    Similarly, a recent thread on comp.text.tex recently asking about the extensibility of TEX produced a number of comments from those who know about how unextensible and unreusable TEX really is.

    So, while I use literate programming (CWEB) to document a lot of my own code, I don't believe in all these years, that I have ever seen a good example of literate-programming that looks towards the future (refactoring, extending, reusing) as opposed to generating a fossil with that comes with a good story of its life and times.

  28. Sync code with docs, not vice versa! by dstone · · Score: 2

    At least the idea is nice. Attempt to keep the doc in sync with the code.

    I hope you meant "keep the code in sync with the doc". ;-)

    in our environment most of the doc is actually in presentation forms, some diagrams, word documents, etc. These also need to be kept in synch with the code.

    Ummm... You mean the code has to be kept in sync with these docs, right?! Please?

    From what I've skimmed of Leo, it's certainly not designed to generate/update docs after you wrote code. Thank goodness. Having to update docs to match the code can be a serious symptom. There are exceptions, of course, but in my opinion, if you're updating your docs -after- your code has already changed so often that you need a -tool- for it, welll....

  29. Re:look at the screenshot of pg 10 from the perl s by edream · · Score: 2, Interesting
    I am the creator of Leo. Leo shows that the "stream of consciousness" style typically associated with literate programming can be replaced with a more effective organization, one that is more like a reference book.

    So you could say that Leo turns literate programmers into reference librarians ;-)

    -Edward K. Ream

  30. Re:Sensible uses for Hungarian Notation by Sj0 · · Score: 2

    Old Qbasic had an interesting way of doing that. You just put the right symbol at the end of the variable. It forced you to follow the standard, because anything which wasn't declared otherwise was automatically a single precision floating point number(which hurts speed -- a lot.)

    --
    It's been a long time.
  31. Literate programming caveats by majordomo · · Score: 2, Interesting

    I've used both CWEB and noweb, the latter for a large scientific computing project involving (among other things) a large number of tensor operations. While I've thus found the TeX math typesetting features invaluable, literate programming has some serious drawbacks.

    The most common problem for me has been the function/code chunk dichotomy. You might have a code chunk like "Set initial conditions" and only later realize that your chunk is too long and you need a function: set_initial_conditions(). Literate programming makes it so easy to write chunks of code without wrapping them in functions that your code ends up with too many chunks. If you do take the time to make functions then you vitiate much of the advantage of your literate programming chunks, since you end up just deleting the chunks and replacing them with descriptive function names.

    Another serious problem is that it is very difficult to invert a literate program into human-readable source code; i.e., if you decide to junk CWEB and go back to C source and header files, you are in big trouble, since the machine-readable source code is horrendous -- not to mention stripped of all comments! So you really make a huge commitment if you decide to go the literate route.

    Having used lit. prog. for several small projects and one big project I appreciate some of its advantages, but on balance I think that well-documented standard code is better. The only thing I really miss in standard coding is TeX math typesetting, but this is easy to rectify. I just wrote a simple program to convert a regular source file into LaTeX. I use a Qt-style //! or /*! */ comment and then some TeX formatting in my source code and strip it out later to make my documentation.

    einstein.cpp
    ...
    /*! Einstein's equation
    is $G^{\alpha\beta} = 8\pi T^{\alpha\beta}$.
    */
    for (int i = 0; i != 4; ++i)
    for (int j = 0; j != 4; ++j)
    G[i][j] = 8*pi*T[i][j];

    ...

    The commands
    % simple_doc einstein.cpp > einstein.tex
    % latex einstein
    then produce a typeset version, with C++ code in typewriter font and the tensor equation in beautiful TeX math fonts.

    Lit. prog. might be good for some large, mainly single-author projects such as TeX or Mathematica, but it adds a layer of considerable complexity to your code base, forcing everyone who uses it to learn your system. It will also never make good programmers out of bad ones, and in some ways actually encourages sloppy code by making it easy to write chunks of code without good modular design. As a result, after my current project I'll probably not use a literate programming system again.

    -Michael

  32. Re:lit vs unlit? ;-) by renehollan · · Score: 2
    Ah, but Wolfram is a mathematician, no? Presumably, then he thinks in a way that an expository style would match well to a first cut at code -- I'd bet his comments are merely code for a non-existent programming language in his mind.

    I tend to do this too, when I'm developing, but I use a less precise C++ish pseudo code. It's the best way for me to think about code that will have to be shoehorned and implemented in a particular language that's likely a good implementation fit.

    --
    You could've hired me.
  33. programmers can't write: the fly in the ointment by Xtifr · · Score: 3, Insightful

    There's an old saying (was on a "Murphy's Laws of Computing" poster I used to have): "make it easy for programmers to write in English, and you'll find that programmers can't write in English."

    Others have pointed out the all-too-common case where the code gets edited but the comments don't. This is bad, but not as bad as another common case: the programmer tries to comment the code, but his/her grasp of English isn't up to the task. This may be because English is a second language, or simply because the person specializes in computer languages, not human ones. In any case, the result is frequently misleading or incomprehensible comments that either do no good, or worse than no good. And, of course, deadline pressures never help.

    I think Literate programming is a wonderful idea, but I don't think it's a practical one in many (most?) real-world environments.

  34. Evisa.com bad example by Srin+Tuar · · Score: 2


    Apparently literate programming was not enough to allow the developers of evisa.com to avoid making yet another site that only works with IE 5.5+.


    Unimpressive.

  35. Self Documenting is better by afidel · · Score: 2

    Minimal comments and a language that creats documentation for you is much better. With Eiffel your classes automatically have their public members documented, and with the design by contract model the interaction between classes is obvious.

    --
    There are 4 boxes to use in the defense of liberty: soap, ballot, jury, ammo. Use in that order. Starting now.
    1. Re:Self Documenting is better by Tablizer · · Score: 2

      Minimal comments and a language that creats documentation for you is much better. With Eiffel your classes automatically have their public members documented, and with the design by contract model the interaction between classes is obvious.

      I see it like a newspaper. You can still read and navigate it without the headlines/titles, but it would be tough. If the detail is self-explanatory, that is fine. However, summaries of sections and modules is really nice to have. Just think "newspaper" when commenting.

      Also, "self-commenting" code often ends up with huuuuuge long variable/routine/method names that make code harder to read, at least for me.

      I would rather have a slightly cryptic abbreviation that is described in a comment once in the declaration than a 50-character variable name repeated over and over again, making all the lines wrap and be hard to read.

      A rule of thumb is that the more times a name (var/func/meth) is referenced in the code, the shorter the name should be. IOW, name length should be inversely proportional to its usage frequency.

      Thus, if you reference FormatHTMLInputCell 200 times, then shorten it to something like FmtCell. (Of course, at the function/method declaration a fuller description should be given.)

      I know some will balk at this suggestion, but it works for me. What sinks your boat may not sink mine, and visa versa.

      The logic is that a reader will only have to look up definitions of frequently used names once, but rarely-used stuff can be more self-documenting since it is often easier to read it once than look it up once. And, being infrequent, it does not contribute nearly as much to repetitious bloat that a repeated long name does. IOW, a long name does it job once or twice, but after that just gets in the way by wrapping and hogging eye-space. They are like an alarm clock that just keeps on ringing long after you are already awake.

  36. Every heard of Libero? by randomErr · · Score: 2

    Imatix, the makers of the awsome open source webserver Xitami, has a similar product called 'Libero'. It allows you chart and build your code as you go.

    http://www.imatix.com/html/libero/

    --
    You say things that offend me and I can deal with it. Can you?
  37. Until it becomes out of date by bluGill · · Score: 2

    I am not that old, and I seen several cases of someone cutting as pasting some similear code, comments and all, and then not updating the comments with the minor changes. When the comments references one register, and the code a different one, the comment is useless. Even though the code is similear, you can be sure that something is different, otherwise the two functions would be combined into a different one. But what logically is different between the two? What was missed?

    When the orgional was written 25 years ago in assembly for a different CPU,(previous model, old code will still run) by a guy who is dead, you are in trouble. (I'm thinking of a real case here)

    Great documentation also doesn't help when it covers the wrong thing. I read the documentation for one module I needed to make minor changes in and discoverd nothing about the code, instead I found the rough draft for a book: Advanced tricks with internal OOA process (Don't look on amazon, it never got further, and in any case is just enough specific to that companies old precess that it wouldn't apply elsewhere).

    The problem with documentation is that good documentation rarely exists, not that it is hard to get at. Literate programing sounds good, and it would be if everyone wrote good documentation, but nobody could find it afterwards. Instead nobody writes good documentation, but at least it is in accessable places. (Generally company specific, but most companys do a fairly good job of keeping it)

  38. Re:Oh my, ignorance to a whole new level by Viking+Coder · · Score: 2

    The argument was made that good code is self-documenting. I'm saying that good code only documents its own current behavior.

    What is completely lacking is any indication of what should happen, as soon as the use cases become more complicated.

    The original poster was implying that the code was so perfect, that everyone should shut up and worship it as the end-all, be-all of self-documenting code. I found many, many flaws with the code. If you want to write the perfect version of it, that meets all of my demands, go for it.

    But - every time I add NEW requirements, you'll have to massively modify the code. As the code becomes more and more complex, it will have more opportunities to gain bugs. All this while, though, the documentation might remain constant, if it's written clearly enough.

    *shrug* You're welcome to your opinion, but I'd appreciate it if you wouldn't post as an Anonymous Coward, so I could have a real debate with you.

    --
    Education is the silver bullet.
  39. Re:Literate programming versus continuing developm by Peter+S.+Housel · · Score: 2, Interesting

    In one respect, literate programs are a lot easier to maintain in the long term than illiterate programs because it's much easier to come back to them after a few months away.

    Since Pascal didn't support modules and separate linking, TeX and WEB weren't designed with any sort of reusability in mind. I don't think that there's anything inherent about literate programming that causes inseparable blobs of code like TeX and METAFONT to be produced.

    I generally program so that one document == one reusable library. The Monday Status page contains links to some of the literate libraries written for the Monday Project.

  40. Re:Literate programming versus continuing developm by Tablizer · · Score: 2

    For a project I am working on, I needed to extend CWEB to do some things Knuth hadn't thought of, and I found that excessive cleverness in the data structures made it much more difficult to extend than it should have been, so that Knuth could demonstrate clever data structures that probably add a few percent to the performance over what he could have achieved with more prosaic ones

    Generally, collection management API's should be "wrapped" such that you can change the implementation without changing or reducing change to the application code that uses collection management.

    Whether there is a performance penalty to such wrapping is hard to say. Generally, there will be some performance penalty for the "indirection" needed for hiding implementation.

    For many domains, making the software easier for programmers to maintain is more important than speed. Some programmers get obsessive over speed for no good reason, and make stupid (change-unfriendly) code as a result. They should be embedded systems programmers if they get off on that.

    (BTW, you don't need OOP to wrap collection handlers.)

  41. The creator's view of Leo by edream · · Score: 5, Interesting
    Hi. I am the creator of Leo and I'd like to say here what my own view of Leo is. Joe Orr has contributed greatly to Leo, and I would not characterize Leo exactly as he did in his original article. In this posting I hope to clear up misconceptions about what Leo is, what it can do, and the relationship of Leo to literate programming.

    I would like to distinguish between the techniques of literate programming and the practice of literate programming (LP) as it has always been done before Leo (traditional LP). The key technique of LP is what might be called "functional pseudocode." For example, here is a fragment of code that can be written in Leo:

    def spam():
    done = false ; result = None
    while not done:
    << do something complicated >>
    return result
    The line: << do something complicated >> is a section reference. It works pretty much like a macro call. In particular, the code in the defintion of << do something complicated >> has access to the done and result variables. This is almost the entire content of noweb, one form of literate programming. It turns out that this technique can be extremely useful, as simple as it seems. Leo creates one or more "derived" files from an outline automatically when the outline is written, and Leo can update the outline from changes made to derived files when Leo reads the outline.

    In contrast to the technique of literate programming, the practice of traditional LP has focused on the central role of comments, and lots of them. Here is where Leo radically parts company with the LP tradition.

    One's view of the proper role of documentation in a project hardly matters to Leo. You are free to use comments as you always did, though you will probably find that LP as implemented in Leo helps you out in unexpected ways. I discuss at length and in great detail the relationship between traditional LP, comments and Leo here. In short, discussions about the role of comments in programming (literate or not) do not get to the heart of Leo.

    In fact, Leo often reduces the need for comments. Indeed, it is good style to organize Leo outlines like a reference book. Well-designed Leo outlines act both like self-updating tables of contents and self-updating indices. This is in marked contrast to the "stream-of-consciousness" or "narrative" style typically employed in traditional literate programming.

    In my view, the essence of Leo is this: Leo makes outline organization the most important part of a program or a project. Both code and documentation could be considered secondary. At every moment, the overall big picture of a function, class, module, file or project is always at hand. Moreover, Leo makes outlines structure a part of the computer language. For example, I often define a Python class as follows:

    class myClass:
    << declarations of myClass >>
    @others

    The @others directive acts as a reference to all the text in all the outline nodes which are descendents of the node containing this class declaration. Such nodes are copied to the output (derived) file in the order in which they appear in the outline. The reference << declarations of myClass >> ensures that those declarations precede the methods. There are several other ways that outline structure is important in Leo; I won't discuss them here.

    Leo fully exploits the organizational power of outlines. A single outline typically organizes an entire project. Outlines can handle large amounts of data with ease. Moreover, it is possible to clone any part of an outline so that changes to one clone affect all other clones. This is feature makes it possible for a single outline to contain multiple views of a project. For example, when fixing a bug, I clone all nodes related to the bug and gather them in a new part of the outline, called a task node. This task node effectively becomes a view of the project that focuses exclusively on the bug. Any changes I make to code are propagated to all other clones.

    Earlier I mentioned that a well designed Leo outline acts like self-updating tables of contents and self-updating indices. Tables of contents you get for free: an entire outline is the table of contents. Clones create self-updating indices. For example, each task node acts like the index entry for that particular task.

    - Edward K. Ream

    1. Re:The creator's view of Leo by holon · · Score: 2, Insightful
      I'm a long time outliner (15 years). Began with MaxThink then jumped to Ecco.

      Most people don't 'get' outlining. Most people are what I call linear thinkers. They use MS Word in page layout mode thank you very much, have no need to outlining, and will never understand brainstorming and the power of organization of thoughts thru outlining.

      Same thing with programmers. Most of the programmers here just aren't going to 'get it.' But I do. You're on to something big here. Makes complete sense... an orthogonal view of the physical artifacts of the system. And, the orthogonal view is the most important one - it's the logical view. But, the key that you succeeded with is clones. I'm a long time Ecco Pro user and the same effect is implemented there. It's multiple orthogonal perspectives that makes it truly work. You can shift perspectives, isolate certain elements and create a new perspective.

      I look forward to helping Leo evolve. I see many uses for it beyond a programmer's tool of course - as obviously do you.

      Congrats and right on,

      david bolene...

    2. Re:The creator's view of Leo by slamb · · Score: 2
      Well-designed Leo outlines act both like self-updating tables of contents and self-updating indices. This is in marked contrast to the "stream-of-consciousness" or "narrative" style typically employed in traditional literate programming. [...] At every moment, the overall big picture of a function, class, module, file or project is always at hand.

      Very interesting. You've exactly described one big reason I haven't liked literate programming in the past. I always felt it was too hard to the structure of the code and found a folding text editor to be a better guide. The cweb stuff seemed to completely flatten the structure. For example, when fixing a bug, I clone all nodes related to the bug and gather them in a new part of the outline, called a task node. This task node effectively becomes a view of the project that focuses exclusively on the bug. Any changes I make to code are propagated to all other clones.

      These task nodes seem interesting as well. Seems like they would be good ways to find candidates for refactoring. It would be especially useful if you could tie it to a version control system and/or a bug tracking tool. (I.e., "make a task node of what I changed in this commit. Associate it with this bug report.")

      Recently, though, I've been using API documentation tools (doxygen, javadoc). Generating output in these formats is really important - it's valuable and expected now for Java/C++ code. I probably wouldn't use leo if it interferes with their processing and can't replace it.

  42. Limits of Javadoc by fm6 · · Score: 3, Insightful
    Well, specifying the API before you write is certainly a good idea. But you hardly need Javadoc to do that. The problem with Javadoc -- and all LP tools I've seen is that it confuses documentation with specification. A specification just has to be clear to other working on the project. It can be written by someone with no training in technical communication. The writer doesn't even have to have a full grasp of the language he or her is writing in -- computer terms are pretty universal.

    None of that is true for technical writing. It's a discipline onto itself. It's not just about good writing. (I've known computer scientists who'd written award-winning papers and articles, but couldn't write technical docs worth beans.) It's about understanding your audience and the (often painfully boring) task of writing in the clearest possible language.

    Not every project needs technical writers. If you're a small software shop, and you're building a set of components with an uncomplicated API, and hiring a professional writer isn't cost effective -- then yeah, use Javadoc or some other LP tools.

    But for big projects... Back in 1998, I was in charge of production for the doc set of a large Java framework. Having the API docs embedded in the source code was a nightmare. Javadoc was supposed to allow any of the engineers who wanted to to do their own API docs -- but many botched it, because they didn't understand Javadoc or HTML very well. We had professional writers, but many of them couldn't be trusted with source code. Hell, some of them didn't understand why they couldn't edit the SCCS archives!

    Worst of all was when the release cycle entered code freeze. Document freeze is always later than code freeze -- but you cannot let people modify the release code base during code freeze. The only solution was to split the source, then merge the docs back in after release. Very painful.

  43. The terror of the teletype by Cryogenes · · Score: 2

    still haunts us poor programmers. Backwards compatibility is hard to sacrifice.

    Do you believe in life after death?

  44. Re:Literate programming versus continuing developm by jaoswald · · Score: 3, Interesting

    This is absolutely on the mark.

    I believe that WEB was a great improvement over Pascal at the time that Knuth began to use it. However, it does not solve the underlying software engineering problem. Knuth's style at the time of TeX, etc., involved very little abstraction.

    The biggest problem this causes is that the major data structures in TeX do not have well-defined or factored interfaces that allow them to be easily changed or extended. Furthermore, important details of these data structures are basically undocumented, and often cause interdependencies between different portions of a WEB that are not at all obvious.

    If you wish to see the problem face-to-face, look through TeX: The Program at the "inner loop" and see how many different sections of the WEB that you would have to understand.

    A similar problem is his use of enumerations with certain magic values, where the magic is documented (or becomes apparent, while still undocumented) some distance away from the point of definition.

    Another serious problem with WEB is that it allows one to completely obscure the sequential nature of the program. Many times, one chunk depends on initialization that was performed by another chunk. If Knuth decided to make some laconic comment rather than remind you of that initialization, good luck reconstructing the sequential dependencies.

    If one is writing monolithic programs, writing them like a Russian novel might be easier to comprehend than one large unformatted source file. However, if one has the alternative of writing a highly modular program with clean interfaces, I don't really see any advantage to breaking up and rearranging the underlying code.

  45. It's pointless by Old+Wolf · · Score: 2

    Maybe the reason Literate Programming never took off is because it wastes the time of good developers. I rarely have trouble reading code written by myself or the other developers at my work, and I can even completely rewrite someone else's software and get it almost all right.

    I guess it would be useful for novice programmers who do not know how to write useful comments (that is, 'self-documenting' code, as well as actual comments).

    If I spent the time writing document outlines and program plans and crap beforehand it would be just that, spending time for no reason; not to mention the design changes that often go on as you are actually writing code ; the last thing in the world I want would be to have to go back and change all these plans because I decided to change an aspect of what I was doing.

    1. Re:It's pointless by Stonehand · · Score: 2

      If APIs and system designs were documented first to the point that people agreed upon them, then perhaps you wouldn't have had to make significant design changes later.

      Programmers should not write code, hand it off, and say "it documents itself". Have you read the entire source code for the GNU C Library? Unless you're a developer for it, it's rather unlikely. That's because the writers actually had a clue: they wrote documentation so that you don't have to use the code as a manual. If you're working on projects of any significant size, the same applies.

      --
      Only the dead have seen the end of war.
  46. Re:The perfect documentation... by Stonehand · · Score: 2

    You're ignoring the really important parts:

    - Preconditions.
    - Failure modes -- because you /know/ that with any exported function, it will be given bad input. Even without bad input, I/O failures et al happen. Document what happens.
    - The semantics of each input parameter. Yay, it's really bloody useful to say "blah" is a C-style string. The semantics of it should be in a well-documented API -- in fact, somebody else using your code shouldn't even have to look at its internals.
    - The semantics of each output value.
    - Postconditions.
    - When the function is useful and why.
    - What drawbacks might make the function less useful.
    - Sample calling syntax, including code that shows how the input was obtained.

    --
    Only the dead have seen the end of war.
  47. It's up to the PROGRAMMER by mindriot · · Score: 2

    I suppose the reason why Literate Programming has not caught on is simply that no major programming language forces you to do it.

    Given the right tools within a programming language---say, a documentation tool such as JavaDoc, and some code and commenting conventions---and proper understanding of some software engineering methods concerning the thoughtful design of your software, it is quite possible to achieve what Literate Programming tries to achieve.

    But Java, for example, doesn't require you to build a proper UML model, follow the code conventions, and JavaDoc everything in a way understandable for others. But nobody stops you from using those methods right now. The problem is just that doing Literate Programming---or, for that matter, any kind of proper, thorough documentation---eats up a lot of time, since easily around 50 percent or more of the total time spent on a project are concerned with documentation. And for most programmers, including me, it requires quite some effort to be disciplined enough to do such "proper" software development thoroughly.

    In other words, it might be helpful to use a Literate Programming tool that forces you to document your stuff, but it is still up to you to create a proper design and documentation for your software.

    1. Re:It's up to the PROGRAMMER by jaoswald · · Score: 2

      Any tool that is inflexible enough to force programmers to do things a certain way is not going to be flexible enough to solve every problem that a programmer might face.

      Programmers need more flexible tools, not less. Not that most developers would know what to do when they got them.

  48. Why not document on the interfaces? by Bodrius · · Score: 3, Informative

    I'm not a big fan of abusing Java's interfaces (an interface for each implementation hierarchy), but in a big project that has to be properly documented and strictly specified, this would seem to help.

    The interface is after all closer to the specification level, so your documentation can be strictly about the specification. Then you can let the programmers code, document and freeze the implementation independently from the interfaces.

    Since an interface doesn't have any implementation sourcecode, writers could be trusted with the files, and since the interface API per se is frozen at design, they can keep modifying the Javadocs without affecting the coders.

    If the writers have to modify the API per se and recompile an interface, they are changing the specification (re-design) and of course the coders are forced to adapt their code to those changes.

    But otherwise there would be no need to "split the source" and then "merge". All you would have to do is provide the Javadocs for your interfaces (plus a manual based on this, perhaps) and the Javadocs for your implementation (if implementation details are to be exposed, such as efficiency guarantees, etc).

    If anything, I would think the split would improve documentation.

    --
    Freedom is the freedom to say 2+2=4, everything else follows...
  49. Visual Studio .NET? by Bodrius · · Score: 2

    I may be a bit confused here:

    What exactly is it that you cannot do with your source code in Visual Studio .NET?

    I don't mean that the wisdom of MS has allowed them to put all functionality ever needed in Visual Studio.

    I mean that every time I checked my source code was still there in a flat file, and I could modify it with a text editor, a perl script, or whatever I wanted.

    I haven't seen any repository system from which I have to import/export source code or anything like that. Am I missing something?

    --
    Freedom is the freedom to say 2+2=4, everything else follows...
  50. Debate away... by gregfortune · · Score: 2
    I'm not the anon from above... Regardless, you have your real debate.
    1. "Code should document the program"

      Of course it should. Anywhere that the code does not "document" the program, the progammer needs to provide explicit documentation or write clearer code. That's very very simple if you just consider that the code *is* the program. What documentation could be more correct than the code if you want to know what the program does.

    2. "Documentation should document what a program *should* do."

      Very nice idea, but I've never seen this work in practice. The problem is basically this: You just introduced an entirely different vector under which bugs can occur. These new bugs do not break the program in any visible manner, they just destroy the productivity of a maintenence programmer.

      Example... Client decides to change the behavior of a component of a system after the program has been released. Programmer goes in and changes the code, but never changes the documentation. While making the change, the programmer notices that another requested change will cause the first piece of code to break in a very subtle way if it had not been changed.

      6 months later, another programmer makes some changes and notices that a line of code is clearly not doing what the documentation says it should be doing. Feeling almighty and powerful, he modifies the line so it fits the documentation, thus overwritting the change from 6 months ago and introducing a subtle bug.

      What happened? If documentation is not kept up to date (one more bug vector to worry about), the maintenence programmer will either lose time verifying which is correct or will "fix" a bug that shouldn't be fixed. Neither case is a good thing. Documentation bugs are especially bad because they are so transparent.



    So which is worse? I would warrant that the second is far worse. Any documentation that can be embeded directly into the statements of the language through variable names, function names, language constructs, data structures, etc are a great benefit as they cut down on the number of instances where doc bugs can occur.

    Nonetheless, it's is definitely necessary to document particulary nasty chunks of code, but keep the documentation at the highest level possible. If it is a system overview comment, it belongs in a design doc. If it describes how a black box *should* work, it belongs at the highest level of that box (ie, class or function). If it is a single line genius piece of code, by all means, document it. But be assured that anyone who changes it will probably have a tough time understanding it, will have to read the documentation, and will likely remember to update the documentation out of appreciation if nothing else.

    If this is tough to accept, look at one of your own statements..

    But - every time I add NEW requirements, you'll have to massively modify the code. As the code becomes more and more complex, it will have more opportunities to gain bugs.
    Really? And so as it becomes more complex, it will likely need documentation to describe the additions that are being glued to the side of the original design, right? Oh, right. Maybe it will remain constant? .....

    All this while, though, the documentation might remain constant, if it's written clearly enough.
    Yes, it might. Are you going to remember to check it, especially if it is right *most* of the time...

    So, there you go :) Debate away
    1. Re:Debate away... by Viking+Coder · · Score: 2
      Six times* in your comments, you argue for the existence of documentation beyond the mere existence of the code. In the context of the debate, there were two positions:
      1. Documentation is worthless.
      2. Documentation is valuable.
      I agree that there are many more layers to the debate, but each of the arguments you have made implies the existence of SOME documentation. Can't you see that you're on my side? It's not much of a debate, if you agree with me. =)

      I'm not saying that I have the solution to everything, but I do know one thing for a certainty:

      The worst of all possible solutions is no documentation, at all. (Excluding the consideration of "code as document".)

      I don't believe you disagree with my statement. If you do, feel free to phrase your retort for maximum effect.

      * Here are the six times (with emphasis added) you referenced the existence of documentation, beyond just the code.
      1. Anywhere that the code does not "document" the program, the progammer needs to provide explicit documentation or write clearer code. (Self explanatory case.)
      2. In your second case, you essentially argued the case for a revision control system, with strong documentation, and regression tests. I would argue that, being external to the actual functioning of the code, that regression tests qualify as additional documentation. I particularly feel that regression test code should contain high-level documentation in the form of comments - specifically, when the tests can cite design documents or requirement specifications.
      3. Nonetheless, it's is definitely necessary to document particulary nasty chunks of code, but keep the documentation at the highest level possible. (Again, fairly self-explanatory case.)
      4. If it is a system overview comment, it belongs in a design doc. (A design doc is written primarily not in code.)
      5. If it describes how a black box *should* work, it belongs at the highest level of that box (ie, class or function). (I believe "it" referred to documentation beyond the code.)
      6. If it is a single line genius piece of code, by all means, document it.(Self explanatory.)
      Or did I miss something?
      --
      Education is the silver bullet.
    2. Re:Debate away... by gregfortune · · Score: 2

      I'm not stating either 1 or 2. The posts above are arguing both extremes and I'm leaning towards the idea that the code itself is a damn good documentation tool. I'm also pointing out that no documentation is many times better than incorrect documentation (so no, I do not agree with you). Strong regression testing would most likely catch what you call my second case, but that won't always be true. I will concede that regression tests are probably the most vaulable form of documentation that has been mentioned so far, but again, incorrect documentation (or regression tests here..) are deadly.

      So again, I'm not imply or recommending that we try to get away with *no* documentation. I'm just pointing out that it's in our best interest to allow the code to document as much as absolutely possible.

    3. Re:Debate away... by gregfortune · · Score: 2

      I'm surprised that anyone would attempt to argue the merits of using any computer language as the appropriate mechanism for communicating the intent of an algorithm/function/method.
      Howdy, here's one. Actually, I'll argue the merits if we remove algorithm from that list... The merits from my point of view: Concise, minimized number of changes, "documentation" is always up to date. Now, before anyone gets crazy, I did state in my last post that some documentation is necessary. In particular, high level documentation is a must and documentation of very tricky pieces of code makes it much easier for a maintainer to work with your code. Other documentation just gets in the way or, in extreme cases, misleads the maintainer.

      And I regard algorithm more as a paper thing than a code thing. A function or method is the implementation of that algorithm and if you've put that much thought into a piece of code to justify it as an algorithm, you've probably got some very nifty diagrams and design docs to go along with it. Documenting the implementation is unnecessary unless it deviates from the specified algorithm. "Reference: My cool algo" is probably enough.

      In your scenario, the problem was not simply that the documentation was out of date. If you're operating in a shop where a change can be made in a core component without triggering regression testing, or core components can have their functionality change without revving the API, you need to fix your process.
      That works. So now the code and documentation match, but the regression test fails. Or the code and regression test works, but the documentation says something like, "This should be fixed. Possible risk for thread contention" when in fact, the risk for thread contention has been removed. So which is correct? Regression testing is perhaps the best form of documentation, but it's not quite so "invisible". If a regression test fails, you know it. If documentation is incorrect, you might miss that for months or years.


      In general, I prefer less high-level documentation and more at the class and library level. I know I'd much rather have a well documented class header and methods (with code fragment examples) and a good unit test than having to dive into an implementation and reverse engineer somebody else's code.

      That is high level documentation, isn't it? Design documents are higher level, but not by much. The api documentation is critical and having a separate individual who's responsibility is to maintain api documentation is not too bad an idea (poor, poor soul though....). And as long as the api stays consistent, it's a write once and forget. With a rapidly change api, it's probably more of a burden initially and Leo seems to push for api solidity. I don't know about you, but I'm constently extending and improving the api of my personal libraries as I learn more or need more out of the api. Minimal documentation seems to be a better use of my time than trying to exhaustivly document a changing api.

    4. Re:Debate away... by Viking+Coder · · Score: 2
      I'm just pointing out that it's in our best interest to allow the code to document as much as absolutely possible.

      Absolutely.

      Nothing beats good code. Given that sometimes there is bad code, it would be better if the code contained documentation - that's my position.

      I'm also pointing out that no documentation is many times better than incorrect documentation

      That's an absolute statement which I think you don't really mean. For instance:

      // this algorithm comes from page 293 of the book "Numerical Recipies in C"

      Well, what if the algorithm actually came from page 294? The documentation is incorrect. But even that HINT of the source of an algorithm is SO MUCH BETTER than no documentation at all, that it's killing me that people are disagreeing with me on this point! =)

      I agree, we're both coming awfully close to making absolute statements - to which there are always exceptions. But I'd rather have the hint of the coder's state of mind (even if they do a crappy job of explaining themself), than no hint at all - when faced with code which is provably misbehaving. *shrug* Especially since I can always just keep hitting that "del" key to make their bad comments disappear, but the only thing I can do to make comments appear is figure out the intended behavior of their damned code, and type it in, myself. Which can be pretty tough, sometimes - I've seen some Grade-A Horseshit code, in my day. *shrug*

      --
      Education is the silver bullet.
    5. Re:Debate away... by gregfortune · · Score: 2

      Your example for the documentation is a good one and your closing statements make good sense too. So far, I've been lucky enough to work with some pretty talented developers so minimal documentation is an asset. I guess I'm wishing for ideal situations :)

    6. Re:Debate away... by Viking+Coder · · Score: 2

      Thanks. I wish we were all so lucky. =) I agree, there are situationa when anything beyond minimal documentation just gets in the way. Especially when an API is changing dramatically. *shrug*

      Damnit. Why isn't there a magic bullet that fixes all problems?! =)

      --
      Education is the silver bullet.
  51. Shivver by Srin+Tuar · · Score: 2


    In addition IE is required for the pages that have speech, since that uses MS Agent, and there is no comparable technology for Netscape.


    You used MS-Agent and technology in the same sentence! I can think of a portable systems which provide text-to-speech (festival), and its certainly possibly to provide the page without "speech", or with a few sound clips in ogg or mp3.


    Also, some languages are trivial to text to speech, such as japanese. (trivial as in a perl script and a directory with sound clips could probably doit in real time)


    Well, mostly my problem is that I have no way of getting any version of IE going, and I really wanted to try the language sections, so I am bummed :( If they ould at least allow me to attempt to use it with Moz/linux, maybe I could get a reduced functionality version, rather than being redirected by the cgi.

  52. Re:I think you haven't been in certain jobs yet... by jgerman · · Score: 2
    I don't disagree with you. Well not totally at least. If you can't read code and understand it you shouldn't be writing it (note that that is a general you, not blaming you in particular). I don't need my code with subtitles thanks, I know how to read code and only need commentary in places that might be misinterpreted.


    Your example actually is about a different area of poor coding skills, though it does relate to commenting. Obviously, the poorer the code the more comments that are needed to understand it. For example: If I was non-english speaking and had to take a translator with me to make myself understood. If my command of english is bad, my translator will have to jump in more often and say "he means ...". However, if my command of english is perfect, my translator rarely has to explain my meaning, if at all.


    As far as your rant, the problem is real enough, companies do sell some crappy software I won't deny that. But your implied solution is completely wrong. The idea that "companies should not be allowed" to sell anything no matter what the quality is just nonsense. Nobody has the right to dictate to anyone else what they can or cannot attempt to sell. The fault doesn't lie with the companies selling the software it lies with the consumer who continues to purchase it. It's completely about demand. Consumers have given their approval of companies selling buggy software by their willingness to buy it. The reason that you are on the hook for bugs you weren't responsible for is your fault (or someone higher up who bought the software for your company), not the developer of the software. If you knowingly buy software that a company has attached a 'no warranty' EULA to the responsibility is yours plain and simple. Claiming that they should be illegal is one step away from banishing the GPL.


    Software that could potentially put lives in danger should be thouroughly examined by the people responsible for buying it. Should the government only buy software that is warrantied by the developer, sure. We have to put our faith in the government for our safety. Does this mean it should be illegal for any company to put out no warranty software, hell no.


    When it comes to EULA's I don't feel they should be legally binding when they are legally binding before someone has the chance to read and accept them (sorry UCITA you're a crock of shit), or at least if after purchasing software and reading the EULA the place where you bought the software is legally required to accept a return in you don't agree to the license. It shouldn't be a long drawn out process to contact the manufacturer and have them refund your money.


    As a side note, there or dozens of other problems with EULA's not directly related to this discussion that I have problems with, possibly the most serious being the belief of corporations that they can nullify your rights through them.

    --
    I'm the big fish in the big pond bitch.
  53. funky RAmen by castlan · · Score: 2

    The reason geeks don't like writing too much documentation is simple. It's not laziness (well not always), it's just tedium with human language (or poor speeling and grammer to).

    Project completion includes documentation.

    Professionalism demands it.

    Always.

    Full steam ahead.

    The worst cause of feature creep and software bloat is delineated in your rationalization. The "simple" change should be to your documentation, and then the code should be updated to reflect that change. Note that that change in the spec is usually considered a valid reason for an increase in the revision number.

    The worst thing in the world for a software company (profit motivated) is a moving feature set, and never reaching 1.0.

  54. You are missing the point by ArcSecond · · Score: 2

    Of course the documentation will change. I forgot to mention how important docs are in the process of "change management". It's like war: no battle plan survives the first engagement with the enemy, but that is no reason not to have one. As long as you change the docs to reflect the new features/behaviour, there is no problem with docs "getting out of date" with respect to the code.

    Besides, if you are writing the docs and someone notices a glaring issue, you can resolve it before telling someone to start coding. The earlier, the better. And you WILL do the same changes later in the project anyhow, with a few hundred percent increase in the workload.

    This is why (most) programmers make horrible tech writers: they are too involved in the code to be concerned about issues that affect usability and project management.

    --

    I've got a bad attitude and karma to burn. Go ahead. Mod me down.

  55. Visual Age for Java tools by John+Harrison · · Score: 2
    I've been using VAJ for over three years and once I got used to its quirks I found it to be very powerful and never felt constrained by it.

    If you REALLY need to do something that the IDE isn't capable of then you can write your own tools. VAJ provides a Java API for this and it is really easy to use. You can then make the IDE do anything that you want, as long as you are able to code that behavior in Java. You can also you vi and Emacs to edit your code in VAJ if you really want to.