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

21 of 188 comments (clear)

  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 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?
    6. 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
    7. 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"
    8. 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.

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

  3. 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.
  4. 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.
  5. 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?
  6. 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!
  7. 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."
  8. 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.

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

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