Slashdot Mirror


Documentation As a Bug-Finding Tool

New submitter Sekrimo writes "This article discusses an interesting advantage to writing documentation. While the author acknowledges that developers often write documentation so that others may better understand their code, he claims documenting can also be a useful way to find bugs before they ever become an issue. Taking the time to write this documentation helps to ensure that you've thought through every aspect of your program fully, and cleared up any issues that may arise."

188 comments

  1. Common knowledge? by O('_')O_Bush · · Score: 4, Insightful

    I thought everyone knew that documentation describes what you intended code to do, rather than what it actually does.

    --
    while(1) attack(People.Sandy);
    1. Re:Common knowledge? by jgrahn · · Score: 4, Insightful

      I thought everyone knew that documentation describes what you intended code to do, rather than what it actually does.

      The documentation tries to document what your intentions are, just like the code tries to implement them. The code can fail to do its job, and of course the documentation can too!

    2. Re:Common knowledge? by icebike · · Score: 5, Insightful

      I thought everyone knew that documentation describes what you intended code to do, rather than what it actually does.

      Just as often, while writing documentation on code I just wrote, I've thrown up my hands, and thought "this is so ridiculous and embarrassing that I can't be associated with it", and I went back and re-wrote it to do it the right way. The act of documenting it revealed you left too much undone, or too many situations un-handled.

      Any time your documentation reads like you are describing a game of twister you just know the code can't be worth documenting, or even keeping.

      But as for finding bugs, I don't know. You may document exactly what you intended, and thought the code did, but still be wrong because of some corner case. Documenting it isn't likely to reveal all of these situations any better than the code itself. A

      --
      Sig Battery depleted. Reverting to safe mode.
    3. Re:Common knowledge? by O('_')O_Bush · · Score: 5, Insightful

      Article summarised: "Thinking about what you write produces better results than not."

      --
      while(1) attack(People.Sandy);
    4. Re:Common knowledge? by ZackSchil · · Score: 4, Interesting

      Just as often, while writing documentation on code I just wrote, I've thrown up my hands, and thought "this is so ridiculous and embarrassing that I can't be associated with it", and I went back and re-wrote it to do it the right way. The act of documenting it revealed you left too much undone, or too many situations un-handled.

      This is by far more common for me as well. I'll find myself describing some really brittle setup process or some common operation that seems to take a thousand steps, get embarrassed over how bad it is, and then go fix the code. More than once, I've written sophisticated automatic parameter selection code because it was easier than finishing the documentation I had started explaining to the user how to set up parameters properly.

    5. Re:Common knowledge? by Anonymous Coward · · Score: 2, Insightful

      Tell that to the PHB that wants the code to ship YESTERDAY--bugs or no bugs!

      To me, proper programming is and exercise in minimalism--get the most work you can out of the simplest and least least amount of code.

      Then comments/documentation isn't so critical.

      But that takes too long and time is money to the average PHB. So you get apps that barely work and must be 'updated' to work better and to be an income stream for the company that put said software out.

      But when you have people DELIBERATELY writing needless, convoluted code in an effort to keep their job because they are the only one who can upgrade it--you have the situation we have to day which is addressed humorously by the The International Obfuscated C Code Contest

    6. Re:Common knowledge? by DaneM · · Score: 1

      Article summarised: "Thinking about what you write produces better results than not."

      Someone mod up parent. :-)

    7. Re:Common knowledge? by Anonymous Coward · · Score: 1

      Some won't follow the coding plan and won't write documentation. We have four software departments and they just walked out 30 people out of 50 across all of them for failure to document and other issues. Six were managers. This happened about 3 months ago. It took them less than two months to fill those positions.

    8. Re:Common knowledge? by Anonymous Coward · · Score: 0

      The problem is more often maintaining good documentation. Sometimes code and documentation disagree but code is actually right because documentation was not updated when changes were implemented.

      Having tests as documentation is much better: you should have them anyway and if you change what the code does you are forced to update the tests (and confirm the new behavior).

    9. Re:Common knowledge? by Anonymous Coward · · Score: 0

      Sounds like good business at work, assuming the new hirees have proven they'll do a better job documenting?

    10. Re:Common knowledge? by AuMatar · · Score: 3, Insightful

      If you really filled 30 positions in 2 months, your problem is likely in hiring shitty programmers. A most companies I've worked at, we made offers to 10-20% of the people who interviewed. Unless you're doing 5+ candidates a day, and all offers are accepting, you're murdering that rate. Some of that may be better offers or more efficiency, but it sounds like you're hiring a lot of mediocre people to fill seats.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    11. Re:Common knowledge? by TheRaven64 · · Score: 4, Interesting
      There's a very old saying:

      If the code and documentation disagree, then they're both wrong

      The documentation itself is probably not the important bit. The thing that a lot of programmers seem to do wrong is getting the correct ordering of the thinking and coding steps mixed up. Writing documentation first means that you have to do the thinking before the coding, and that eliminates a whole load of problems.

      --
      I am TheRaven on Soylent News
    12. Re:Common knowledge? by julesh · · Score: 1

      But as for finding bugs, I don't know. You may document exactly what you intended, and thought the code did, but still be wrong because of some corner case. Documenting it isn't likely to reveal all of these situations any better than the code itself.

      Handling corner cases is accomplished by identifying what they are and specifically implementing code to handle them when necessary. In order to identify them, we must think about what the code is doing. As programmers, there are three times we do this:

      - When writing the code
      - When testing the code
      - When writing the documentation

      It happens that we tend to pick up different corner cases in each case. This happens because different corner cases require different ways of thinking to identify them, and while performing these three activities we tend to be thinking in different ways (logically, spatially, and verbally, as a rough approximation). So, yes, I think coding and documenting is likely to reveal corner cases better than coding alone, particularly if we leave a few days between coding and documenting (thus allowing us to forget how we were thinking about the code at the time we wrote it, and get more into the verbal method of thinking about the problem).

    13. Re:Common knowledge? by olau · · Score: 1

      Agreed. That's why, if you writing a library, it's a really good idea you write some documentation before others start depending on the API.

    14. Re:Common knowledge? by Anonymous Coward · · Score: 2, Funny

      Kudos to you if you can refactor the implementation in your head before you write it!

    15. Re:Common knowledge? by sourcerror · · Score: 1

      This might work if you're writing a new webshop. If you're doing something innovative it won't work.

    16. Re:Common knowledge? by St.Creed · · Score: 2

      Interesting sidestep: consider Literate Programming (http://en.wikipedia.org/wiki/Literate_programming). Donald E. Knuth advocates the approach of document, AND code, then compile the documented code. I have always been fond of this and try to use this in all my programming.

      Just comment preconditions, postconditions and mock up the pseudo-code, then extend it.

      I'd absolutely love it if Eclipse and Visual Studio supported this. However, most people don't know Literate programming so I doubt it's going to be in there anytime soon.

      --
      Therefore, by the (faulty) logic you're using, you're just a cow with a keyboard - osu-neko (2604)
    17. Re:Common knowledge? by Beryllium+Sphere(tm) · · Score: 1

      Can we moderate this above +5? There's no need for any other comments after that one.

    18. Re:Common knowledge? by RonBurk · · Score: 1
      No. Wrong. Completely wrong. Completely misses the point.

      Writing is a quite different cognitive activity than "thinking". Writing about things provides distance and helps overcome the limitations of working memory that can prevent you from seeing the same problem by just "thinking". Writing documentation produces very different results than just thinking about the code.

    19. Re:Common knowledge? by DrLang21 · · Score: 1

      As the adage goes where I work, if you want software really bad, you'll get really bad software.

      --
      I see the glass as full with a FoS of 2.
    20. Re:Common knowledge? by SimonInOz · · Score: 4, Interesting

      When I was involved in writing one of the first packet switching systems in Europe (AT&T, Belgium, 1979), we found a brilliant way to fix bugs was to explain the bug (and thus the operation of the program) to someone. They didn't have to do much, just nod and look interested.
      Then usually about halfway though, the hapless coder (eg me) would go "Oh shit" ... and the listener cold then leave.
      We called it the "tailors dummy" approach to debugging.

      A bit like pair programming, only less labour intensive.

      --
      "Cats like plain crisps"
    21. Re:Common knowledge? by mickwd · · Score: 3, Insightful

      So let's get this straight: you just sacked 60% of your developers for not following certain rules?

      That 60% of your developers had properly been informed that certain rules were important enough to follow that breaking them would probably mean dismissal, and then went ahead and broke them anyway?

      That there was no process in place of informal verbal warnings / formal verbal warnings / formal written warnings that could have been followed before sackings?

      That this wasn't discovered before it was widespread enough that it became necessary to sack 60% of your developers?

      That you have decided you'll be more productive in future with only 40% of your new development workforce having any experience of your software whatsoever?

      Your company has BIG problems.

    22. Re:Common knowledge? by rtfa-troll · · Score: 1

      The documentation tries to document what your intentions are, just like the code tries to implement them. The code can fail to do its job, and of course the documentation can too!

      This is 4/insightful? On the scale of today's article that's probably right too but if you look at the history of this stuff it should be 1/redundant. We seem to be continually rediscovering the computer science of the 60s. I mean, how can we be discussing this without even mentioning literate programming a 1970s answer to the problems which you get when you start to use documentation for code maintenance?

      I mean, some poor guy writes a blog spreading wisdom to himself and his five friends who are just discovering about how to lead programming teams (there's nothing wrong with that; one of his friends should just point him to some of the literate programming discussions and some of the rants of Linus Torvalds against over-documentation, for example). What's wrong is when it gets plastered on the front of Slashdot and we take it seriously.

      What's next? Rediscovering that it's a good idea to test things in a separate environment before deploying them in the real world?

      --
      =~ s,(.*),<sarcasm>$1</sarcasm>,g if any_point_you_wish();
    23. Re:Common knowledge? by __aaltlg1547 · · Score: 1

      That's true. But the process of writing it down is often the first time that a coder thinks of what the code is supposed to do. If code comes without documentation the programmer might not have thought about what the code is supposed to do at all.

      That's why some of us were taught to write the interface documentation before starting on the code.

    24. Re:Common knowledge? by jgrahn · · Score: 1

      No. Wrong. Completely wrong. Completely misses the point.

      Writing is a quite different cognitive activity than "thinking". Writing about things provides distance and helps overcome the limitations of working memory that can prevent you from seeing the same problem by just "thinking". Writing documentation produces very different results than just thinking about the code.

      Then how about this? Writing (different kinds of) documentation forces you to think in different ways. *Forces* as in you can't cop out mid-sentence without noticing.

    25. Re:Common knowledge? by Mr+Z · · Score: 1

      I love Literate Programming in theory. In practice, I find the source code of a Literate program ugly. I'm not sure a WYSIWYG would help. I believe the concept is a good concept, and what holds it back is the lack of a modern realization of the concept that makes the LP easier to follow and easier on the eyes.

      There's no question of Donald Knuth's genius. If there's anyone who has ever threatened to exceed the Shannon limit for information density, it's him. But, aesthetically, the source of a Literate Program and the compiled result lay on direct opposite ends of the "beauty" spectrum. For LP to really catch on, the source needs to be a little more readable, IMHO.

    26. Re:Common knowledge? by Mr+Z · · Score: 1

      Pretty much. And, while he was going on about subtle concurrency errors, did anyone notice just how awful his sliding window filter actually was?

      The code was simple enough, sure, but you could have gone much faster if you kept a running total in the class itself. And, instead of sliding the whole array over by one, just replace the element at array[idx % SIZE]. (You'd have to add a persistent index to the class too.) Those two changes would speed up the code by a factor of N, where N is the length of the window, by eliminating two loops over the arrays.

    27. Re:Common knowledge? by NotSoHeavyD3 · · Score: 1

      To me, proper programming is and exercise in minimalism--get the most work you can out of the simplest and least least amount of code.

      You're really on to something there but there's at least one other part to this minimalism. You shouldn't be asked to implement stuff nobody is going to use. (A little different than your last sentence.) I mean at multiple companies I've been asked to implement something that either I realized at the time or found out later nobody actually used.(Or worse would actually be dangerous to implement) What's annoying is that either a PHB or "Person who thinks they're a project manager" decides we absolutely have to have feature X. Then somehow, someway I find out a year or 2 later hey way do you know, literally nobody has used this feature even once after it got out of testing. (I've tried pointing out in some cases that this isn't really necessary and the company is wasting their money having me implement this. Fortunately I'm pretty good at not getting stuck doing free overtime doing this feature and also doing the stuff that actually needs to be implemented) I guess I just find it annoying to give my opinion, have it ignored, and turn out to be right. (But I've been trying to get better since I give my opinion once, if you ignore it it'll cost you money, not me.)

      --
      Did you know 80 to 90% of the moderators on slashdot wouldn't recognize a troll even if one dragged them under a bridge.
    28. Re:Common knowledge? by St.Creed · · Score: 1

      I love Literate Programming in theory. In practice, I find the source code of a Literate program ugly. I'm not sure a WYSIWYG would help. I believe the concept is a good concept, and what holds it back is the lack of a modern realization of the concept that makes the LP easier to follow and easier on the eyes.

      True. If I was working for Microsoft Research, I think this would be a nice start for a research proposal. As it is, I can only dream :)

      --
      Therefore, by the (faulty) logic you're using, you're just a cow with a keyboard - osu-neko (2604)
    29. Re:Common knowledge? by gbjbaanb · · Score: 2

      rubbish. At no point in any development process does thinking not enter the equation.

      If you're doing something innovative, you'll be spending much more time thinking - re Edison's "genius is 1% inspiration, 99% perspiration" comment. He knew what innovation was!

      Too many developers I know think that you can slap something together (calling it 'being creative' or 'innovative') and fail to do a professional job which ends up requiring massive amounts of maintenance, if it works properly at all. Those who really do good job think first, write down their ideas so they won't forget them, develop them, then write down the results so others can use them.

    30. Re:Common knowledge? by Anonymous Coward · · Score: 0

      Wrong; before you can get your thoughts into a terminal coherently you must be able to verbalize them, and therefore communicate them to others. You are so laughably far from the mark.

    31. Re:Common knowledge? by sourcerror · · Score: 1

      My point is that if you're solving a hard problem that doesn't have a widely accepted solution, than it's better to document the thing when you'got something to show for.

    32. Re:Common knowledge? by Glonoinha · · Score: 2

      I read this as 'When I don't know what I'm doing, I hack at it until I get something working and then I document what I did.' Fair enough. At that point you are documenting it at a fairly detailed level (hopefully). This happens when software development is done as 'Art'.
      When software development is happening as 'Science', odds are you can at least outline your intent and design before you start coding the solution.

      I've done both. Computer Science usually produces better results than Computer Art.

      --
      Glonoinha the MebiByte Slayer
    33. Re:Common knowledge? by turbidostato · · Score: 1

      "Handling corner cases is accomplished by identifying what they are and specifically implementing code to handle them when necessary."

      For the most part, corner cases are bad algorithms.

    34. Re:Common knowledge? by WillAdams · · Score: 1

      ::applause::

      I've found Literate Programming to be a huge benefit when developing, esp. since I often work on projects intermittently (submit version, then test, then deploy, then months later get a feature request from a customer) --- it's a brief bit of reading to re-aquaint myself w/ the code.

      It also fascinating to me how the act of writing out the documentation then makes it obvious how the code should be written.

      William

      --
      Sphinx of black quartz, judge my vow.
    35. Re:Common knowledge? by kmoser · · Score: 1

      Clearly nobody wrote a functional spec in advance to document the requirement for new programmers. When the company finally discovered the buggy programmers, they wisely decided it was better to factor them out late than never.

    36. Re:Common knowledge? by Anonymous Coward · · Score: 0

      "It took them less than two months to fill those positions." sounds quite weird.
      "Pan for gold in a river" approach (employ a lot, fire a lot) doesn't work.
      But I find no reason they need to keep useless employees. A company is not a school.

  2. Better than customer service by kawabago · · Score: 2

    as a bug finding tool. Lots of unhappy customers that way.

  3. False by Anonymous Coward · · Score: 0

    "Taking the time to write this documentation helps to ensure that you've thought through every aspect of your program fully, and cleared up any issues that may arise."

    Not true.

    1. Re:False by icebike · · Score: 4, Insightful

      For some methods of documentation this is very true. For some programmers that care about their work its very true.

      But if you don't care about your code, you probably won't care about the documentation. In this case, I agree its False.

      If you know the documentation you just wrote is a bag of lies but you turn it in anyway, because you know that the PHB won't understand it and couldn't check if it was true if his life depended on it, then you might as well junk the code you just wrote as well. Chance are it will break the minute you walk out the door.

      --
      Sig Battery depleted. Reverting to safe mode.
    2. Re:False by David+Gerard · · Score: 2
      --
      http://rocknerd.co.uk
    3. Re:False by David+Gerard · · Score: 1

      I must point out that I will never apply that link in practice ... having had a friend end up working somewhere I'd worked four years previously and discover my name in the documentation. Always leave the documentation in the form you'd like to have found before you did whatever it was.

      --
      http://rocknerd.co.uk
    4. Re:False by expatriot · · Score: 1

      In the article someone commented on the difference between business needs and developer needs. This is why I favour doc generating systems like doxygen.

      Part of the problem might be brain organisation, some people think very spatially and words get in the way. The code and fix as fast as you can does work if you are good, lucky, or fast. If so you probably do not want to doc every iteration.

    5. Re:False by St.Creed · · Score: 1

      I once got hired back to a place I worked for 3 years before that, and had to answer questions about the code I designed when I worked there before... fortunately I always document at least the basics diligently but it still made for some sweaty moments. So yeah, it could be your friend. But it could also be you after 3 or more years :)

      --
      Therefore, by the (faulty) logic you're using, you're just a cow with a keyboard - osu-neko (2604)
    6. Re:False by David+Gerard · · Score: 1

      Oh, it's often me. I frequently find myself cursing my past self's stupidity. That guy was a dick.

      --
      http://rocknerd.co.uk
  4. Indeed by bazald · · Score: 2

    Explaining your work is a great way to demonstrate that you actually understand it. As the article illustrates, perhaps the most critical part is going back and verifying that the code matches the explanation.

    --
    Insert self-referential sig here.
    1. Re:Indeed by paimin · · Score: 2

      This is news? Wow, the human race is going downhill.

      --
      Facebook is the new AOL
    2. Re:Indeed by grcumb · · Score: 3, Informative

      Explaining your work is a great way to demonstrate that you actually understand it.

      My standard development process is:

      1. Document the method;
      2. Write the tests for the method;
      3. Write the code for the method;
      4. Make corrections to each until everything works;
      5. Move on to the next method.

      My rationale is precisely that: I'm not really sure I know what I'm doing until I've described it, then figured out how my idea might fail.

      Forgive my ignorance, but doesn't everyone do this?

      --
      Crumb's Corollary: Never bring a knife to a bun fight.
    3. Re:Indeed by Jens+Egon · · Score: 1

      Stuff that matters, surely. Certainly not news.

    4. Re:Indeed by purpledinoz · · Score: 3, Interesting

      I think most people to this:

      Write method.
      Write unit tests.
      Fix until it works.
      Write documentation.

      I generally find that code documentation is a lot better if the document first approach is used. In the above approach, the method is done, and the documentation becomes a chore.

    5. Re:Indeed by Jah-Wren+Ryel · · Score: 2

      Forgive my ignorance, but doesn't everyone do this?

      Yep, pretty much every one does do that.
      Where they tend to differ is in their particular definitions of "do."

      --
      When information is power, privacy is freedom.
    6. Re:Indeed by Anonymous Coward · · Score: 0

      I don't. I'm a pretty intuitive sort of programmer -- probably not ideal, but it's who I am -- and it is very difficult for me to write tests or documentation before I write code. My intuition works well on the level of code, but not on the level of tests or documentation. For me test writing usually involves me thinking about the major use cases of a particular (mostly finished) piece of code, and also what I could do to break it. I implement tests based on what I come up with. Code documentation I sometimes add as a I go, sometimes add after I'm finished (generally simple code gets on the fly documentation complex code does not). User level/ API documentation gets written when everything else is done.
      Again, I don't say that this is the ideal process, but, for me, it does work reasonably well -- and much better than the method you describe.

    7. Re:Indeed by Anonymous Coward · · Score: 0

      I am more of a holistic type of programmer/designer. I think about what I have to make for quite a long time, scribble down some schematics, think about it more. I mostly design all my stuff in the shower in the mornings. You could say I am doing test-driven development in my head.

      Then, when I thought of how to make the program as simple as possible with many ways to expand on it later, I start programming it immediately. When I am done with writing some functions I start to see if I can make the implementation of each function better. Possibly I split the function up in separate functions until my code becomes mostly self documenting, and I can share the most amount of code. I write my function headers after this process since during it everything is still very much in flux.

      Most of the times I do not put comments inside the function, except when I write low-level code, especially with wait-free code it is important that people don't mess with the order and type of intrinsics in those function, even if it looks like one can optimize it.

      I read a great comment on slashdot recently: "in code comments: don't explain what you are doing, explain why you are doing it."

      I only make unit tests if a function has failed, in an attempt to debug the code. Then when I have fixed the code, I actually have a regression test as well. This way the number of unit tests grows and it will cover actual real world situations. On the other hand I don't often write code that needs to be perfect in one go either, I rather have it working quick than be perfect :-)

      At home right now I have a large project where I am reinventing literate programming, the Knuth version went way to far in it. I have not gotten too far yet, I write my documentation and some code in straight HTML. Then I used attributes of tags to tell the code generator what to do with it. For example I have tables with constants in it, which are converted into constants/enumerations code files for languages like C and Python. Or I describe a database table which are converted into DDL SQL. HTML is great for this, simple to parse (I use XHTML), nicely nested, expandable with attribute. This way documentation and code keeps in sync, like the reverse of Doxygen, I call it Noxygen.

    8. Re:Indeed by OddJobBob · · Score: 1

      The process I have seen followed by the most senior developer in my last company was more like:
      Write code
      Don't write tests
      Don't put a label on the trunk
      Commit hundreds of files to the trunk
      Write specification
      Write requirements
      Run out of budget
      Trunk now abandoned for other projects

      He did work "at a higher level to all of you" so what did we to know!

    9. Re:Indeed by boaworm · · Score: 1

      Explaining your work is a great way to demonstrate that you actually understand it. As the article illustrates, perhaps the most critical part is going back and verifying that the code matches the explanation.

      Explaining your work by writing it down is fine, but if noone reads what you have written, it isn't as useful anymore. Hence, it is not the documentation part but rather the reviewing part that helps. Hence, what really does the job is code reviewing, rather than documentation. If you document it before reviewing, thats even better.

      The key thing here is that the person who wrote the code isn't likely to find bugs in it, as that person "knows" how the code works. The important thing is to make someone else look through it, or at least have the author explain it to someone else. Most coders will for sure have experienced the as-soon-as-i-explained-it-to-my-college-i-found-the-bug-phenomena.

      --
      Probable impossibilities are to be preferred to improbable possibilities.
      Aristotele
    10. Re:Indeed by Anonymous Coward · · Score: 0

      Forgive my ignorance, but doesn't everyone do this?

      No, the boss says "All You Have To Do Is..." and "Git 'er Dun!", and "By the way, we also need this other stuff", and you hack something out, run a few hasty tests, then dump it into production.

      The users complain it's crap, but try and get a decent budget for a decent effort. Especially since they've been told that Offshore Corporation X can do it in half the time and 1/4 the price.

    11. Re:Indeed by Tom · · Score: 1

      Forgive my ignorance, but doesn't everyone do this?

      No.

      I start with code, because I think in code. Writing out a couple lines of pseudocode explains much clearer to me what I intend to do. Then I add comments to explain why I am doing things and then I flesh out the code from pseudo- to real code.

      People think differently.

      --
      Assorted stuff I do sometimes: Lemuria.org
    12. Re:Indeed by jgrahn · · Score: 1

      Explaining your work is a great way to demonstrate that you actually understand it.

      My standard development process is: [unit-test each function before writing the next one] My rationale is precisely that: I'm not really sure I know what I'm doing until I've described it, then figured out how my idea might fail.

      Forgive my ignorance, but doesn't everyone do this?

      Writing unit tests (code) is not the same thing as writing prose. I find it doesn't trigger the same thought processes at all. For one thing, doing it like you describe, you lose focus on anything bigger than the function: the classes and the cooperating groups of classes.

    13. Re:Indeed by Mr+Z · · Score: 1

      For many (but not all) things, I try to write the documentation first, starting at a high level and drilling down. In fact, I've been known to mock up several prototypes of tough problems solely in English. It really does force me to think out the architecture. It doesn't, however, prevent magical thinking about how the low-level implementation will actually work out, and so isn't foolproof. Quite often, though, I'm able to skeleton-out my code in comments first, and then hanging the actual code off the comments is fairly trivial.

      For some things, though, it's easier to explain in code than in English. This tends to be true with certain kinds of low-level fiddly stuff. There, it seems best to just state the high level goal in English, and then demonstrate it in code (or at least pseudo-code). English can be horribly imprecise for algorithms, and sometimes you just need a precise algorithm description to capture a set of actions. The ratio of English to code/pseudo-code then necessarily drops.

      But all that's just me. Most people I work with code first, and (if they're good) document minimally once it works.

    14. Re:Indeed by Capt.Albatross · · Score: 1

      Explaining your work by writing it down is fine, but if noone reads what you have written, it isn't as useful anymore. Hence, it is not the documentation part but rather the reviewing part that helps.

      My experience is that when I write out an argument, I quite often notice weaknesses, incompleteness or outright errors that had not occurred to me before, so writing it down is very useful even if no-one else reads it. This is particularly true for nontrivial arguments that have several cases, lemmas etc. Based on what I have seen of other peoples' work, there are quite a few people for who this is so. In short, writing it down forces you to review and allows you to handle complexity.

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

      Why? You have to know what the code is supposed to do ahead of time in order to work this way. If you already know what the code is supposed to do, it's not an interesting problem to solve. The stuff I write is new - not one has the foggiest idea what they want, and even if they do, it's usually not really what they want. The result is an iterative process, and the output is usually something that solves the problem, but isn't optimal, elegant, or even understandable. Sure, you can go back and rewrite it, if anyone cares - usually they don't and it's on to the next new thing.

    16. Re:Indeed by gbjbaanb · · Score: 1

      I think most people do:

      hack some code together
      hack some more code on top
      hack in some fixes
      tell everyone what l33t haxors they are 'cos they're so productive having written lots and lots of code.

    17. Re:Indeed by Anonymous Coward · · Score: 0

      "My intuition works well on the level of code, but not on the level of tests or documentation."

      Tests and even documentation are code too. Your intuition is wrong.

      "User level/ API documentation gets written when everything else is done."

      And so, it's usually not properly done because lack of time and forgetness.

      You look like the average programer to me.

    18. Re:Indeed by Anonymous Coward · · Score: 0

      I do the same as you, except with more steps...

      Document the method;
      Write the tests for the method;
      Write the code for the method * Including executable documentation - assertions testing the preconditions and post conditions and other assumptions of the method, and testing the invariant conditions of the class.
      Make corrections to each until everything works;
      * Refactor until the documentation is made redundant;
      * Add enough tests to make the documentation redundant;
      * Delete the documentation if it isn't specifically intended to be part of API documentation for people who do not have access to the source code;
      Move on to the next method.

  5. I'd believe it... by tecker · · Score: 1

    I have caught a number of problems documenting my code. When you describe what it is supposed to do and you realize that it really doesn't do that then you can correct as such. I would say I have found more incorrect behavior rather then show stopping bugs. However if we had shipped the product with the code the way it was we would have probably called it a bug so it is probably the same either way.

    --
    Procrastinating life a way at a rapid rate of speed.
  6. IS0 9000? by jayveekay · · Score: 4, Insightful

    Say what you do.
    Do what you say.

    The documentation becomes an error check on the code and vice-versa. If the 2 disagree, something needs to be fixed.

    1. Re:IS0 9000? by Coryoth · · Score: 1

      If you are trying to save time you can always use a DbC system for some of your "documentation" of what the function is intended to do and have that become an actual error check on your code. You can even use the contracts to automatically generate unit tests for you. It's also harder for documentation to fall out of sync with code since it is part of the testing and flags an error if it isn't kept up to date.

    2. Re:IS0 9000? by Anonymous Coward · · Score: 0

      Indeed. In real life if documentation and code disagree they really just become a source of confusion. DbC makes executable documentation that tells you right away if anything is out of sync, and tells you why.

  7. Plato? by Anonymous Coward · · Score: 0

    What TFA suggests is not new. But it astounds me how close this is to what Plato was saying 2500 years ago.

  8. This by Anonymous Coward · · Score: 1

    We use a commercial mail processing application.
    The documentation stated that the feature works 'this' way.
    Which was to route mail to and from third party applications.
    It only partially did this, it wouldn't route it back from the application. Understand they they also integrate a optional licensed virus processing feature.
    We contacted the company, and they said it worked 'that' way. 'That' way was far less usefull or functional.
    We pointed to the documentation and they corrected the problem.

  9. Reality Sucks by Anonymous Coward · · Score: 0

    In my utopian world, the code is well documented and thought out. In the mutli-million dollar/SLOC world, it is a mountain dew/provigil fueled race to the finish line and payday. As schedule, cost and requirements slide in the middle of a project, the documentation is often left in the dust while we scramble to successfully compile our deliverable.

    For debug, depending on the system requirements, the test software has even less documentation than the original software.

  10. Documentation and Planning by Anonymous Coward · · Score: 0

    Please don't confuse documentation with actual planning. If you think documenting your code is helping to prevent bugs then you're most likely not doing your planning properly. There's a reason we do DFDs, function models and interaction, behaviour and structure diagrams. Use a better development methodology.

  11. I'd fire that guy if he was on my team by Anonymous Coward · · Score: 0

    Writing documentation after writing the code shows that he doesn't exercise TDD, either.

    1. Re:I'd fire that guy if he was on my team by julesh · · Score: 1

      Writing documentation after writing the code shows that he doesn't exercise TDD, either.

      He could be writing *extra* documentation. Not everyone is happy with the idea that tests are documentation.

  12. Documentation IS NOT a Bug-Finding Tool by Anonymous Coward · · Score: 0

    The only reason you find bugs when writing documentation is because you are creating a duplicate set of logic in a different format which should match your source code logic. You would get the same exact result if you wrote the same application in another language, say C# for instance. It's amazing the bugs for find when you verify your logic in multiple formats.

  13. Someone teach this guy about circular buffers STAT by Anonymous Coward · · Score: 0

    FTFA:

    public void doA(int num) {
            for(int i = 0; i < array.length - 1; i++) {
                    array[i] = array[i+1];
            }
            array[array.length - 1] = num;
    }
    public float getB() {
            float total = 0;
            for(int num : array) {
                    total += num;
            }
            return total / array.length;
    }

    There's no excuse for copying array.length - 1 items on every update. Someone teach this guy about circular buffers, STAT. Then maybe he'll have something worthwhile to blog about.

  14. Wouldn't hire him.. by Anonymous Coward · · Score: 0

    His examples seem to be based on having documentation help poor design. Knowing what you feed to your methods is a basis for programming. If you can't trust that (external interface), be ready to catch the exceptions.

    He also forgot the bit about testing; if you're writing stuff up without a design, try at least to write some testcases so that you can verify classes to work individually. Rather than piling them up like a card house..

  15. Good code by pwnyxpress · · Score: 2

    If your code is good, it should be self documenting. Everyone knows what the variables 'foo' and 'bar' do.

  16. So, someone rediscovered Literate Programming? by Elf+Sternberg · · Score: 3, Informative

    Oh, come on, Literate Programming has been around for 30 years! Knuth made exactly this argument in his 1984 essay entitled, surprisingly enough, "Literate Programming!" Wikipedia asserts in it "Literate Programming" entry: "According to Knuth, literate programming provides for higher-quality programs, since it forces programmers to explicitly state the thoughts behind the program, making poorly thought-out design decisions more obvious. Knuth also claims that literate programming provides a first-rate documentation system, which is not an add-on, but is grown naturally in the process of exposition of one's thoughts during a program creation. The resulting documentation allows authors to restart their own thought processes at any later time, and allows other programmers to understand the construction of the program more easily."

    Congratulations to Slashdot for posting about some kid rediscovering an ancient technology by a revered master of the craft. What's next? "Snot-nosed highschooler discovers GOTO is a bad idea?"

    --
    If you're so smart, why aren't you naked?
    1. Re:So, someone rediscovered Literate Programming? by julesh · · Score: 1

      Actually, he's talking about something entirely different to literate programming. LP advocates writing a single document that contains both documentation and code, whereas what this guy's actually advocating is basically finding a reason to take a second pass at looking at the code, which is what happens when you document it separately. You'd get the same benefit from, for example, having a policy of self-reviewing code after completion, or in TDD the refactor phase of the red-green-refactor cycle.

    2. Re:So, someone rediscovered Literate Programming? by St.Creed · · Score: 1

      You're right. Knuth is still much more advanced than this writer.

      --
      Therefore, by the (faulty) logic you're using, you're just a cow with a keyboard - osu-neko (2604)
  17. Re:Someone teach this guy about circular buffers S by commlinx · · Score: 1

    Plus he mentions concurrency and the confusion it may cause for other developers re-using the code, but doesn't address the obvious divide by zero that will occur if getB is called first even in a single-threaded application.

  18. Peer Review by Anonymous Coward · · Score: 0

    Peer reviewing all code before it goes into the main repository also does the same thing. And the upside is you don't need to waste any time writing documentation!

  19. I must be in bizarro world.. by Anonymous Coward · · Score: 0

    My life must just abnormally suck, I guess. I have no time for documentation. I barely have time to get code that mostly works done before I have to move on to some hot bugix, or I have to move on to deliver some feature the customer needs 2 weeks ago.

    I always longingly read people talking about test driven development, or code contracts, or good code documentation. I mean I love all that shit. Sure would be nice if I could do it in the real world.

    Either I have an extraordinarily shitty job or some people just have dream jobs where they have time to write this mystical "quality code" with documentation, tests, etc...

    Either way, if you have time for that shit I fucking hate you.

    1. Re:I must be in bizarro world.. by Anonymous Coward · · Score: 0

      Change job. Go to some small company where there is less than 12 people total. If you like what you see when you first speak with owner and other employees, this tends to be a good job. I had been in the same situation, now I've changed jobs and it's better pay, work atmosphere and more interesting projects.

    2. Re:I must be in bizarro world.. by St.Creed · · Score: 2

      I understand, but at least do this:
      - keep a change log. Even when I'm under extreme pressure I write down at least what the customer wants, and what I'm going to do about it. What did I change where.
      - keep a decision log. Every time you have to interpret a request or design spec in a certain way, write it down.

      Over time, these will keep you afloat.

      --
      Therefore, by the (faulty) logic you're using, you're just a cow with a keyboard - osu-neko (2604)
    3. Re:I must be in bizarro world.. by turbidostato · · Score: 1

      "My life must just abnormally suck, I guess. I have no time for documentation."

      No. Your problem is that you don't *want* to document and so you find lame excuses not to do it.

      Unless your company is really as bizarre as you want us to believe, things don't get implemented twice just in case, so there's no other way but your manager to take your word for how much it takes to deliver any piece of work assigned to you.

      Then the only thing you have to worry about is that the very last thing you do is to add that last syntax sugar the code needs to run.

      An example:
      Step 1:
      # A hello world script
      Step 2:
      # A hello world script
      echo "Hello, World!"

      See? Done this way it always gets documented. What you say you would want to do:
      Step 1:
      echo "Hello, World!"
      Step 2:
      # A hello world script
      echo "Hello, World!"

      Of course, you never reach to step two. Of course too, you don't really want to reach to step two.

  20. This is why I comment code last. by Anonymous Coward · · Score: 1

    This is why I got into the habit of not commenting code as I was writing it. I always saved the documentation as the last step before getting it ready for code reviews or committing it to version control. By documenting last you don't waste time writing documentation that may end up getting deleted because you decided on a different solution, doesn't get out of sync with what the code is actually doing, and it serves as a forced code review for yourself.

  21. Documemtation Priority by PolygamousRanchKid+ · · Score: 4, Insightful

    Manager, at the beginning of a project: "Forget the documentation! Just get it to run!"

    Manager, at the end of a project: "Where's the documentation! You were lazy, and didn't write any!"

    Documentation is at the ass-end of a project. The Manager's Manager wants to see something running. He doesn't accept paper as a currency. So documentation will always get low priority. And that ass-end will be hanging out and swinging in the breeze.

    Someone could do a scientific study that proves that documentation cures cancer.

    It will still get low priority in a software development project.

    --
    Schroedinger's Brexit: The UK is both in and out of the EU at the same time!
    1. Re:Documemtation Priority by Patch86 · · Score: 1

      There are two types of manager (and indeed two types of company) out there. The kind you describe, where everything needs to be done yesterday, damn the protocol, is one kind. Ones where everyone sticks dogmatically to bureaucracy and obsesses with "project gateways" is the other.

      When you're stuck with the former, the common reaction is "for god's sake, if they won't let me follow procedure properly the code won't be any good at all!". The reaction to the latter is usually "for god's sake, if they obsess over the paperwork so much I'm never going to actually code it at all!".

      I guess you just make the best of the hand you're dealt with, and don't fantasise about which way would be best. As an analyst, I always prefer to do the paperwork properly; but most coders out there would probably feel the opposite.

    2. Re:Documemtation Priority by wrook · · Score: 1

      It's easy to simply dismiss this as poor management (and it is), but solving the problem is often a bit trickier than replacing the manager. The biggest problem is that a really large segment of the software industry does not know how to connect business goals with software development activities. It's not just the managers who are clueless, but also the programmers. Many programmers do not consider business goals further than, "If I do things *right* then it will be better in the long run" (for various descriptions of the words "right" and "better").

      What I've tried to do in the past is to encourage my manager to worry exclusively about business goals while I worry exclusively about maximizing through put. It's important to stress to the manager that you want to achieve maximum through put, not just maximum velocity. If you are running a marathon, it does you no good at all to break the world record in the 100 meter dash. You need to achieve the highest *average* speed possible over the entire course. This is done by intentionally slowing down and paying attention to things other than that when running a short distance. It's important to illustrate that the world record holder in the 100 meter dash would probably finish a marathon several times slower than even an average marathon runner.

      Having said that, there really are times when you have to sprint. It does you no good at all to get tremendous throughput and finish on Friday when the company runs out of money on the Monday before. But just like a sprinter, after we sprint, we have to stop and recover. Sprinting continuously leads to death.

      What I tend to do is to be very respectful when my manager asks me to sprint. I tell him that we will be happy to sprint for him. I tell him how far we can sprint and how fast we are likely to be able to run. I tell him the cost in terms of productivity (i.e., after this sprint, we have to stop and spend at least an equivalent time recovering). I let him choose, because that's his area. If he says we have to do something that I think is impossible, I agree to try my best. But I ask him to find another business plan, because this one will almost certainly lead to failure. It's his call and after he makes it, I will never say another word about it.

      Finally, if my manager tells me that he thinks we can go faster with another method, I will certainly listen to his ideas. If I disagree, I will tell him that I don't think it's a good idea. Getting the highest productivity that meets the business goals is my job. If he does not have confidence in my ability to do that job, then he should certainly find someone else for the job.

      Once we have an understanding in place, I've never had any trouble introducing any development practice I want. But my ass is on the line if we don't hit the business goals. And that's the way it should be.

    3. Re:Documemtation Priority by gl4ss · · Score: 1

      in reality, in modern changing by half year update platforms.. you first write it to see if it can be written. then you ship it.

      it's sad. but wtf, in which gigs can you actually document what you're going to do beforehand? where you'd have the specs at the start of the project - "this is what we want and we checked it can be done".

      I suppose with financial backends etc db stuff you'd know that.

      do you know what kind of "for end user" documentation I really hate though? the lying kind. press here for more information and then you don't get more information.

      --
      world was created 5 seconds before this post as it is.
    4. Re:Documemtation Priority by St.Creed · · Score: 1

      Good practice. I use it too and it works great for me as well.

      --
      Therefore, by the (faulty) logic you're using, you're just a cow with a keyboard - osu-neko (2604)
  22. Side note... by DaneM · · Score: 1

    "As an added benefit, documenting your code makes it possible for people who didn't write the program to use it."

    Yes, this seems obvious, but it's not. It's a Zen koan. Really. It's a well-known fact that koans are more fun to write and think about than documentation.

    Dance with the pinch pine blossom.

  23. Knuth by phantomfive · · Score: 4, Interesting

    I believe this is the method Knuth recommended, and formed the beginnings of the idea of literate programming.

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

      I've always wanted to write "tests" in a literate way. For me tests are a way to document the behaviour that I expect and various assumptions along the way. If the behaviour changes, or if I do something that disregards the assumptions I made, I want the tests to fail.

      I feel that I *should* be able to organize this in a literate way. If I want, I can even write human language documentation in the same place. The testing framework provides the same purpose that Web (or its equivalent) would -- it allows me to organize my discussion by design or by behaviour. The added benefit is that it is executable and so tells me if the production code is meeting my expectations. It also has the benefit of providing examples of how I expect the code to be used.

      The problem that I tend to run into is that I have too much coupling between the implementation and the tests. As I refactor code, the discussion I make with the tests drifts and I end up having to refactor the tests considerably more than the production code. To combat this, I have made a practice of separating my unit tests from my larger scale behavioural tests, but I still end up with a lot of churn whenever I'm refactoring. Because of this churn, it's quite easy to lose track of where I'm discussing what issue and my ability to use the tests as literate documentation slowly disintegrates.

      I've never actually done literate programming in the proper sense, so I wonder if people who do run into the same issues. I suppose it is possible they just try to avoid refactoring, which would be unfortunate.

    2. Re:Knuth by St.Creed · · Score: 1

      The idea is interesting but the tight coupling makes it difficult to check behaviour, unless you test the output on screen. Perhaps your tests are too granular for that?

      --
      Therefore, by the (faulty) logic you're using, you're just a cow with a keyboard - osu-neko (2604)
    3. Re:Knuth by phantomfive · · Score: 1

      The problem that I tend to run into is that I have too much coupling between the implementation and the tests. As I refactor code, the discussion I make with the tests drifts and I end up having to refactor the tests considerably more than the production code. To combat this, I have made a practice of separating my unit tests from my larger scale behavioural tests, but I still end up with a lot of churn whenever I'm refactoring.

      Have you ever solved this problem?

      It could be the problem is this: if you want proper code coverage, you typically need to write quite a few more unit tests than code. However, with literate programming, it seems you only have to write one comment for each piece of code. So I think the number of comments you have to write is significantly smaller than the test cases, but I'm not 100% sure.

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

      I'm experimenting with something that seems promising now. I think you're right about the test vs. comment issue. If you have code testing a boundary condition, you can pretty much say "This tests a boundary condition", but you might end up writing 3 or 4 tests to actually make sure that all the boundary conditions are satisfied. So what I've done is separate TDD unit tests from BDD acceptance tests.

      My process at the moment is to create a new test directory at the beginning of an iteration. In that directory, I create a test file for each story in the iteration and place the contents of each story in a comment. When I start a story, I write a behaviour oriented test and show that it fails. If I get to a point (it doesn't always happen) where the code necessary to satisfy the behaviour oriented test is more than what the test covers, I write a unit test. This usually happens if I create a new class, for instance. These unit tests are organized in the same way that the code is organized.

      When I'm refactoring, the unit tests are usually hit harder than the behavioural tests because they are more highly coupled. But I keep track of the code coverage. When I'm refactoring the unit tests, if I notice that a unit test is already covered by a behavioural test, I actually delete the unit test. This keeps the coupling to a minimum. Similarly, when I'm writing a new story, if I have behavioural requirements that are the same as a previous story, I will move the test into the new story.

      What I end up with is a directory tree containing unit tests that are organized like the production code. As I refactor code, these tests tend to be replaced by behavioural tests and the only thing that remains are minor details or assumptions that probably don't need to be pointed out explicitly when reviewing the code.

      I also have one directory for every iteration, containing tests organized by story. As the functionality changes, the old test files get smaller and smaller. If they become empty, I remove them. This gives you a pretty good idea of the functionality in the application ordered by the date that the functionality was added. So far this has been easier for me to search when I'm looking for something. You could potentially create a new directory containing symlinks to the behavioural code that presents everying in a different order, but so far I haven't felt the need for it.

      The other cool thing that I've experimented with is modifiying the test framework so that a burndown chart is created automatically from the behavioural tests. Originally, each story has no tests in it, just comments. This means the story hasn't been started. As soon as a test is added, the story is started. The story has an effort estimation, which I find is often indicative of the number of tests I will need. Thus, you can estimate how much effort is left in the story by the number of tests written. When the story is finished, it is marked as such. When all the stories are finished (and the tests pass) the iteration is completed. You can also compare the effort vs the number of tests and identify areas where the testing/documentation is not as complete as you might expect.

      I've only been doing this for a little while, so I'm not sure how well it will work out, but like I said it looks promising so far.

    5. Re:Knuth by phantomfive · · Score: 1

      Good luck

      --
      "First they came for the slanderers and i said nothing."
  24. Documentation as a static code analysis by Anonymous Coward · · Score: 1

    I believe the opinion of the OP is that documentation forms a powerful technique for static code analysis. This I think is likely, although there are better tools such as peer review, and static code analysis tools.

    I have to ask "at what moment in time did you write the documentation?". The purpose for the question is to point out that code changes across time. There are complex links between the documentation and code. These links are either correct, or in error. If they are in error we could categorise them as "bugs". True they are not bugs in the traditional sense: they are not the sort of bugs that can be detected and prevented with tests, or that affect the execution of the program, but they do affect the cognitive integrity of the code, and influence the developer.

    Let us be charitable and assume that no bugs were present at the first release. Then changes are made. Fortunately for the developer, IDEs and refactoring tools exist that allow the developer to identity areas of the code that likely to be impacted. In a scenario in which code reviews are mandatory, other peoples intellect are present to help reduce the chance of consequential changes. The developers test suite is present to help prevent regression errors.

    What about the documentation?

    The links between the documentation and code are complex, and difficult to understand in their entirety: the nature of plain text is that facts are repeated all over the place. There is no automated way to check this integrity. Even in a world in which you review all the code and documentation, you have little or no tool support (unless you use a requirements management tool, which are expensive in developer time) to help you. Effectively you are adding a manual testing stage to each release.

    So lets look at the costs:
    In my experience documentation adds around 50% to the cost of coding. The release cycle time deteriorates, and code is released into the user community much slower, which results in a poorer quality product. More defects are introduced.

    Lets look at the wins:
    It is clear that the documentation for an API makes a massive difference to the usability of the API. I have yet to be convinced that documentation of the code enhances that maintainability of it. The OP is correct I feel in his assertion that documentation forces a peer review.

    Personal conclusion:
    Document your APIs as thoroughly as you can. Spend the effort you would have spent on documentation on more effective peer reviews, and more ruthless code committing practices that ensure that the code is more maintainable.

    1. Re:Documentation as a static code analysis by rollingcalf · · Score: 1

      "It is clear that the documentation for an API makes a massive difference to the usability of the API. I have yet to be convinced that documentation of the code enhances that maintainability of it."

      Rather than enhancing the maintainability per se, the documentation helps with letting you know what needs to be maintained. In particular, a block of code may look perfectly error-free without looking at the documentation, but you only realize something is wrong when the documentation doesn't match what the code is actually doing. That then triggers further investigation to determine whether the documentation or the code is wrong or both, whereas without the documentation you might have glossed over that block of code because it looked logically correct by itself.

      --
      ---------
      There is inferior bacteria on the interior of your posterior.
  25. How to do documentation by Anonymous Coward · · Score: 1

    Most programmers complain about documenting because they've never been told the correct way to do it. Well here it is motherfuckers:

        1) Requirements need to be written and have a unique id. Functional reqs = what is needed, non-functional = constraints on how things shall be done.
        2) Design document = plan for fulfilling each functional req, each design configuration item has a unique id and references the id of the req it is fulfilling.
        3) Architecture document = plan for fulfilling each non-functional req, each architecture item has a unique id and references the id of the req it is fulfilling.
        4) In-code comments = id reference to the design/architecture/requirement configuration item the code is implementing.

    1. Re:How to do documentation by davide+marney · · Score: 1

      This is actually a pretty good list, but why are you posting as AC? AC posters have no Karma. You should get credit when you post insightful things like this.

      --
      "We receive as friendly that which agrees with, we resist with dislike that which opposes us" - Faraday
    2. Re:How to do documentation by St.Creed · · Score: 1

      I'm not sure that Architecture is just about the non-functional requirements. In my opinion, the Architecture doc is about ALL the constraints on the solution from an implementation point of view, not just the technical constraints.

      Your list does make sense though. Perhaps I should reconsider my opinion.

      --
      Therefore, by the (faulty) logic you're using, you're just a cow with a keyboard - osu-neko (2604)
  26. CS Research From the 1950s Onward Called by jfz · · Score: 0

    Isn't this precisely what specifications written in formal logic was intended to solve? http://en.wikipedia.org/wiki/Formal_verification

  27. Cool by DeBaas · · Score: 1

    Cool, the software we have to implement hardly has any documentation, so this must mean hardly any bugs ;-) Knew there had to be a reason why the documentation is hardly existing...

    --
    ---
  28. This article from 1996 never gets old by sn00ker · · Score: 4, Interesting
    Titled They Write the Right Stuff it looks at the coding practices at the company that wrote the control software for the space shuttles. If you want to know about documentation as a bug-finding tool, this is pretty much the holy grail.

    Consider these stats : the last three versions of the program -- each 420,000 lines long-had just one error each. The last 11 versions of this software had a total of 17 errors. Commercial programs of equivalent complexity would have 5,000 errors.
    ...
    Take the upgrade of the software to permit the shuttle to navigate with Global Positioning Satellites, a change that involves just 1.5% of the program, or 6,366 lines of code. The specs for that one change run 2,500 pages, a volume thicker than a phone book.

    --
    "God, root, what is difference?" - Pitr, userfriendly
    1. Re:This article from 1996 never gets old by Beryllium+Sphere(tm) · · Score: 1

      How many errors were there in the 2500 pages of specs?

      That group commands everyone's respect, and the answer is surely "As few as humanly possible", but doing that much error-free is not humanly possible.

    2. Re:This article from 1996 never gets old by Mr+Z · · Score: 1

      It really depends on how many passes over the specs they made, and how separable the sections were. If you have to hold all 2500 pages in your head at the same time in order to spot deep inconsistencies, few (if any) humans will ever succeed. But, if the documentation was well segmented, such that you only needed to hold couple dozen pages of knowledge in your head at one time to understand a section, then you stand a chance, with sufficient reviews, to comb all the nits out.

      I imagine there must be large portions of the spec just stating intended interactions with the other 420,000 lines of code. Even just stating the negative (ie. "no interaction with module X") for that much other code would take quite a few pages.

      And, consider this quote from the article:

      And money is not the critical constraint: the groups $35 million per year budget is a trivial slice of the NASA pie, but on a dollars-per-line basis, it makes the group among the nation's most expensive software organizations.

      That's the real reason. Perfection in the software is the primary focus, cost be damned. Most projects live within less generous cost and time constraints. They can't afford a 2.5:1 code to spec ratio.

      Also, I wonder about the nature of measuring the defect density. If there's a "deep" error, but the spec and the software agree, does it count as a bug?

    3. Re:This article from 1996 never gets old by Doofus · · Score: 1

      great reference

      thank you for sharing this

      --
      If the Government becomes a lawbreaker, it breeds contempt for law; ... it invites anarchy. - Brandeis
    4. Re:This article from 1996 never gets old by ultranova · · Score: 1

      Also, I wonder about the nature of measuring the defect density. If there's a "deep" error, but the spec and the software agree, does it count as a bug?

      Depends on what you mean by "deep" error. There are guaranteed to be circumstances in every control system where they make sub-optimal decisions, simply because making optimal decisions in every circumstances requires an unbounded amount of processing power. Even assuming limited computing resources, you'd need to enumerate all possible circumstances and their likelihood to figure which of possible programs will perform the best overall, which is impossible.

      I mean, was it a "deep" error that Challenger would launch when the temperature was too low? And was it a "deep" error that Columbia didn't download the video of its launch from the Internet, analyze it for possible problems, and then refuse to re-enter the atmosphere until someone had gone and investigated its heat tiles? Or, in a simpler hypothethical scenario, what if the shuttle is launched overloaded and is unable to reach orbital velocity - will the control system give up and properly handle landing (using up and ejecting the external tank first, not accelerate to speeds said tank couldn't handle in the atmosphere, etc)?

      Once your system has to deal with the real world and its infinite variety of situations, any discussion about "deep" errors tends to go off the deep end pretty fast.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

  29. The term "documentation" is subjective by ciaran.mchale · · Score: 5, Interesting

    There is an old joke: "The definition of promiscuous is somebody who has more sex than you do". From reading TFA and some of the comments on slashdot, I get the feeling that the definition of documentation is equally subjective and self-serving for developers. Some developers think that writing documentation means adding comments to code. Others feel it involves writing Javadoc/Doxygen-style comments at the start of every class and method, and then generating HTML from that. Yet others feel that documentation hasn't been written unless it involves an architectural description.

    When I am working on my own open-source projects, I feel that documentation isn't complete until I have written a few hundred pages of text that aim to be cover most/all of the following: (1) API reference guide, (2) programming tutorial, (3) user guide, (4) architectural guide, and (5) suggestions for "future work" that I hope other people will volunteer to do. Yes, I recognise that I am a bit extreme in the amount of effort I put into writing documentation. However, it does enable me to elaborate on the thesis of TFA: attempting to write such a comprehensive amount of documentation often highlights not just coding bugs, but also architectural flaws. This causes me to work in an iterative manner. I implement a first draft version of the code. Then I start documenting it, and when I encounter a part of the software that is difficult to explain, I realise that I need to re-architect the code base a bit. So I do that, and then get back to writing documentation, which causes me to notice another difficult-to-explain issue with the code. Working in this manner is slow, and I suspect it wouldn't work in a business with time-to-market pressures, but I find it gives excellent results in my own, non-time-pressured open-source projects. I touched on this issue in the documentation for one of my open-source projects.

    1. Re:The term "documentation" is subjective by olau · · Score: 1

      Are you sure you're really receiver-focused when you write all that stuff? Most people don't want to read that much text to use, say a configuration parser. If it takes people 10 hours to dig through your documentation and 1 hour to actually write the code, you're probably not doing it right. Sometimes less is more.

      Reference documentation is a bit different because people to some extent can just go directly to what they need. But in my experience, most people just want something they can copy-paste into their project and get started with.

      One problem with producing too much stuff yourself is that you tend to build up your own little bubble where everything makes sense. In theory. :)

    2. Re:The term "documentation" is subjective by Anonymous Coward · · Score: 0

      Not at all. We wright pretty damn good code. It's not quite space shuttle quality, but it's the same order of magnitude. We use the term "requirement traceability" instead of "documentation" since we do the documentation first. However, if you read RTCA DO-175C, you'll see that there's a good way to write life safety critical code. We don't start with a programming language; picking that it later. We start with a definition of what the system will do.Then we describe the requirements of the system. Identifying edge cases is interesting, when you have mechanical sensors that can fail in creative ways, but it must be done. Then we decompose those requirements down to the module of code level. It's a waste of time if you're writing another Angry Birds knockoff. However, if your code is the flight controls for an angry bird, well, it's important. That being said, though, writing code is remarkably fast when you know what the hell you want to do and how it will play with the rest of the program. Yes, even our fucking idiot retarded Northrup Grumman can get it right. Most of our code maintenance now is loosening up parameters so that it will accept more risks, now that we've got numbers to support that.

    3. Re:The term "documentation" is subjective by Sponge+Bath · · Score: 1

      You saved me the time of writing a similar post. Writing that kind of documentation makes robust, maintainable, supportable, reusable and long lived software (or FPGA design, etc). It's not a chore, it's a pleasure because it results in a polished product that people want to use. Without it you just wrote a fart in the wind: it stinks now and is gone tomorrow.

    4. Re:The term "documentation" is subjective by ciaran.mchale · · Score: 1

      Are you sure you're really receiver-focused when you write all that stuff? Most people don't want to read that much text to use, say a configuration parser. If it takes people 10 hours to dig through your documentation and 1 hour to actually write the code, you're probably not doing it right. Sometimes less is more.

      In the case of my configuration-file parser, a new user just needs to open the Getting Started manual and read two short chapters: Overview of Config4* syntax and Overview of the Config4* API. I would be surprised if doing that would take more than 30 minutes. And having done that, it would then take the new user about 5 minutes to write working code.

  30. Re:Only proprietary software needs documentation by Zontar+The+Mindless · · Score: 1

    Everything else is nitpicking by incompetent people which do not belong in the audience anyway.

    I'm sorry, you seem to have written incompetent people where you really meant to say,

    Devs who need to make changes but who came on board after the original code was written;

    Support techs who have to support and debug code they themselves didn't write;

    QA folks who are responsible for making sure a release does what we claim it does before it gets out in the wild;

    Managers who like to have some assurance that when they tick the little box labelled Task Complete , the task they've just signed off on is actually complete and correct;

    Customers who are trying to understand why the software does [foo] when they expected it to do [bar];

    Community members who'd like to contribute patches;

    Tech writers who have to write end-user documentation.

    --
    Il n'y a pas de Planet B.
  31. Found some bugs by roguegramma · · Score: 1

    I found some bugs documenting my own code lately, but I think that only works if you write the documentation a month or so after you wrote the code.

    --
    Hey don't blame me, IANAB
  32. Documentation requires a human reader by Anonymous Coward · · Score: 0

    Good code should require little low level documentation to describe it and of you spend your time writing tests surely they document the intent of your code and can be tested by a computer.
    Personally I would prefer to see high level design drawings/sketches, tests and code I can read.

  33. Not really sure ... by thoughtspace · · Score: 1

    All in favor of the idea; but many boundary conditions are dependent on the implementation. If the documentation goes down that far into the implementation level - well ... it becomes code.

  34. Aehm, why is this news? by gweihir · · Score: 1

    I was taught that in my first year CS studies, when we were required not only to write programs, but to clearly document the algorithms used. Are there really people that write software and do not know this? Well, I guess there must be. Supports my claim that the only real problem the human race has is too many idiots.

    --
    Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
    1. Re:Aehm, why is this news? by St.Creed · · Score: 1

      Ratio of CS educated programmers to random people picked off street and cleaned up: 1 to 100.

      Yeah I'm making that up, but in the course of my career I've worked with hundreds of developers and I think I've only encountered 1 or 2 CS graduates in my work. I meet more of them socially than I've ever seen in the workplace doing real work (not managing the IT dept.).

      So 1:100 might be an optimistic estimate.

      --
      Therefore, by the (faulty) logic you're using, you're just a cow with a keyboard - osu-neko (2604)
    2. Re:Aehm, why is this news? by Anonymous Coward · · Score: 0

      In the real world, things don't work like your first year of CS studies. The goal of COMMERCIAL software development is to produce a product that makes money. Documentation does not fit into that scheme.

    3. Re:Aehm, why is this news? by Mr+Z · · Score: 1

      How many of those programs had comments like this?

      i++; /* add 1 to i */

      People joke about such bad documentation, but I have actually been subjected to it in a professional environment. If I ever teach a programming class, I will give an automatic zero to such inanity.

    4. Re:Aehm, why is this news? by gweihir · · Score: 1

      Students tried, but that made you lose points. And you had to get 50% to be allowed to take the final exam.

      --
      Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
    5. Re:Aehm, why is this news? by gweihir · · Score: 1

      Well, that would both explain the sad state a lot of software is in and support my conclusion. Of course the problem is now those that thing random people picked off the street can be taught to program. Creating good software (reliable, secure, efficient, maintainable,...) is one of the hardest activities known to mankind.

      --
      Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
    6. Re:Aehm, why is this news? by gweihir · · Score: 1

      It does as long as you have the minimal ethics to actually try to offer long-term value to your customers.

      --
      Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
    7. Re:Aehm, why is this news? by ultranova · · Score: 1

      If I ever teach a programming class, I will give an automatic zero to such inanity.

      Then you'd better be prepared to teach psychology and literature in your programming class, since knowing what others can easily figure out falls into the realm of the first and the ability to communicate your intent clearly into the second.

      Writing (useful) technical documentation is its own skill, and if you require it you either must teach it yourself or list it as a pre-requisite.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

  35. there are 10 types of people by Anonymous Coward · · Score: 0

    there are 10 types of people. those who read binary and those who don't.

    why bother with documentation if you could read binary?
    why bother with binary if you can read code that can be compiled to binary?
    why bother with code if you can read documentation that can be compiled to code?

    so why isn't there a code that is human readable and can be compiled to code? because its too damm hard for humans to do it. and if humans cannot compile code from documentation well, why would you invest in a process the yields no extra power, just extra place to introduce bugs?

    documentation will not help, if it is not fused into the code.
    you need to ponder before you go into coding? go talk to pinky.

  36. Pick descrisptive variable names by Required+Snark · · Score: 2
    This is another good documentation tool, and a way of avoiding bugs. It is surprisingly hard to do.

    If you can't think of a good reasonably short and descriptive name then you don't understand the concepts as well as you should.

    I only use variable names like i,j,k for loops. I use x1,x2,y1,y2 and similar names only for numeric values. This is applicable when I am implanting math algorithms. If I have a lot of similar variables differing by their last digit and I'm not doing equations, I know I am writing code that I won't be able to read later.

    I tend to declare one variable per line, and describe what I am using it for as a comment. If I have a lot of variables I split them into groups, which I separate by blank lines.

    I try and avoid reusing intermediate variable names, unless they are in different lexical scopes. It is fine to have similar name inside loops that doing similar work, but make sure that you are not confusing concepts when reusing variable names thie way.

    I have been working on algorithms, and have stopped and spent an hour or more thinking about what to call the variables. I do this when I get confused. It always pays off. When you have a good descriptive name and you see it in it's use context, you can actually see the mistakes before you make them.

    --
    Why is Snark Required?
    1. Re:Pick descrisptive variable names by davide+marney · · Score: 2

      Even better:

      1. When naming entities, pick the SAME names that the business people use when they talk about their domain. Do they call that thing you're working on an "XYZ Thingy"? Then that's the name you should give that entity in the code, formatted according to your conventions for names. Why? Because then your code aligns with the requirements, models, and documentation, no translation needed.

      2. When naming methods, use GENERIC names for generic actions, or build names from combining generic action verbs with entity names, sort of the way the German language builds compound words. The entire web, for example, runs on a handful of method names, and the top three (HEAD, GET, POST) account for 99% at that.

      This is the domain-driven design way to do it.

      --
      "We receive as friendly that which agrees with, we resist with dislike that which opposes us" - Faraday
    2. Re:Pick descrisptive variable names by Mr+Z · · Score: 1

      I would go further: Thinking about the language of your project can be incredibly useful and clarifying. If you can boil down your problem's concepts into a consistent and fairly precise language, then you stand a better chance of implementing without too many thinkos.

      Aligning that language with the business processes is definitely important, if your software is implementing business logic. Not all problems have a business process to align with. But, they have something they interface with, so try to be consistent with that (unless that thing is itself horribly inconsistent).

      All that said, the strategy of the GP post of having consistent generic names (i/j/k for loop labels, etc) also has an important role. It makes it easier to identify the details that are not important. Consider array[array_index] vs. a[i]. The former takes a lot longer to read, but doesn't really convey any additional information for the effort. Conventional names for common actions allow you to filter away the noise, leaving you to focus on the actually novel bits.

  37. Re:Only proprietary software needs documentation by Anonymous Coward · · Score: 0

    No need to be sorry.

    If you look closely you'll see that I have also written: Software using open standards for configuration and data uses open standards that have been documented already.

    Devs can read that documentation.

    Support techs can read that documentation.

    QA folks can read that documentation.

    Managers instruct Devs to change realities to resemble their incompetent believes.

    Customers will never read documentation but, instead, contact/bother QA folks, Support and Devs.

    Community members can read that documentation and contact Devs.

    Tech writers write what they want (see Slashdot summaries).

    Welcome to reality. Now mod it down as much as you want.

  38. Re:Only proprietary software needs documentation by julesh · · Score: 1

    Reality? The reality is that a design document written before coding starts is likely to never be accurate enough to perform the kind of annotation you're talking about, because as soon as coders sit down with it to actually implement stuff, they'll realise the design missed some crucial point of logic about how the application should work. And as soon as the code is demonstrated to the customer, the customer will point out misunderstandings about the design. And as soon as you start changing requirements your entire cross-referencing scheme starts taking more time than actually implementing the software does. The developers begin to hate it. The managers start to hate the developers because they can't stick to an apparently simple scheme. QA wonders why the software that has been produced appears to be different to the software they expected to be testing (because the coders had to update the spec to fix logical ommissions, but nobody forwarded the revised spec to QA), and starts filing bugs against correct behaviour. Before long the entire system falls apart and people are bickering about whose fault it is.

    Been there, done that, and it's the last time I ever work for an FTSE250-listed corporation.

  39. Theory doesn't always work in practice. by Barbara,+not+Barbie · · Score: 4, Insightful

    The theory was, write the documentation, then code to the documentation.

    In practice, that isn't sufficient to reduce bugs significantly, for several reasons.

    1. As you develop something, you find that "getting from A to B" sometimes requires going via D instead of C;
    2. Other times, you realize that the documentation doesn't completely capture the requirements, and you need to visit both C and D, and maybe Z
    3. Still other times, you realize that A is entirely superfluous.
    4. "Can you add/change this feature?"

    The initial specification should never be too specific about implementation details - that's a mistake that too many people fall for, going with the illusion that they actually can nail down every detail of a non-trivial problem and just throw the spec at "code monkeys." They don't understand that a specification should only say what, not how. Writing "code documentation" before writing the code is writing the "how".

    So they can end up with something that meets that spec, but doesn't work either as intended or just flat-out is wrong.

    Unfortunately, code, then document (when and if you get around to it) is the reality because, unlike theory, reality is messy.

    --
    Let's call it what it is, Anti-Social Media.
    1. Re:Theory doesn't always work in practice. by St.Creed · · Score: 4, Insightful

      You need to distinguish between functional and technical specs.

      Functional specs are very usefull (if done even halfway right). Technical specs are a waste of time unless you assume by default that you're dealing with incompetents, in which case you're better off saving yourself time, money and aggravation and hire a better developer.

      So I do write a lot of functional specs. Even now, in an agile environment, with HUGE time pressure and multi-million penalties for delivering late - just finishing up my final 40 pages (90 pages total, in this 4 week sprint). Why? Because not doing so will make the project much later. Good architecture (system design) specs will make the project about 20% more likely to deliver on time (citation if I can find it again) even if the programmers don't follow the guidelines (interesting, right?). This matches with my experience: if you write decent designs, you are more likely to find the pitfalls before they can bite you in the ass. If you cover all the bases and make sure the business has provided for all scenarios before you get there, your project will run smoother.

      So docs may not prevent all the bugs. But it does prevent a large number of nasty stuff before it gets to the stage where it turns into a defect.

      --
      Therefore, by the (faulty) logic you're using, you're just a cow with a keyboard - osu-neko (2604)
    2. Re:Theory doesn't always work in practice. by ThirdPrize · · Score: 5, Funny

      Wrong. First you write the documentation, then you write the tests and then, if you have time, you write the code.

      --
      I have excellent Karma and I am not afraid to Troll it.
    3. Re:Theory doesn't always work in practice. by Barbara,+not+Barbie · · Score: 0, Troll

      "agile" and "sprint" - two more myths.

      --
      Let's call it what it is, Anti-Social Media.
    4. Re:Theory doesn't always work in practice. by DarkOx · · Score: 1

      So don't get to specific about the implementation. That is what comments in the code are for (well I suppose they are form of documentation as well). The design docs help you eliminate the most dangerous type of bug, "the logic flaw", almost any other type of problem can be patched. If you get the basic assumptions wrong you wind up throwing away all the glue.

      The glue is the application. Anyone one can toss together a little atomic procedures to do X or Y, know which ones are needed in the first place, and being able to organize them into something larger an cohesive is all the value.

      --
      Repeal the 17th Amendment TODAY! Also Please Read http://www.gnu.org/philosophy/right-to-read.html
    5. Re:Theory doesn't always work in practice. by Barbara,+not+Barbie · · Score: 0

      Wrong. First you write the documentation, then you write the tests and then, if you have time, you write the code.

      What garbage. According to that definition, if all that is ever delivered is docs and tests, you're good - whereas the reality is you've failed completely, since you have zero functionality.

      The additional problem with test-driven design is that tests can only cover what you anticipate. But that's okay if you're a java weenie - you can point to all your tests and say "see, I'm 90% there already", because process is more important than working code.

      --
      Let's call it what it is, Anti-Social Media.
    6. Re:Theory doesn't always work in practice. by doom · · Score: 1

      No one said anything about specs, did they?

      I find if I write the documentation for a routine before I start writing it (and/or it's tests), I'll simplify the interface a lot. It's all too easy to code to support different largely irrelevant options, but if you actually have to describe how to use the code, you quickly discover it's too hard to write about them all.

      This process works because I'm not typically working to a "spec" (as indeed most of us are not these days).

    7. Re:Theory doesn't always work in practice. by Barbara,+not+Barbie · · Score: 1

      You're not ever supposed to get into implementation details in a spec, unless it's to describe externals - such as an existing database or table that new stuff needs to work with.

      The words "MAY", "SHALL" and "NOT" should pepper the initial spec.

      1. Users MAY be logged in; // logging in is optional
      2. Users SHALL log in before doing X; // only logged in users allowed to do X
      3. Users SHALL NOT remain logged in for more than Y time before being re-validated.
      4. Prices SHALL be displayed per unit, and per pallet;
      5. Prices MAY include taxes; // this tells you that you'll need to do some research on taxes, locales, etc
      6. Users MAY NOT have more than one session at a time;

      None of this goes into implementation details; to the extent that you do, you have a bad initial spec - you're focusing on the wrong thing.

      The logic, if it's not apparent when it's time to code, is a warning to step away from the keyboard, get a scratchpad, and THINK. Come up with at least 3 different ways to solve that portion, then pick one. Not just bang out documentation, test cases, and code until you have something that "sort of" works.

      It's like the fundamental flaw in TDD (test-driven design). I'm all for DDD (data-driven design), but TDD encourages "let's fix this flaw", write a test for it, and if it passes, we're good. They forget to add 4 words - "until the next time."

      TDD doesn't put the responsibility on the programmer to ask "what did *I* do wrong for this to happen in the first place, and what can be done to prevent it happening again?" Sometimes, it's an ambiguous spec. Sometimes, it's a badly thought out process - or an unnecessary one.

      Case in point - bad user input. The typical TDD Agile Weenie says "I'll insert some code to make sure that they can't input a negative amount." WRONG! That doesn't solve 2 problems - the initial cause, which was that the spec should have said "The input SHALL always be an amount between X and Y", and that they coder didn't write a small lib that always forces values to be the right type and range.

      Writing documentation in parallel is just a distraction; the same amount of time would have been better spent in quiet meditation about the problem and how to avoid it in the future.

      So, next time someone delivers a spec, the programmer will look at it, redline the areas where no "Acceptable values SHALL be between X and Y", and send it back, so that whoever wrote the spec in the first place can fix THEIR mistakes.

      --
      Let's call it what it is, Anti-Social Media.
    8. Re:Theory doesn't always work in practice. by Barbara,+not+Barbie · · Score: 1

      This process works because I'm not typically working to a "spec" (as indeed most of us are not these days).

      And there's problem # 0.

      People are too lazy to write a decent spec. Or, in so many cases, they don't even know how. Many have never even SEEN a proper spec. I've seen people who think that a bunch of screenshots is a spec, or that some database layout is a spec (though the latter is closer, but since it describes the actual implementation, it still fails). Or they'll spend a week with a UML tool, and produce something equally useless.

      "SHALL", "MAY", and "NOT". A good spec is peppered with these. Not screenshots. Not general fuzzy descriptions. But too many people simply are intellectually lazy. They won't take a day to read a few real specs, and learn how to cleanly separate the specification from the implementation details, so they're locked into one channel of thinking before they even start implementing.

      if you actually have to describe how to use the code, you quickly discover it's too hard to write about them all

      If you have to code them all, you're "writing them all out" anyway. So, whoever has to write the spec should be equally willing to "write them all out" - or they're a problem, are not doing their job, should be called on it, and if necessary fired for incompetence.

      A good example of the ongoing problems caused by incomplete and ambiguous specs is CSS 2.1. 15 years later, no two browsers render CSS 2.1 completely the same, because the original spec was a steaming pile of dog turd. It's why there are still so many additions being made to it to fill in ambiguities - and the back-filling process should never have happened.

      This is what you get when you have a bunch of egg-heads in an ivory tower "assuming". Don't expect CSS 3x to be uniformly implemented in your lifetime - the process was never fixed, the guilty parties were never taken behind the outhouse and shot, and most people are still saying it's okay because "that's the way it is", same as programmers duck responsibility by calling it a "bug" instead of a mistake. I don't make bugs - I make mistakes. Only bugs make bugs.

      --
      Let's call it what it is, Anti-Social Media.
    9. Re:Theory doesn't always work in practice. by Ryanrule · · Score: 1

      "1. As you develop something, you find that "getting from A to B" sometimes requires going via D instead of C; 2. Other times, you realize that the documentation doesn't completely capture the requirements, and you need to visit both C and D, and maybe Z 3. Still other times, you realize that A is entirely superfluous. 4. "Can you add/change this feature?" " This ALL should have been covered in design. Design should be AT LEAST as long as build, probably more. The problem is all the middle managmentment are boomers and genx, and they are terrible.

    10. Re:Theory doesn't always work in practice. by Barbara,+not+Barbie · · Score: 1

      This ALL should have been covered in design

      Not really - that's like saying that the building architects should have covered the placement of every single screw for attaching cladding to a building, every single nail that goes into every 2x4, and every single joint in every piece of piping.

      The code is also a "reality check".

      You can design down to the last implementation detail, in which case you're doing it wrong. You just have to hire experienced programmers who know what they're doing, not some outsourced 3rd-world contractors. It's cheaper in the long run.

      --
      Let's call it what it is, Anti-Social Media.
    11. Re:Theory doesn't always work in practice. by ewibble · · Score: 1

      First I think the if you have time, write the code was a joke.

      Tests are useful, but it depends where, with UIs a lot of it is about how it feels, looks it so quite hard to write test that are useful and won't break at the slightest change. With underlying complex code however tests are very useful.

      Nobody said test are a silver bullet an you will not get any bugs, but written well and appropriately they can save time developing and maintaing. written badly you spend more time fixing tests than writing code, and once you don't trust your test not to break they loose a lot of their value. Since you just assume its a broken test double the code to debug.

      Documentation can useful however it has to be short, and useful too many times do see things like: /*
          finds item in list
          map the map to find the key in
          Key the key
          returns the found item or null
      */
      ItemType find(Map map, KeyType key)

      for crying out loud the documentation provides nothing (apart from fluff I should ignore), and really it isn't needed it anyway. That is what you get when you force people to document every single thing. Developers should be able to read code, I can read code better than can English and definitely write it better because spelling isn't so important 8-). I can usually tell when someone meant to do something or it was by accident.

      On a side note documents seen to be far too big, too much emphasis on you wrote X page well you must have done lots of work. (just like back in school) Once I read a specification for transferring data the first 100 pages where what is XML the last 2 where what was needed.

      I good technical document should convey the relevant information well, putting irrelevant padding only detracts from that

    12. Re:Theory doesn't always work in practice. by Anonymous Coward · · Score: 0
  40. Another Anecdotal Datapoint by mattpalmer1086 · · Score: 1

    I'm currently writing up API documentation for a large code branch which was never properly documented (and wasn't written by me), but now needs merging into trunk. I've found several serious bugs in the code as a result, all from trying to explain to the client how to use the API. These bugs were actually blindingly obvious when the behaviour of the code had to be explained.

    I've also found some horrible design issues, where various settings the code allowed were contradictory or meaningless, or one setting overrode the behaviour of another, unless something else had been configured, in which case... you get the idea. As soon as you try to explain it, the awkwardness makes the design problems incredibly obvious - and in fact a much better way of doing it is also obvious. I can almost picture the evolutionary process by which this code was written, with each developer adding a new feature without regard to how the whole thing hung together.

    So documenting after the fact can definitely detect bugs and design weaknesses - although I don't think this is an ideal way of doing so. Having said that, I'm not sure forcing the developers to document their design beforehand would have helped either, as a lot of developers simply regard documentation as a necessary evil (assuming it is enforced), and will simply write down whatever it is they intend to code, no matter how awkward the result.

    I guess you have to have a mentality which loves elegance at all levels, not just in the specific lines of code that are written but how the system as a whole functions. Unfortunately (and surprisingly to me), many developers don't seem to care about the bigger picture, even when they have a deep appreciation of clever or elegant code.

  41. Actually, I think most people do this: by petes_PoV · · Score: 2

    Sit around trying to make sense of the requirement
    Write some code that they think does what the requester really meant
    Spend most of their time fighting the code management system and getting it to build cleanly
    Pull an all-nighter just before the deadline so it doesn't crash when fed correct input
    Toss it "over the wall" to the integration team
    Refuse to answer any questions about it as they're not "too busy" on the next project

    Have a nice feeling of satisfaction that they never have to do support on old code, as none of it ever gets into a production system
    Get promoted frequently for meeting their targets on productivity and delivery times

    --
    politicians are like babies' nappies: they should both be changed regularly and for the same reasons
  42. Re:Someone teach this guy about circular buffers S by donscarletti · · Score: 2

    Crap coders tend to focus on incidental things that they feel will improve the quality of their code, rather than addressing the issues directly.

    --
    When Argumentum ad Hominem falls short, try Argumentum ad Matrem
  43. If you can't explain it, you don't understand it by time961 · · Score: 1

    Attributed to Albert Einstein, the full quotation sometimes reads “If you can't explain it simply, you don't understand it well enough yourself". He was a smart dude.

    The most useful type of documentation is about intent and goals: WHY does the software have these interfaces, what are they supposed to accomplish, what is the overall model of operation, etc. That, I think, is where the best bugs are found. If the model isn't complete, then the code won't be. And that kind of documentation isn't bulky or repetitive--it has a very high return on effort. It's also useful to have documentation that explains particularly clever or complicated implementations.

    Less useful is documentation that can easily be inferred from the code. Writing API documentation by hand is tedious and unproductive. If the API and its parameters use well-chosen names there's not a lot to add--and using something like Doxygen makes it easy to include a few hints where they are needed. But Doxygen isn't the place to explain the architecture or system model--that should be thought out first, not stapled into API comments here and there.

    Many times I've found bugs by explaining to someone how a system is supposed to work. Doesn't have to be someone who knows much about it, occasionally it's even been my dog. High-level documentation is just another way to exercise that technique, with the advantage that the explanation itself can be reused.

  44. What kind of documentation? by Beryllium+Sphere(tm) · · Score: 1

    Debugging is about what the code actually does, and the hard part, why it does it.

    The *right* kind of comments helps explain the "why" if the code is working right. I've been complimented for including comments that began "Maintenance note:" that explained non-obvious decisions.

    But end-user documentation? You can generate test cases from it, but only a small fraction of those you need.

  45. Problem Solved 25 years ago by Anonymous Coward · · Score: 0

    We use design by contract (google it) now at my company. Comments are part of the formal interface specification for our code.

    You don't have formal interface specifications? Your code is buggy.

  46. Code Review by tomhath · · Score: 1

    What this guy is talking about is a do-it-yourself code review; better would be to get coworkers to review it with you. It doesn't matter what technique you used to write the code in the first place, get a couple of fresh eyeballs to read and try to understand it.

    As an unrelated comment, someone who thinks extra large gray on white fonts look good shouldn't be making web sites. At least he didn't put each paragraph on a separate page.

  47. a different perspective by Anonymous Coward · · Score: 0

    When I really struggle with a coding problem, I post it on Stackoverflow. Before I post it, I plan what I need to say.
      I plan how to describe the problem, what I am trying to achieve and what I have done so far.More often than not, during that process of planning I find the answer to my problem and don't need to post anymore!!!

    Sometimes you just need to take a few steps back, breathe and look at it from a different perspective.

  48. Nothing will eliminate bugs. by 140Mandak262Jamuna · · Score: 1
    There is simply no incentive to write bug free code or even to make a conscious effort to reduce the bugs. Given the incentive structure in most programming shops one should be amazed the bugs are as few as they are today.

    Think about it, if I implement a feature that has absolutely no bugs, no problems, no one complained and it is all hunky dory all the way. How much praise will you get for it? How many of you have written in your annual self assessment, "I implemented a critical feature foo in 2009 that has no bugs reported on it"? If you had bothered to write something like that down, would it be given a higher reward than "I increased the speed of the feature foo by 10%"

    A step further, if you had a choice of a complex, difficult to test algorithm (say, using AVL tree based on two custom hash functions on a data set) to give you a 10% speed up versus a clean simpler algorithm (say, using a std::multimap that is essentially a balanced binary tree) which one would be rewarded more by your company? If you had chosen the complex one and a critical bug shows up and the customer is breathing down the neck of the company, everyone from the VP of sales will be talking to you, asking when and how fast could you fix it, and if you do fix it, you get this glowing review and reward. The simpler algo? You are just leaving food on the table for some jerk to come in, replace it with a buggy 10% faster algorithm and ask for a raise, making you look like a fool implementing a "slow" algorithm.

    The reward structure in the corporations place very little value on bug free code, reward it very little, under estimates the maintenance cost of buggy algorithms, the programmers see buggy/complex implementations as job security. That is the crux of the matter.

    --
    sed -e 's/Chuck Norris/Rajnikant/g' joke > fact
    1. Re:Nothing will eliminate bugs. by tomhath · · Score: 1

      if I implement a feature that has absolutely no bugs, no problems, no one complained and it is all hunky dory all the way. How much praise will you get for it?

      If you don't get recognized for that you need to find a new job.

      if you had a choice of a complex, difficult to test algorithm (say, using AVL tree based on two custom hash functions on a data set) to give you a 10% speed up versus a clean simpler algorithm

      Unless there was a critical need for that extra 10% you would be foolish not to go with the simple approach. Cost, schedule, and reliability are almost always more important than an incremental performance improvement.

    2. Re:Nothing will eliminate bugs. by 140Mandak262Jamuna · · Score: 1

      If you don't get recognized for that you need to find a new job.

      I know you mean well, but most bosses and most companies do not recognize better quality coding. Some programmers know how to talk "managementese" and make them do the right thing. Like, "Let us use the simpler algo, though slower, because it would get us to the maket sooner. In the next release we will replace this faster algo to sell the upgrade". But often the people who actually do the coding are removed several layers from the management and they rarely get a chance to sell their idea to their management.

      Management is obsessed with the assembly line and Toyota factory model of software development. The software development process will be broken down into smaller and smaller pieces, and eventually a set of generalist programmers will be able to implement the feature. That is their idea of cost control.

      Unless there was a critical need for that extra 10% you would be foolish not to go with the simple approach. Cost, schedule, and reliability are almost always more important than an incremental performance improvement.

      I totally agree, but people who think like you and I rarely go high into management.

      --
      sed -e 's/Chuck Norris/Rajnikant/g' joke > fact
    3. Re:Nothing will eliminate bugs. by Anonymous Coward · · Score: 0

      Speaking as a salesman, I can assure you that upgrading to the latest version will eliminate bugs.

  49. Pre / Post coding benefits by Tronster · · Score: 1

    I've witnessed writing documentation / seudo lines of code in comments on what a section is suppose to do is a quick way to ensure all pieces come together; frequently able to leave those comments afterwards to describe the following 1-N lines below it.

    On the flip side, writing documentation after code can indeed point out bugs if the code is scanned as the documentation is written; it's not unlike a form of Rubber Duck Debugging https://en.wikipedia.org/wiki/Rubber_duck_debugging .

    In the end, the only glaring weakness is rewriting the (more minuet) documentation when refactoring the code it's describing. But I'd argue the extra time it takes to rewrite the documentation is, again, Rubber Duck Debugging the refactored code.... a good thing.

  50. Not bugs, design flaws by Hentes · · Score: 1

    Documentation describes what you intent a piece of software to do. It doesn't assure that the documented piece really does that, but it can help catch design flaws if you realise that that's not the functionality you wanted.

  51. I've heard a variation of that before by NotSoHeavyD3 · · Score: 1

    The one I heard was try to explain it to a big cardboard cut out of a person. Halfway through you explaining it out loud to it you'll have a eureka moment even though you'd literally be explaining it to a big piece of paper.

    --
    Did you know 80 to 90% of the moderators on slashdot wouldn't recognize a troll even if one dragged them under a bridge.
  52. Fagan Inspection has been around for 4 decades by Anonymous Coward · · Score: 0

    software inspection -- you go thru and review the requirements and file bugs. fagan created this process a long long time ago. i've attended both fagan and tom glib training -- really got a lot out of tom gills training

  53. Documentation is your first user by BobC · · Score: 1

    I look to documentation as being my first blank-sheet synthetic user. Writing documentation early forces me to get out of developer mode and into user mode. If I can't write the documentation first, then I probably don't understand the problem space well enough to craft a usable solution. If I can't explain my approach to others, then I probably don't understand it well enough myself!

    If you subscribe to the "Test Early, Test Often" mantra, then what can you test before you have written any code? Yup, the documentation. As soon as I feel I've documented something well enough enough to start coding, I release my documentation to anyone who wants to look at it. The feedback can reveal areas I missed or misunderstood before I have sunk too much time into building a wrong or incomplete thing.

    As a developer of embedded real-time systems, early knowledge or perception gaps can become costly in terms of both money and schedule. Writing documentation and getting it reviewed will quickly highlight areas that need further examination or exploration. Where is more research needed? Which areas should be prototyped to ensure feasibility before choosing a specific solution path?

    You can also view documentation as the first conceptual system test and last real-world system test: If the final product doesn't do what's promised in the documentattion, then either the worng product was built, or the documentation describes something that can't or shouldn't be built. Good to know this stuff ASAP!

    Documentation is also a negotiation tool: It gives all stakeholders something to point at while describing their needs. It ensures we're all speaking the same language.

    If you work in an Agile environment, negotiated documentation updates are one of the best ways to get needed changes into the product. This also means documentation is a living artifact: The code can't be wrapped up until the documentation stabilizes. It also helps bind distributed teams, again because it provides a common point of reference.

    In a completely new project, the first document I write is the User Manual. It lets me distill requirements and use-cases into my conception of the final product. If my task is a library, then that document may fit in a README.txt file. If it is a device or system, it may be the size of a small book (depending on the size or complexity of the system).

    When doing maintenance, the bug system is the primary gateway I use for deciding what should be changed, why it should be changed, and how it should be changed. The relevant bug reports and feature requests live only in text form, and evolve into stories that end with a "to do" list. Again, it's all documentation.

    Finally, the code itself must also be documentation that can be understood by those who may need to maintain it later or re-use it in another product. When the code is working well and passes all tests, prior to release I host a code review. In addition to inviting other programmers, I always invite non-coders who have the technical acumen to understand the problems the software tries to solve: If the code and its comments are not self-documenting to a significant degree, then I have failed to make a maintainable product. Which means *I* may be stuck maintaining it, rather than being able to move on to new projects!

    Documentation also has professional and ethical dimensions: My employer has commissioned and paid me to develop a product, and they deserve to recieve not only the final implementation, but also the means to maintain, re-use and re-engineer that product in the future. Anything that stays in my head becomes "lost" to my employer should I die or accept other employment.

    My obsession with all levels of documentation came from a mentor whose code at a prior employer became an issue in a law suit between his prior employer and one of their competitors. Because he was working at a third competitor, his then-current employer was able to prevent him from testifying, arguing that his prior code con

  54. I Was that Guy by ninetyninebottles · · Score: 1

    Not code documentation, but end user documentation was my gig for a while. At one point there were more Bugzilla entries from me (entered as I tried to use and document the software) than from the whole 15 person QA team put together. It was one of the experiences that drove me into software testing and then pen testing.

    More on topic for the article, my current employer implements extensive unit testing before any code is written (no really, I know lots of places say they do this, but it actually happens and is useful). Specifications are written by non-technical people and then tested and approved by those people before code is accepted. It also goes through a technical review and blackbox testing before acceptance. I'm not sure writing technical documentation would add a lot to the process, but I'd like to give it a shot and see how the experiment plays out. I'll bring it up next week and see if the team has any interest.

  55. Commenting vs. Review: A False Dichotomy by Capt.Albatross · · Score: 1

    Several commentators have said that reviews are better than comments, but this is no argument against commenting, as they are complementary and synergistic activities. I have found in practice that reviews without prior documentation are almost worthless, and generally not cost-effective.

    1) Having the author write down an explanation of her code saves the time of half a dozen reviewers trying to figure it out. This, alone, is justification enough for pre-review documenting.

    2) The alternative, having the author try to improvise an explanation in a review meeting, and have the reviewers follow along, leads to incorrect assumptions going overlooked or unchallenged, and may degenerate into confusion.

    3) As others have pointed out, the author is likely to find some errors as a result of documenting the reasoning behind her work, leading to fewer failed reviews, and consequently, fewer repeats.

    4) If the reviewers don't fully understand the whys and what-ifs of the code being reviewed, the exercise degenerates into a search for coding standards violations.

    5) Comments, if both relevant and correct, save a lot of time in future whenever that code needs to be understood. While this is not the most important case where this matters, it includes when reviewing changes to that code, and any other work where its correctness is conditional on the prior code. Having the commented code and other documentation being part of reviews helps meet the relevant and correct criteria.

  56. Obvious. by drolli · · Score: 1

    iff you document what a function *should* do, you *can* compare its projected behaviour to that.

  57. doctest by sad_ · · Score: 2
    --
    On a long enough timeline, the survival rate for everyone drops to zero.
  58. How to find bugs with a document by Caerdwyn · · Score: 1

    I call it a "test plan".

    1. Write test plan
    2. Hand it to developers for review
    3. Developers read test plan
    4. Developers consider factors, conditions and workflows spelled out in test cases that they hadn't thought of before, because they are developers not QA engineers (if a developer were capable of doing what I do, they would never have written into code the bugs that I find. Developers are not, and never will be, superior to QA engineers. Life lesson, prima donnas: QA saves you from yourselves.)
    5. Developers examine their code with these new insights
    6. Developers fix bugs in the code, prompted by the document (test plan)

    I realize this all breaks down at step 3, but I can dream.

    --
    Everybody gets what the majority deserves.
  59. In my day... by kenh · · Score: 1

    In my day we called this "Requirements". we wrote them before we wrote code, and we tested the code to make sure all the requirements were met.

    --
    Ken
    1. Re:In my day... by ArcadeNut · · Score: 1

      Mine too. Guess you can stay on my lawn.

      --
      Visit the Arcade Restoration Workshop @ http://www.arcaderestoration.com
  60. The cardboard dog by PuZZleDucK · · Score: 1

    I always thought this was just a joke: http://www.sjbaker.org/humor/cardboard_dog.html

    --
    Can a person program a new solution to a problem? Why should anyone be able to stop such a thing? -Richard Stallman
  61. Try writing code vs being an overpaid bullshitter by Anonymous Coward · · Score: 0

    Any programmer/analyst is capable of what you do which amazes me your title even exists at all. Same with most IT/IS/MIS "managers" who haven't written a line of code in their lives. Too much of that crap has gone on for decades.

  62. Using tomhudson to mod yourself up again? by Anonymous Coward · · Score: 0

    You know - the other account you use here to troll others with also?

    1. Re:Using tomhudson to mod yourself up again? by Anonymous Coward · · Score: 0

      barbara.hudson@unjava.com from http://slashdot.org/~Barbara%2C+not+Barbie = barbara.hudson@barbara-hudson.com from http://slashdot.org/~tomhudson proves that assertion. It'd be pretty easy to mod herself up with a 2nd account and to mod others down with it too.

  63. Barbara not Barbie has 2 reg'd accounts on /. by Anonymous Coward · · Score: 0

    barbara.hudson@barbara-hudson.com from http://slashdot.org/~tomhudson shows Barbara/Tom could pull off just what you've noted by keeping 2 registered accounts here. Spare mod points to downmod his/her detractors with and to upmod herself too.

  64. U R A troll that uses 2 /. registered accounts by Anonymous Coward · · Score: 0
    1. Re:U R A troll that uses 2 /. registered accounts by lostfayth · · Score: 1

      If this is the case, then you add nothing useful to the conversation, simply more noise. And despite, the opinion expressed by GP seems entirely valid, so you seem to be the only one not providing anything of value.

  65. You have 2 registered accounts for trolling on /.? by Anonymous Coward · · Score: 0
  66. STFU you troll with multiple registered accounts by Anonymous Coward · · Score: 0
  67. help by callmebill · · Score: 1

    When I write little utility programs, I start by writing the words that will come out with "--help".

  68. Documentation for good or evil.... ;-/ by lpq · · Score: 1

    That's good for little util progs, but for larger progs like 'bash' or 'vim', --help just doesn't cut it...

    Then there's issues about what is a bug and what is not. I've seen that used percolate down from committee's as well. Where incompatible changes are introduced, by say, POSIX, -- but that's ok, because, it's in the POSIX spec! (the latest rev of it, that is...)..

    Documentation can be used as a spec -- or it can be used to document bugs or inconsistent changes as a means of supporting the change.

  69. Think about those who support your software by GrantRobertson · · Score: 1

    As a former network manager (most of who's job was supporting various special purpose software products) I can tell you that I got sick to death of supporting software where it was obvious that design decisions were based on what the programmer knew he could do easily. Sure, you wrote a program that could do "D" but my users had to go through "W" then "L" and then "R" to get there. Oh, it all made perfect sense from a programming perspective. I could easily see why a programmer would add that feature in that particular manner. But it made even educated users feel like idiots trying to figure out the logic of how they were supposed to do things. I have overheard minor religions being invented while users try to figure out why in the world they have to go through "W" then "L" and then "R" to just get to "D" when they are sitting at "C" right now. It was so bad that it is the major contributing factor for my decision to get out of the IT field. I got sick and tired of trying to make software just simply do what the vendor said it would do.

    So, I am a firm believer in writing the USER documentation before writing a single line of code. If you can't explain how a user is supposed to get from "C" to "D" in a simple, coherent, manner which is somewhat consistent with how they got from "B" to "C" then you aren't finished designing your program yet. Have your grandmother read the manual. If it doesn't make sense to her then you got more work to do. Sure, your code may be elegant, with clojures and functional programming all over the place. Your class structure may be the envy of all who maintain it. Sure you may be able to refactor the holy hell out of it and every bit of the code is reused three times. But if users can't use it then what the F is the point?