Slashdot Mirror


The Importance of Commenting and Documenting Code?

mrtrumbe asks: "The company I work for is in the process of creating a development standard to be applied to all projects. The topics being considered range from dictating the formatting of the code (an issue on which there is widespread agreement), to creating a standard for commenting and documenting the code (a far more contentious issue). On the issue of commenting and documenting, there are two extreme views being considered with most employees' opinions falling somewhere between them." To comment, or not to comment. And if you do choose to comment, what's the best way to standardize it, company-wide? "The first view is that commenting and documentation will protect the firm from bad programmers or a programmer abruptly leaving, make the code far easier to understand to someone unfamiliar with the codebase, and are necessary for all public, private and test code. The opposing view is that there are more effective ways to mitigate the risk of bad and disappearing programmers (like mandated shared ownership of code and sufficient oversight), that comments are not necessary for clarity and can be dangerous if not kept up to date (which is considered likely), and that documentation is necessary only for public code. Where does Slashdot stand on this issue? Please share any success stories and recommendations for a company-wide standard on commenting and documentation of code.

203 comments

  1. doxygen by Intron · · Score: 1

    We just got rid of our out-of-date function headers and replaced them with doxygen-style comments. The function parameters, return values and called-by / calls information will now stay up to date, and the html reference output is handy.

    --
    Intron: the portion of DNA which expresses nothing useful.
    1. Re:doxygen by baadger · · Score: 2, Informative

      Doxygen is a documentation system for C++, C, Java, Objective-C, Python, IDL (Corba and Microsoft flavors) and to some extent PHP, C#, and D.

      No Perl? :(

    2. Re:doxygen by Ithika · · Score: 2, Funny

      Didn't you get the memo? - perl is self-documenting.

    3. Re:doxygen by Randolpho · · Score: 2, Informative

      Doxygen is nice because it standardizes a particular commentation style over multiple languages, so that whatever you use for a project (or within a project), you comment in roughly the same way, using the same commands, etc.

      Personally, however, I very much prefer the xml-oriented way of doing it found in Javadoc and .NET's comment/documentation scheme.

      --
      "Times have not become more violent. They have just become more televised."
      -Marilyn Manson
    4. Re:doxygen by renehollan · · Score: 1
      Heh.

      I once suggested this, at least for new code, at a former employer in Canada, was backed up by all other devs who would have to use it, and got the ideas shot down by our boss because he could not see the value in it over the cost of learning a new way to annotate code to be doxygen-friendly.

      Sigh.

      I didn't stay there very long.

      --
      You could've hired me.
  2. Are you mad? by voice_of_all_reason · · Score: 3, Funny

    Never comment your code. That way everyone needs to ask you for a fix when thinks break. Think of it as "employment insurance..."

    1. Re:Are you mad? by indifferent+children · · Score: 1

      No, feel free to comment your code (random gibberish works fine). But whatever you do, do not *read* comments in code and expect them to have any bearing on reality. Even if the comments accurately describe what a program was written to do (rare), someone will have changed the code and not the comments, or the comments and not the code. Save yourself a lot of time and asprin; if you want to know what the code does, read the code.

      --
      Censorship is telling a man he can't have a steak just because a baby can't chew it. --Mark Twain
    2. Re:Are you mad? by kpwoodr · · Score: 2, Interesting

      That works in some companies. But be careful, it can bite you in the ass.

      I recently took a promotion on another team within my company (a large Aeronautics firm). Because I was saddled with a high customer exposure product and given no support I am the guy that >"everyone needs to...ask for a fix when thinks [sic] break." I did an average job of commenting, I believe in using meaningful variable names to help self document the code. Lots of people I work with over comment ie: //Set i equal to 5
            i = 5; //get the element in the fifth slot of the array //array is zero based, so be sure and subtract 1 //from i beforehand
            int iBS = somebullshitarray[i-1]; //now that we have iBS we need to......

      I've also written and kept up to date several high level overview documents that help new developers get acquainted with the code quickly.

      Unfortunately, I was handed my transition plan for moving to my new team yesterday. The >"employment insurance" you speak of came in the form of a transition that is slated to last through March of 2007. So sure, I have a job for another year minimum, but it's the one I've been trying to escape for the last 2 years. Not to mention that my new salary won't kick in until after the 50/50 transition point in June.

      My point: Comments can be good if they are meaningful. If you are trying to protect yourself and your product to ensure it is maintainable, the best way is to ensure that more than one developer is familiar with each product. Always have a backup plan for one of your developers getting hit by a bus, or leaving for another team.

      --
      This sig has been removed pending an investigation.
  3. Don't comment or document by youngerpants · · Score: 0, Redundant

    For Gods sake man, you're just making so that you are easily replaced. Real men don't comment or document their code; instead we sit in high priced development contracts performing application support.

    1. Re:Don't comment or document by Bazzalisk · · Score: 1
      You still have a lot to learn on this subject.

      Real men comment their code misleadingly - which is much more confusing than no comments at all.

      --
      James P. Barrett
    2. Re:Don't comment or document by Anonymous Coward · · Score: 1
    3. Re:Don't comment or document by the+eric+conspiracy · · Score: 2, Funny

      Not only write misleading comments, but also write variable and method names both generically and misleadingly too. For example:

      ArrayList aStrPtr = new ArrayList()

      If you are writing in C or C++ use macros to transform your code to look like another language, but incorrectly:

      #def begin: }

      #def loop: if

      and so on

    4. Re:Don't comment or document by owlstead · · Score: 1

      Ugh, I hate to browse through undocumented code, especially if it is mine. It is hard enough finding things on my drive, the network drives and the various backups. Sure, it is all there, but where? Nope, commenting code it is.

    5. Re:Don't comment or document by TechieHermit · · Score: 2, Interesting

      A friend of mine told me a story about someone at a large engineering company here in the Northeast (details are being left vague to protect the guilty and/or insane). Here's what this amazing, completely mad person supposedly actually did:

      In a huge software project, he named every single variable after a notable warship in United States History. If the variable was really important, it would be named after the lead ship in a battle group, like for instance an aircraft carrier or (WWI era) a dreadnaught. If the variable was just a little local variable, it would be named after something tiny, like a P.T. boat. Variables that participated in the same battles were used in the same modules. Variables' relationships mirrored their relationships in real life, so for instance, one variable would be named after a destroyer and a helper variable would be named after a tender.

      Think about how utterly brilliant and devious this is!

      The ONLY people who would have any chance at all of understanding the program would be anal-retentive naval history buffs! And the scope of it was supposedly amazing. If my friend was to be believed, this was an old-fashioned, NON-OO, structured-programming project with hundreds or maybe thousands of variables, all spaghetti code, everything named after fucking BOATS!

      It's priceless.

    6. Re:Don't comment or document by trevick · · Score: 1

      If you aren't replaceable, you aren't promotable...

    7. Re:Don't comment or document by Anonymous Coward · · Score: 1, Interesting

      "The ONLY people who would have any chance at all of understanding the program would be anal-retentive naval history buffs! And the scope of it was supposedly amazing. If my friend was to be believed, this was an old-fashioned, NON-OO, structured-programming project with hundreds or maybe thousands of variables, all spaghetti code, everything named after fucking BOATS!"

      Intentional Programming would have dealt with that problem.

    8. Re:Don't comment or document by Anonymous Coward · · Score: 0
      Good job on copying the quote from the bottom of the page!

      (In all fairness, it is rather applicable here.)

    9. Re:Don't comment or document by B1 · · Score: 2, Insightful

      Replaceable you must be, or promoted you won't.

    10. Re:Don't comment or document by sglane81 · · Score: 1


      #def begin: }

      #def loop: if

      and so on


      This is wrong on so many levels. Time to implement this into my code.

      --
      This is the Internet. You can say "fuck" here. - AC
    11. Re:Don't comment or document by Nutria · · Score: 1

      The ONLY people who would have any chance at all of understanding the program would be anal-retentive naval history buffs! And the scope of it was supposedly amazing. If my friend was to be believed, this was an old-fashioned, NON-OO, structured-programming project with hundreds or maybe thousands of variables, all spaghetti code, everything named after fucking BOATS!

      This has to be an Urban Legend.

      Why? I heard something similar, back in my early programmer days. Since this was a mainframe COBOL shop in the late 80s, the project was a big COBOL system from the early 70s, and it was an ex-priest writing all variable names in latin.

      --
      "I don't know, therefore Aliens" Wafflebox1
  4. Documentation by bloodredsun · · Score: 3, Informative

    A brief decription of the object/class and then simple comments on any methods. That's a minimum but I would also go for single line comments for conceptually difficult peices of code that you know you will forget in a couple of weeks. Not overly rigorous but easy enough that people do follow it.

    A good model for me would be the Java SDK docs and the javadocs tool but that's just me.

    1. Re:Documentation by anomalous+cohort · · Score: 5, Insightful

      In addition, consider the following points.

      • Code comments are only one form of developer documentation. Other forms include design and discovery docs (e.g. UML) and change comments (e.g. this change fixes bug 2938). Put design/discovery docs in an Intranet collaboration site. Wiki or any CMS such as Plone are good technologies for this. Put change comments in your source code control system.
      • Code comments should answer why, not what. As stated elsewhere, commenting is not a replacement for compentency. Any compentent developer can read most business application style programming and figure out what is going on. What you cannot read from the code was that meeting where some influential user or other relevant stakeholder insisted on a certain approach or placed high value on a certain outcome.
      • Code comments should not insult the intelligence of your average programmer. If you are coding a simulated annealing or genetic programming algorithm, then providing a URL to the appropriate material in the code is sufficient. If you are looping through some recordset for search or data aggregation purposes (which is about 90% of your business application coding), then you don't really need to provide a comment to the affect that that is what you are doing.
    2. Re:Documentation by dkf · · Score: 2, Interesting
      An example of a useless comment:
      // Increment rc
      An example of a more useful comment:
      // Bump the reference count
      An example of a much more useful comment:
      // Bump the refcount to stop premature deallocation during the recursive call
      An example of an enormously useful comment:
      /* Bump the refcount to stop premature deallocation during the recursive call. [Bug 122345].
      * Watch out here, the fooble compiler V7 has a tendency to reorder instructions wrongly
      * so the obvious optimization results in a bizarre crash in production. [Bug 179981].
      * This is a candidate for improvement when we finally switch to V8 */
      "What" should be obvious from the code. "How" sometimes needs commenting. "Why" is the important one though. Even if the "why" is out of date, at least it records what someone intended at some point and that gives you at least a chance to maintain the code instead of having to relearn all the subtleties from scratch each time. And the "gotchas" should always be commented; documenting them elsewhere is good too, but putting them in the code makes sure that Joe "In a Hurry" Maintenance Coder (or yourself) three years down the line doesn't have to relearn all the subtleties you've just sweated blood to discover.
      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
  5. Fit-for-Purpose by redelm · · Score: 1
    The problem with standards is they confound things and treat them similarly. Each [software] project has different goals, expected lifetimes, maintainability and communications concerns. And sometimes subsections are different.

    About the only thing a good standard will do is present options, advantages and disadvantages, and require that an explicit decision be made after appropriate discussion.

    1. Re:Fit-for-Purpose by kpwoodr · · Score: 1

      A good way to solve this is to have a company-wide standard, and allow individual programs to determine how they will implement the standard based on what will work for their product.

      If you have 2 people working on a small web applet, you probably don't need to be implementing FAGAN. Likewise, development and QA go hand in hand, and should be defined to support the product being developed.

      --
      This sig has been removed pending an investigation.
  6. more standards... that'll fix it! by yagu · · Score: 4, Insightful

    Stop it! Stop it! Stop it! The Noise. Make it stop!

    No, seriously, you cannot comment your code and enforce that as policy. You can't impose standards and impose enforce that! It doesn't work.

    You either know how to program/code, and commenting is part of that, or you don't. Either your staff knows same or doesn't.

    Go ahead and establish "guidelines", you'll feel better. But I've been in this industry for over 20 years and applying "standards" for coding and "comments" has never worked.

    Write un-obfuscated code, have peer reviews and walkthroughs, and have staff that know how to create... It's really all you need.

    (As an anecdotal experience -- we had "standards" on a major project, and I accidentally created a Class without the proper capitalization. A peer came to me and confronted me on said transgression and wondered what I intended to do about it. I said I intended to let it slide and would try to be better in the future. He insisted we "fix" this problem and we spent (and I'm NOT making this up!) the next day's worth of time re-factoring the code (the IDE wasn't up to speed for this -- thanks Microsoft) to "correct" the "problem". Sigh)

    1. Re:more standards... that'll fix it! by oni · · Score: 4, Informative

      You either know how to program/code, and commenting is part of that, or you don't. Either your staff knows same or doesn't.

      Spot on!

      Write un-obfuscated code, have peer reviews and walkthroughs, and have staff that know how to create... It's really all you need.

      *stands up and cheers*

      I totally agree. You can't take someone who is, frankly, lazy and selfish - and that's what we're talking about here. Anybody can write code. When you write a comment, you are doing more than coding, you are developing a product, you are making sure that product is maintainable. You are helping people who will come after you, maybe years later, people you'll never meet. People who flat refuse to think that way are lazy and selfish - you can't take someone like that and make them comply. They are worthless. Just fire them.

      You need a business culture that values documentation. You need people who have maintained someone else's code. Those kind of people understand and care. The kind of people who have only ever written new stuff don't get it. They don't understand why this is important. They don't realize that the wiz-bang program they wrote today will have to be thrown away in a year or two when the boss asks for just one little button to be added. It will have to be thrown away because it'll be cheaper to rewrite it than to decode it and add the button. Some people just don't get that.

      Look, commenting is not rocket science. You don't need strict rules. A comment is a communication with someone in the future. It's like a time capsule. You just need to comment things when it's reasonable to think that a person looking at the code might need help. You don't need comments like //add one to x and store it in x. But you might need a comment like, //increment x because this procedure pushs the stack.

      In an interview with a prospective programmer ask the following question: "what is the most expensive part of the development lifecycle" If they say anything else except maintenance, don't give them a job. They don't get it. They aren't going to do it.

      I also want to add something to the story, where it says this:
      dictating the formatting of the code (an issue on which there is widespread agreement)

      I was thinking, "yeah right, there is widespread agreement on the idea, but when you sit down and try to do it you'll find widespread disagreement." Everybody likes the idea of forcing the other programmers to write code the same way that you do. Nobody likes the idea of having to write code a certain way. Where I work, there was widespread agreement too, but we never got past the issue of capitalizing the first letter of functions. Seriously.

      If I had to do it again, I would get some premade coding standards. Creating your own is too hard.

    2. Re:more standards... that'll fix it! by SlayerDave · · Score: 1
      He insisted we "fix" this problem and we spent (and I'm NOT making this up!) the next day's worth of time re-factoring the code (the IDE wasn't up to speed for this -- thanks Microsoft) to "correct" the "problem"

      I call bullshit. Visual Studio is easily capable of doing a find-and-replace over the entire project (try CTRL-H). It shouldn't have taken you more than 30 seconds to fix this problem. If you spent the entire day "re-factoring" then you obviously had more serious problems than a simple deviation from the capitalization standard.

    3. Re:more standards... that'll fix it! by carlos92 · · Score: 1

      Better make it a standard to document/peer review designs, specially if you are doing OOD/OOP. You DO design before you code, do you?

    4. Re:more standards... that'll fix it! by Wisgary · · Score: 0

      definitely fucking agree, wtf, an entire day just doing a find and replace? Even if it was a common word that could be contained in other lines of code and you had to manually look for it, clicking next next replace next replace etc etc, and it was a HUGE project, if you did a find and replace across it, it shouldn't take an ENTIRE DAY.

    5. Re:more standards... that'll fix it! by badfish99 · · Score: 1
      The company I work for has a "standard" that says "every method you write must have a comment".
      So our code has hundreds of methods called things like getFoo() and setFoo() with comments like "this returns the value of foo" or " this sets the value of foo".
      By the time you've written all these useless comments, you're too tired to write a single useful comment that explains how the code works.

      In any case, code is always obvious when you've writing it. So it's hard to know what comment would be needed to make it clear to someone who wasn't familiar with it. Maybe comments should always be written by someone other than the author of the code?

    6. Re:more standards... that'll fix it! by Trepalium · · Score: 1

      Unless it was in source control, where you had to take a lock on each file you wanted to modify. Getting locks released on the various files you needed to change could take a good amount of time depending on how easy it is to track down the lock owners.

      --
      I used up all my sick days, so I'm calling in dead.
    7. Re:more standards... that'll fix it! by PianoComp81 · · Score: 1
      The company I work for has a "standard" that says "every method you write must have a comment". So our code has hundreds of methods called things like getFoo() and setFoo() with comments like "this returns the value of foo" or " this sets the value of foo". By the time you've written all these useless comments, you're too tired to write a single useful comment that explains how the code works.
      There are programs out there for auto-commenting get/set methods. Heck, there are programs that'll create basic get/set methods from your class variables and comment the functions at the same time.
      In any case, code is always obvious when you've writing it. So it's hard to know what comment would be needed to make it clear to someone who wasn't familiar with it. Maybe comments should always be written by someone other than the author of the code?
      Instead, write your code, comment as you think it should be, and then send it out via e-mail for review. If you don't have enough comments, you'll get e-mail back saying "this needs comments here, here, and here". It works well. Usually, you don't have to change anything, but every once in a while, you miss a comment or something you think is obvious is not obvious to others.
    8. Re:more standards... that'll fix it! by Mr.+Slippery · · Score: 1
      In any case, code is always obvious when you've writing it.

      Hmm. What field do you work in where you always write trivial code?

      --
      Tom Swiss | the infamous tms | my blog
      You cannot wash away blood with blood
    9. Re:more standards... that'll fix it! by codeboost · · Score: 1

      Documentation is important, but it shouldn't be the only reason for hiring or firing programmers.
      Many smart programmers tend to be ego-centric and/or megalomaniacal with a set of strange beliefs. For instance, some exceptionally smart hackers think that good programmers should read the code, not the comments.
      Although they don't write good comments, these are the guys you want to have working for you.
      But then of course, it depends on the project.
      Not all tasks require genius hackers with a personality disorder.
      Laziness and selfishness are not determined just by how many comments programmers write, but by the quality of their job.
      Just my opinion.

    10. Re:more standards... that'll fix it! by WGR · · Score: 2, Insightful
      In a proper software project, comments are written before the code so they should not be written by the coder. They should reflect the block of the system design that the routine implements, the assumptions made during design etc. It should capture the design so a maintainer can avoid changing the design unintentionally.

      A comment should be there to tell a future maintainer why this code exists, what was the intent and its reason for existence. It does not exist to tell how the routine is implemented, so it should seldom have action verbs.

      The other useful kind of comment is the expansion of variable type declaration that describes the constraints on a variable that are not expressible in code.

    11. Re:more standards... that'll fix it! by oni · · Score: 1

      Laziness and selfishness are not determined just by how many comments programmers write, but by the quality of their job.

      In my opinion, a large part of the quality of a job is how long it lasts. It's like a bridge. I don't care if you build me a beautiful bridge today, if I have to throw it away in two years and build a whole new bridge, it's worthless to me. I want something that lasts.

      For code to last, it has to be maintainable. The single largest factor in determining what is maintainable is documentation.

      Many, many times I've been asked to look at something and advise as to the possibility of adding new features. Frequently I have to report back that the system is so horrible that messing with it will cause more problems than it will solve. Maybe you don't believe me? That's ok, there are people here at work that don't believe me too. So they take on the project, and 9 times out of 10 they end up regretting it, because they just have to rewrite the whole thing from scratch.

      Code that isn't maintainable is practically worthless. In the modern world, things change so fast. You have to anticipate the need to add features to a software project. You have to anticipate it and build it so that changes are possible.

    12. Re:more standards... that'll fix it! by Anonymous Coward · · Score: 0

      I agree with the parent that modifying capitalization across a project shouldn't take a day, but I disagree with the idea of using search and replace. Here's how you should do it:

      Step 1: Make sure it compiles without errors. (This is a given if you were about to check it in).
      Step 2: Make sure that the name you're going to use is unique (use find and grep).
      Step 3: Go to the header where the symbol is defined and rename the symbol.
      Step 4: Compile with make -k; fix errors; repeat until it compiles without errors.
      Step 5: Go get your morning coffee (this task shouldn't take more than about 20 minutes if your source code is properly factored).

    13. Re:more standards... that'll fix it! by pthisis · · Score: 1

      Step 1: Make sure it compiles without errors. (This is a given if you were about to check it in).
      Step 2: Make sure that the name you're going to use is unique (use find and grep).
      Step 3: Go to the header where the symbol is defined and rename the symbol.
      Step 4: Compile with make -k; fix errors; repeat until it compiles without errors.


      Good luck modifying code in a dynamically typed language that way (Python, Perl, Ruby, Smalltalk, etc). Just use a refactoring tool (a la BicycleRepairMan for Python).

      --
      rage, rage against the dying of the light
    14. Re:more standards... that'll fix it! by Solemn+Bob · · Score: 1
      There are programs out there for auto-commenting get/set methods. Heck, there are programs that'll create basic get/set methods from your class variables and comment the functions at the same time.
      Right. And those auto-generated comments are always useless. By their very nature, they can't add any information or insight that's not already in the function signature. They are completely without value. I delete them with extreme prejudice (i.e., while swearing at the guy who cluttered up the code with that crap in the first place).
    15. Re:more standards... that'll fix it! by badfish99 · · Score: 1
      Computer programming. Not rocket science.

      Of course it's easy when you're familiar with what you're doing. You only need comments when you (or someone else) goes back to look at the code later - perhaps years later - to fix a bug. Then the bug fixer needs to get up to speed with what the code is doing. So the most useful comments would be those put in by someone who was unfamiliar with the code and was trying to understand what it did, because this is just the information that the future bug fixer would need.

    16. Re:more standards... that'll fix it! by mattpalmer1086 · · Score: 1

      I've worked in places with coding standards and without. Believe it or not, the places that had coding standards were much more fun places to be. But they were appropriate standards, not standards-for-the-sake-of-having-a-standard standards.

      I can believe that standards which are imposed without any rhyme or reason, or that are just there because management think they are a good thing, won't work. But not having standards at all is not the solution to having bad standards. And standards are not the solution to having bad programmers either. Standardising common things can be useful if applied sensibly.

      A simple example: in one place I worked, anyone who had to fix a problem quickly, for whatever reason, put a KLUDGE comment in the code, with a short explanation if necessary. This was an invaluable standard and required no enforcement. It was too useful for all of us later on to be able to see why this bit of code wasn't quite right and why.

    17. Re:more standards... that'll fix it! by PianoComp81 · · Score: 1
      And those auto-generated comments are always useless.
      But look at what the parent said:
      So our code has hundreds of methods called things like getFoo() and setFoo() with comments like "this returns the value of foo" or " this sets the value of foo".

      These comments are just as useless as autogenerated comments, so why not use them?
    18. Re:more standards... that'll fix it! by Anonymous Coward · · Score: 0

      That's bunk, all of it.
      I know that programmers like to think of themselves as samurai, artisans of code, or other such nonsense whose creativity and time can't be spent doing trivial things like documentation, but that's a terrible business practice. Standards are important because they give you a good reason to confront sloppy coders, a way to train new people on a codebase, and a searchable archive of bugfixes. Yes it's time consuming, yes it somewhat menial, but for code that is expected to have any kind of productive lifespan, it needs to be maintainable by anybody. If people don't update their comments with their code, go back and make them during a peer review. If they refuse or get self righteous, let them go, your product will be stronger in the long run without them and their dramatic baggage

    19. Re:more standards... that'll fix it! by ldspartan · · Score: 1
      You either know how to program/code, and commenting is part of that, or you don't. Either your staff knows same or doesn't.

      Yes. Its completely binary. We are either all Dijkstra's or wet salmon. There are no mediocre programmers in the world, and more so there is a glut of brilliant programmers and its trivial to fill a team with them. Plus, once you do, they all agree and get along and are productive!

      Christ.
  7. Are you serious? by zhobson · · Score: 5, Interesting

    If your code is not commented it's not complete. My advice is to fire every developer that doesn't think that comments are necessary.

    1. Re:Are you serious? by Rakshasa+Taisab · · Score: 2, Insightful

      Ops, you just lost all the developers who manage to write code that is so clear it doesn't need comments.

      --
      - These characters were randomly selected.
    2. Re:Are you serious? by NathanBFH · · Score: 3, Insightful

      For significantly complicated projects, those programmers don't exist. If you think commenting your code is an unreasonable job requirement, I will fire you.

    3. Re:Are you serious? by Grab · · Score: 1

      No such code exists. There are *portions* of code that don't need comments, but the code in general *will*.

      Grab.

    4. Re:Are you serious? by gnovos · · Score: 2, Insightful

      For significantly complicated projects, those programmers don't exist. If you think commenting your code is an unreasonable job requirement, I will fire you.

      I have yet to see a project, in 11 years of coding, that is so complex that comments are a REQUIREMENT. If you don't know how to refactor, and how to reduce your bloated thousand-line long methods into a series of simple to understand 10-line long methods, you still have much to learn about good code.

      --
      "Your superior intellect is no match for our puny weapons!"
    5. Re:Are you serious? by Randolpho · · Score: 2, Insightful

      Even if you're the best normalizer/refactorer (is "refactorer" a word?) in the world, you had better explain what a function or method or class or aspect or (etc..) does, how it's used, and what the expected results are, or you have made code that is a nightmare to maintain.

      In truth, function-point comments of a well-normalized/refactored program represent easily 99% of the necessary commentation for a program. The only time you ever really need comments otherwise is to explain a particularly tricky algorithm that, say for performance reasons, must resist typical normalization/refactoring. Even then, you can easily place an overview of the algorithm in the documentation (or reference a whitepaper), and again remove most of your inline comments.

      As for function-point comments/documentation, I suggest something like Javadoc, C#'s Intellidoc, or some similar platform like doxygen, although if you're manly or insane enough, you can always maintain the documentation separate from the code.

      --
      "Times have not become more violent. They have just become more televised."
      -Marilyn Manson
    6. Re:Are you serious? by gnovos · · Score: 2, Insightful

      Even if you're the best normalizer/refactorer (is "refactorer" a word?) in the world, you had better explain what a function or method or class or aspect or (etc..) does, how it's used, and what the expected results are, or you have made code that is a nightmare to maintain.

      That is what your automated tests are for! No comment in the world is better than a test showing exactly how a method works, what expected inputs and outputs are, and *proving* that what you think it should do is what it actually does. The great thing about proper automated tests, they can NEVER go out of date and still pass.

      --
      "Your superior intellect is no match for our puny weapons!"
    7. Re:Are you serious? by blincoln · · Score: 1

      If your code is not commented it's not complete. My advice is to fire every developer that doesn't think that comments are necessary.

      Seriously.

      I code C# for fun, on my own. I still comment, because otherwise when I go to look at it in a year or two, I will have forgotten the reasoning behind some of my decisions.

      I do a bit of it at work too. I'm an engineer there, but a few people in my group use ASP, ASP.NET, and VB.NET to write simple utility apps. Trying to work with their code is a *nightmare* because there are few if any comments. There's just too many different ways to write program logic for it to be guaranteed that the next person who comes along will be able to quickly figure it out just because they know the language.

      I'm not bad at reverse-engineering. I taught myself basic MIPS assembly so I could hack the PS2 versions of the Legacy of Kain games. It's certainly *possible* for me to eventually figure out someone else's code, no matter how badly-written it was, but if they had commented it I wouldn't waste time on understanding instead of changing.

      If anyone is thinking "dude, you're just an engineer, developers write better code," you're wrong. I've looked at the source code for our internally-developed apps a few times, and it was frequently as bad. Allegedly since those apps were written, the development groups have started requiring comments - with exceptions for things like "//increment i" and "//iterate through the recordset" kind of stuff.

      --
      "...always new atoms but always doing the same dance, remembering what the dance was yesterday." -Richard Feynman
    8. Re:Are you serious? by Metasquares · · Score: 1

      Don't assume that everyone who will read the code will want to figure out what the tests are doing as well.

    9. Re:Are you serious? by Mr.+Slippery · · Score: 1
      If you don't know how to refactor, and how to reduce your bloated thousand-line long methods into a series of simple to understand 10-line long methods, you still have much to learn about good code.

      If you think that the sole, or even primary, measure of how simple to understand a module is, is the length of the functions or methods, then you still have much to learn about good code.

      (For example, I've sometimes found myself refactoring code from a bunch of sort, tightly-coupled routines into one single one to create better encapsultion.)

      --
      Tom Swiss | the infamous tms | my blog
      You cannot wash away blood with blood
    10. Re:Are you serious? by Metasquares · · Score: 1
      You aren't commenting your code (else you'd see a lot of "c++; //increment c" stuff); you're commenting your logic.

      Maybe the code is self-documenting, but program logic for any reasonably complex problem is not. I don't care how much you've abstracted it; you still need to show how you're using those abstract pieces to solve the problem you're given. You still need comments.

      If the developers refuse to comment their code on this basis, I'd probably get someone of average intelligence from sales or HR to read it and explain what it does. If he can't do so, the developer either starts commenting or looks for a new job.

    11. Re:Are you serious? by gnovos · · Score: 1

      Of course they will, if they want to use it properly. Why assume somone will read comments but not read the tests?

      --
      "Your superior intellect is no match for our puny weapons!"
    12. Re:Are you serious? by gnovos · · Score: 1

      For example, I've sometimes found myself refactoring code from a bunch of sort, tightly-coupled routines into one single one to create better encapsultion.

      Good job! Excellent first step. But are you finished? I'm sure you could find a way to reduce that complexity even further if you spent more time one in.

      In my experience, code is very fluid. It can grow and shrink over time, and almost exclusivly, the smaller it becomes, the more readable it becomes... And the more REUSABLE it becomes! The more you reuse code, the fewer overall bugs you will have, the easier it is to continue coding, and the better your code gets.

      --
      "Your superior intellect is no match for our puny weapons!"
    13. Re:Are you serious? by Metasquares · · Score: 2, Interesting

      The same reason that some people only read half of a long email: They think they've read "enough" to get the "gist" of it, even if they miss something like "your default password is your last name" at the bottom. Ideally, you probably want an explanation of what the code does as near to the code itself as possible.

      I had a friend who used to refer us to his tests whenever we had a question about his code. They were his only form of documentation. He didn't believe in submitting the tests with the program itself or sharing them with other developers, so no one could ever understand what he was doing. Unsurprisingly, when it came time to integrate his code, whole projects fell apart because no one could figure out how to cleanly integrate his code into the logic of the larger program.

    14. Re:Are you serious? by AuMatar · · Score: 1

      There's no such thing as code which is so clear it does not need comments. If there's a developer who thinks his is, he needs to have his head removed from his ass.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    15. Re:Are you serious? by AuMatar · · Score: 2, Interesting

      And here is one of the reasons the agile method people get so much wrong. Automatic tests are not documentation, by any means. They do not prove that code is correct, or bug free. A test proves that for some input, a certain output was generated. Thats it. It doesn't explain why that output was generated, why that case was important, what other cases might be important, how those test cases were chosen, or explain the logic used to generate that output. For that you need documentation- either in code or out of code. Automatic tests have their place, but they are not equal to design or documentation. Any place that uses them as such is producing shitty software which will bite them on the ass when the original devs leave.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    16. Re:Are you serious? by Randolpho · · Score: 1

      Automated tests do not grant context. Only non-structured narrative documentation can fully explain the purpose and use of a block of code.

      --
      "Times have not become more violent. They have just become more televised."
      -Marilyn Manson
    17. Re:Are you serious? by gnovos · · Score: 1

      And here is one of the reasons the agile method people get so much wrong. Automatic tests are not documentation, by any means. They do not prove that code is correct, or bug free. A test proves that for some input, a certain output was generated. Thats it. It doesn't explain why that output was generated, why that case was important, what other cases might be important, how those test cases were chosen, or explain the logic used to generate that output. For that you need documentation- either in code or out of code. Automatic tests have their place, but they are not equal to design or documentation. Any place that uses them as such is producing shitty software which will bite them on the ass when the original devs leave.

      It sounds like the agile developrs you have run into aren't doing thier jobs particularly well, or perhaps not understanding thier systems very well... Automated tests tell you exactly what is there, nothing more. It tells you, as you said, for inputs X, Y and Z you get outputs A, B, and C. However, if they are doing thier tests correctly, then they are basing those tests directly off of user/customer requirements, so what more do you need? If a custormer needs somethng that produces X, then proving that the method/class/system produces X, then it doesn't matter how it arrived at that position. The test doesn't tell you "why", but what use is this information?

      All the documentation in the world can do is tell you, at a particular place in time, what somebody wishes would exist, or thinks does exist. Documentation can absolutly NOT tell you "why that output was generated, why that case was important, what other cases might be important, how those test cases were chosen, or explain the logic used to generate that output". It can tell you what somone assumes or knows at the point that it is written, but who knows about NOW? Assumptions change, reasoning changes, algorithms are refined, thrown out, and completely rewritten from scratch every day. In order to learn the "truth" of the matter that you have to go back into the code itself, to the developers, to the customers.

      If you just trust the documentation you will be in a FAR more dangerous position that someone who is forced, by agile methods, to go back, constantly, to the source of the information and get the real, up-to-the minute details.

      The problem, I guess, is trying to describe agile methods to a culture that simply is not prepared to change enough to accept them. Agile development is a complete restucturing of information flow, it's systemic, not just another guidebooks for the programmers to follow. If it's not being reflected in the entire organization from the coders themselves, to the sales department, to the marketroids, to the top brass, then it will quickly be "proven" a house of cards and you'll be very unimpressed with the results. It's a great system, but not one to implement half-heartedly.

      --
      "Your superior intellect is no match for our puny weapons!"
    18. Re:Are you serious? by gnovos · · Score: 1

      He didn't believe in submitting the tests with the program itself or sharing them with other developers, so no one could ever understand what he was doing.

      Come on, there is no way any sort of documentation could have helped this kind of problem... If he isn't willing to submit his tests, what chance is there he'll submit his documentation?

      --
      "Your superior intellect is no match for our puny weapons!"
    19. Re:Are you serious? by gnovos · · Score: 1

      Automated tests do not grant context. Only non-structured narrative documentation can fully explain the purpose and use of a block of code.

      Do you want your code to me modular and reusable? If so, what good is context?

      --
      "Your superior intellect is no match for our puny weapons!"
    20. Re:Are you serious? by Mr.+Slippery · · Score: 1
      Excellent first step. But are you finished? I'm sure you could find a way to reduce that complexity even further if you spent more time one in.

      Of course there was more. I think I ended up shrinking the entire code base on that project by at least ten percent. It was pretty "object-obfuscated" when I got ahold of it, I cleaned up the class hierarchy, factored out some common code, et cetera.

      But the issue is the statement that a bunch of short routines are more easily understood than one long one. If you have to jump around six different subroutines to see how some functionality is implemented, that's not necessarily easier to understand than one larger routine.

      A routine should be as long as it needs to be to accomplish its function; sometimes that means 1,000 lines nicely encapsulated in one "box" of a routine, rather than a bunch of little boxes tied together.

      --
      Tom Swiss | the infamous tms | my blog
      You cannot wash away blood with blood
    21. Re:Are you serious? by gnovos · · Score: 1

      of course, all of this only really applies to junior developers. If you stick with the rule "simpler, shorter is better" you can almost never go wrong. Once you find out where you can go wrong, you may not need that rule any more.

      --
      "Your superior intellect is no match for our puny weapons!"
    22. Re:Are you serious? by BobNET · · Score: 1

      Good luck in figuring out what the uncommented code does after the programmer is gone, then...

    23. Re:Are you serious? by AuMatar · · Score: 1
      Documentation can absolutly NOT tell you "why that output was generated, why that case was important, what other cases might be important, how those test cases were chosen, or explain the logic used to generate that output".


      No, thats ABSOLUTELY what documentation tells you. It tells you what a function is for, and what the expected output is. Your test cases should be documented as well, wether they be automatic or not- why was this test case chosen (corner case? random pick? check some bug we just fixed and want to watch out for in the future?). If your documentation is NOT telling you this, you and your team fail.

      Assumptions change, reasoning changes, algorithms are refined, thrown out, and completely rewritten from scratch every day.


      And when this happens, the FIRST thing you do is change the documentation to reflect that. If you don't, you aren't doing your job.


      If you just trust the documentation you will be in a FAR more dangerous position that someone who is forced, by agile methods, to go back, constantly, to the source of the information and get the real, up-to-the minute details.


      If you work someplace that is so sloppy you get into the positions you claim, maybe. But if your workplace is that sloppy, agile methods will be even worse-if you have devs who are so incompetent that they can't update plain text, I shudder to think of what their code looks like.

      Unit tests are not design. They are not documentation. They can help a well designed and documented program by finding bugs early, and thus are a good thing. But if you make me pick one to drop, it'd be the unit tests in an instant.
      --
      I still have more fans than freaks. WTF is wrong with you people?
    24. Re:Are you serious? by Randolpho · · Score: 1

      Good context for modular and reusable code include things like the the purpose for class. Is the class a custom GUI control, a data object, a control/worker object? What does the data represent? What does the worker object do? What does your control allow users to do?

      Of course, that's modular-level, but the same must be done on the method level and lower. What does this method do? Does it animate a portion of the control in some way? Does it maniplate the data to a new state? What do the arguments represent? Is x in screen coordinates, container/control coordinates, 3d coordinates?

      None of this information can be readily obtained from source code or test cases without careful analysis, and even then a deep understanding of the underlying APIs is necessary, which of course requires, you guessed it, the same context.

      --
      "Times have not become more violent. They have just become more televised."
      -Marilyn Manson
    25. Re:Are you serious? by Arandir · · Score: 1

      In 21 years of coding, I have yet to see a project so simple that comments were not required. If you don't know how to write a comment, you have no business coding. If you cannot take the time to comment, you have no business coding. If you think comments are stupid, you have no business coding.

      --
      A Government Is a Body of People, Usually Notably Ungoverned
    26. Re:Are you serious? by gnovos · · Score: 2, Interesting

      No, thats ABSOLUTELY what documentation tells you. It tells you what a function is for, and what the expected output is.

      Does your function exist for a single purpose? Is it ever going to be reused? The problem with saying what a function is FOR (what you see in documentation) as opposed to what it DOES (which you see in code and tests) is that it assumes many thing that may or may not be correct. It also will breed duplication, as you may implement one method fome one "purpose" and another method for another "purpose" where actually they are exactly the same code, just with different names.

      Your test cases should be documented as well, wether they be automatic or not- why was this test case chosen (corner case? random pick? check some bug we just fixed and want to watch out for in the future?). If your documentation is NOT telling you this, you and your team fail.

      Easily solved with Good Names... testDoFooCornerCase(), testDoFooRandomlyChosenVariables(), testDoFooFailsWhenValueIsNineBug()

      Assumptions change, reasoning changes, algorithms are refined, thrown out, and completely rewritten from scratch every day.
      And when this happens, the FIRST thing you do is change the documentation to reflect that. If you don't, you aren't doing your job.


      Well, the first thing I wonder is what kind of state is your documentation in when you've just changed it to reflect your new assumptions but haven't gotten around to fixing the code yet? Which do you believe, the documentation, or the code, both of which are out of sync?

      But most importantly, are you expecting every developer to a) memorize all documentation, Chapeter and Verse or B) go through every page of the documentation before implementing new assumptions? Because if you plan to change the documentation when you change your reasoning, you'll have to go through every piece of documentation to see if it has any relation to the change you are goign to implement. With a full suite of automated tests, you can make those changes where you assume they should go, and run the tests and see what other part break... With human-readable documentation you'll have to check it all manually, and carefully, because who knows what dependancies are there that you never suspected?

      If you just trust the documentation you will be in a FAR more dangerous position that someone who is forced, by agile methods, to go back, constantly, to the source of the information and get the real, up-to-the minute details.

      If you work someplace that is so sloppy you get into the positions you claim, maybe. But if your workplace is that sloppy, agile methods will be even worse-if you have devs who are so incompetent that they can't update plain text, I shudder to think of what their code looks like.


      As I mentioned above, it has nothing to do with being sloppy... Sure, you can update the bits of documentation that you know about, but you can't know all the constantly changing documentation that is there, without a huge non-productive time-sink... And if you think you work somewhere that does this well, I suggest you take a closer look at your code base. There are guaranteed to be out-of-date comments in whatever code-base you are currently working on, it's unavoidable, it's pure entropy you're battling against.

      Unit tests are not design. They are not documentation. They can help a well designed and documented program by finding bugs early, and thus are a good thing. But if you make me pick one to drop, it'd be the unit tests in an instant.

      Unit tests (and funtional/integration tests, which are really just larger scoped "unit" tests) are absolutly design, if you want them to be. They are the BEST design, in fact, because they are design that can't be incompatible with the code-base, and a design that can prove all of your assumptions. They are proof of quality, or proof of the lack thereof. Writing testable code even forces you to use good encapsulation and proper obje

      --
      "Your superior intellect is no match for our puny weapons!"
    27. Re:Are you serious? by gnovos · · Score: 2, Interesting

      In 21 years of coding, I have yet to see a project so simple that comments were not required. If you don't know how to write a comment, you have no business coding. If you cannot take the time to comment, you have no business coding. If you think comments are stupid, you have no business coding.

      In your 21 years have you ever seen a project built and run for several years, adding new features every week, never slip a single deadline, all without a single bug of any kind making it into production? I've two such projects, and both of them were using XP methedologies with less than four or five well-placed comments in the entire code-base.

      --
      "Your superior intellect is no match for our puny weapons!"
    28. Re:Are you serious? by gnovos · · Score: 1

      Good context for modular and reusable code include things like the the purpose for class. Is the class a custom GUI control, a data object, a control/worker object? What does the data represent? What does the worker object do? What does your control allow users to do?

      Of course, that's modular-level, but the same must be done on the method level and lower. What does this method do? Does it animate a portion of the control in some way? Does it maniplate the data to a new state? What do the arguments represent? Is x in screen coordinates, container/control coordinates, 3d coordinates?

      None of this information can be readily obtained from source code or test cases without careful analysis, and even then a deep understanding of the underlying APIs is necessary, which of course requires, you guessed it, the same context.


      What seems to not make it across is that anything that cannot be expressed in code cannot be expressed in documentation either.

      "Is x in screen coordinates, container/control coordinates, 3d coordinates?" can be addressed "in code" as simply as:

      int xOnScreen = 5;
      int xFromContainer = 7;

      But neither of which will be any more "true" in documentation or code form unless you have a test showing you take X out of the graphics plane, or out of the container, etc, and using that X in the method. Once you have that, then what good is the documentation except sucking time away from programmers?

      Good tests should indeed show the code-context in which it is intended to be used. Good functional tests will include tests from the user-perspective as well, showing how a user will interact with the system, providing you all the context you need to mantain and use the code.

      As long as you can show how the user will use the system, and show that the answers that he gets are the ones you expect, for every feature that the system is designed for, what more do you need?

      --
      "Your superior intellect is no match for our puny weapons!"
    29. Re:Are you serious? by Wonko · · Score: 1

      And when this happens, the FIRST thing you do is change the documentation to reflect that. If you don't, you aren't doing your job.

      I Am A Useless Programmer, but... :p

      I would imagine it is very easy to either not update documentation/comments, or to update them incorrectly. It would be much harder to make that mistake with automated testing. Comments don't fail, tests do :).

      But if your workplace is that sloppy, agile methods will be even worse-if you have devs who are so incompetent that they can't update plain text, I shudder to think of what their code looks like.

      Everyone makes mistakes. If you make a mistake in your code it will be caught by the compiler, the test suite, or possibly by noticing incorrect output. If you make your error is in your comment it won't be caught until someone notices the discrepency.

      I prefer any system that is able to check itself for errors. I don't think comments are useless, I am just not sure how much they should be trusted :).

    30. Re:Are you serious? by AuMatar · · Score: 1

      Oh sure, its possible to forget or make mistakes. Then the next person comes around and sees they don't match. One of them is wrong. Figure out which and fix it.

      As for not getting automated tests wrong- boy would you be surprised. Its actually quite easy, and when you do it can be difficult to debug- you look everywhere else for the problem first "because it passed the tests". I don't trust the tests much due to that.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    31. Re:Are you serious? by Anonymous+Brave+Guy · · Score: 4, Interesting

      I've read all the other replies to this comment at the time of writing, and it's a fascinating discussion. Initially I thought you were just a troll, given that you claim to have produced completely bug-free projects and never to use comments, but now I think you've just had a little too much of the agile kool-aid, so I'll address some recurring points one by one.

      On the trustworthiness of documentation (comments, paper or otherwise): no, you shouldn't absolutely trust them above all else. The final authority about what is happening is always the code. But if your documentation is any good at all, it's not the sort of thing that you refer to last, it's the sort of thing you refer to first. The documentation isn't the implementation, it's just a map of it, telling you what should be happening. Comments are the guidebook, highlighting the major attractions as you reach them and pointing out the subtleties that aren't apparent at first.

      The most successful projects I've worked on have relatively little documentation, but it's well-written and useful. My current project, for example, has perhaps 200,000 lines of code. We have maybe 20-30 reference documents, each electronic and running only to a handful of pages, describing the overall design of the major subsystems and broadly speaking how they're intended to interact. The implementation speaks for itself, with explicit comments generally reserved for things like dividing up longer functions into logical sections, citing references that describe how the algorithm works (from our own documentation or otherwise), or clarifying intent on the odd occasion that the code isn't completely self-documenting. Notice that none of these things, except possibly the last, are likely to need amending just because you change the code.

      You also seem to be arguing that it is unnecessary to maintain any sort of coherent overall design in an "agile" project, because your automated tests guarantee correctness. Sorry, but I think you're seriously misguided on both counts.

      Automated tests are a useful mechanism for increasing reliability, but they're no substitute for a logical design, code review, or any of the other things that contribute to code quality. Unless your tests cover every code path with every conceivable set of inputs, they simply can't do that. My current project has an automated test suite that runs to 1,000s of tests, and yes, they're very useful for spotting major errors and regressions, but they still don't catch anything like all the bugs. No test suite for a large scale application ever has 100% coverage. And even if the test suite does pass in its entirety, it's no guarantee that you got the answer the way you intended and all your code is working. Two wrongs do make a right, if you incorrectly multiplied by -1 twice.

      As for the presence or otherwise of an over-arching design, what you say is true: your code and tests are indeed guaranteed to give you the results your tests say you will get for as long as the tests pass. Of course, that doesn't mean that you can easily extend, modify or reuse that code. In fact, my experience of projects developed with the methodology you describe is that they're written very quickly, but rapidly become almost unmaintainable; someone will find a bug that your tests didn't, and you'll dutifully write a new test, and then it will take you a week to refactor this and elevate that until you can get the test to pass without breaking anything else. The guys who had a carefully planned, well-maintained and systematic design would probably have fixed that bug in five minutes, and without breaking anything else, because the problem would have been localised, easy to track down, and unable to adversely affect other areas of the system.

      Speaking of code reuse, I notice that you're very keen not to bring context into things. I hate to break this to you, but code without context is meaningless, no matter how "reusable" it may be. When context starts to interfere with your reality, a lot of

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    32. Re:Are you serious? by macshit · · Score: 1

      What seems to not make it across is that anything that cannot be expressed in code cannot be expressed in documentation either.

      Do you really think that? However great your code is, it inevitably is going to contain assumptions and higher-level structure; for readers to fully understand the code, they have to know about them, and simple english text is a concise and powerful way of communicating that information.

      An example might be a comment saying: "This code uses algorithm X, which was picked because it has the following properties in the following situations, which are important in the context of this code because ..."

      Obviously there is a lot of straight-forward low-level code that simply doesn't need commenting if you write it well, but it seems bizarre to think that comments are altogether unnecessary.

      --
      We live, as we dream -- alone....
    33. Re:Are you serious? by AuMatar · · Score: 1

      Does your function exist for a single purpose? Is it ever going to be reused? The problem with saying what a function is FOR (what you see in documentation) as opposed to what it DOES (which you see in code and tests) is that it assumes many thing that may or may not be correct. It also will breed duplication, as you may implement one method fome one "purpose" and another method for another "purpose" where actually they are exactly the same code, just with different names.

      Why yes, yes they do. Thats pretty much the definition of a function- they do one logical operation. It doesn't matter if someone else decides to use it as well- its still doing the same thing for them it was for the original user.

      Easily solved with Good Names... testDoFooCornerCase(), testDoFooRandomlyChosenVariables(), testDoFooFailsWhenValueIsNineBug()

      Good variable names are important. They're still a subset of what your documentation should be providing. They coexist alongside commenting and docs, they are not a viable replacement for them.

      Well, the first thing I wonder is what kind of state is your documentation in when you've just changed it to reflect your new assumptions but haven't gotten around to fixing the code yet? Which do you believe, the documentation, or the code, both of which are out of sync?

      You check them into source control with the same submit.

      If the two fall out of sync, that means there is a bug. At that point, you need to use logic and knowledge of the code to figure out which is wrong. Documentation actually helps here- if there was no docs, you might not know something was wrong. I find the code tends to be wrong far more often than the doc.

      But most importantly, are you expecting every developer to a) memorize all documentation, Chapeter and Verse or B) go through every page of the documentation before implementing new assumptions? Because if you plan to change the documentation when you change your reasoning, you'll have to go through every piece of documentation to see if it has any relation to the change you are goign to implement. With a full suite of automated tests, you can make those changes where you assume they should go, and run the tests and see what other part break... With human-readable documentation you'll have to check it all manually, and carefully, because who knows what dependancies are there that you never suspected?

      Most documentation is in place in the form of comments. So yes, I do expect them to change the documentation thats 5 lines above the line they altered. Outside docs are big picture things, not a line by line description. As such, they would only be changes when you're making sweeping changes to the architecture, something that happens rarely enough.

      As I mentioned above, it has nothing to do with being sloppy... Sure, you can update the bits of documentation that you know about, but you can't know all the constantly changing documentation that is there, without a huge non-productive time-sink... And if you think you work somewhere that does this well, I suggest you take a closer look at your code base. There are guaranteed to be out-of-date comments in whatever code-base you are currently working on, it's unavoidable, it's pure entropy you're battling against.

      Yes, it is about being sloppy. And as for being a time sink- think long term, not short term. It takes 5 minutes more now, but it'll save you an hour when you next look at that section of code. It'll save the new dev who knows nothing about the code at least a day.

      Even with entropy- I'll take occassionally wrong comments and documentation over no docs and a shitload of tests any day of the week. The first will have an occassional bug that will cost me a small amount of time. The second will cost me a large amount of time trying to grapple with

      --
      I still have more fans than freaks. WTF is wrong with you people?
    34. Re:Are you serious? by gnovos · · Score: 1

      And even then I don't believe you've ever shipped code with no bugs.

      Very intersting reply, and probably very good points for those who are used to a mor traditional form of programming... But this is the key right here, in your last sentence. Most people just don't believe it's possible to ship without bugs whereas I and the other developers where I work wonder how it's possible to ship a product WITH bugs. I have tried to explain too often to others in my profession, and I always get this same response in the end... but the fact remains that we've been developing for years, we introduce features on time, and we don't ship bugs. In fact, bugs in non-production code base are almost unheard of. You don't check in code unless it's fully tested, period. All without any formal design and without any documentation.

      Basically, all we do is test everything, assume that the current code-base is always production-ready. We check in code every 5-10 minutes, taking baby steps. We refactor everything, constantly, almost to a fault. We write the tests before we write code, and we run the tests before we check in. And the end result is... it works. Simple as that.

      I wish others would give it a try, but nobody wants to chance it. You know, it's been three years since I used a debugger? I think I used a printout (for testing putposes) for the first time in three months last week.

      It's just a different level of coding.

      --
      "Your superior intellect is no match for our puny weapons!"
    35. Re:Are you serious? by Anonymous+Brave+Guy · · Score: 2, Interesting

      I appreciate the reply, but you still seem to be making the mistake of assuming that the rest of us haven't tried your approach and don't know what we're talking about. Please understand that you are not the only conscientious programmer on the planet, nor are the ideas you advocate particularly original.

      As I mentioned, the project I work on has thousands of automated tests. We write code in small chunks, and run the tests before releasing it. We also have a clear idea of what we're aiming for, courtesy of the design docs, we freely bring in fellow developers for second opinions if anything is looking doubtful, etc.

      And we still get bugs.

      What your post says to me is that you have defined a project that passes all of your tests to be bug-free. That's one possible definition, but it's only viable if you can define a test suite that truly enumerates every single possible action your program will ever have to take. Otherwise, you don't know that it's bug free, you just know that you haven't found any bugs yet.

      Now, perhaps you're lucky enough to work in a field where such a test suite is possible. (What field do you work in, BTW?) Unfortunately, in my field it is trivially provable that you can't enumerate all of the possible inputs into our programs, and therefore you can't construct a set of tests to verify that the program always behaves correctly for all inputs. All you can do is try to have a reasonably comprehensive and representative sample of inputs, and use it as another tool in the correctness toolbox. Whether the program is actually correct depends on the rules specified in the requirements, which cannot be universally tested in a finite amount of time.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    36. Re:Are you serious? by Mr.+Slippery · · Score: 1
      If you stick with the rule "simpler, shorter is better" you can almost never go wrong. Once you find out where you can go wrong, you may not need that rule any more.

      I would say that even junior developers should be thinking in terms of abstraction and encapsultion - "what is this module or routine's purpose in life, in fifteen words or less".

      In fact, maybe we can agree that that's the thing that needs to be short; if you need paragraphs to explain what the thing does, you haven't abstracted the problem very well. And to really determine that, you need to try to write down what it does - you need to comment.

      Of course describing parameters, return values, side effects, precondtions, postconditions, design contraints, et cetera, can take pages, but if I can't give a quick snappy answer as to why this thing exists, I probably need to rethink my design. That's something that should be taught to beginning students.

      --
      Tom Swiss | the infamous tms | my blog
      You cannot wash away blood with blood
    37. Re:Are you serious? by dubl-u · · Score: 1

      Even if you're the best normalizer/refactorer (is "refactorer" a word?) in the world, you had better explain what a function or method or class or aspect or (etc..) does, how it's used, and what the expected results are, or you have made code that is a nightmare to maintain.

      For what it does, that's what names are for. For how it's used and what the expected results are, that's what test cases are for. And the big advantage of test cases is that a computer can tell if they're still valid; comments are prone to drift.

    38. Re:Are you serious? by dubl-u · · Score: 1

      And here is one of the reasons the agile method people get so much wrong. Automatic tests are not documentation, by any means. They do not prove that code is correct, or bug free. [...] Automatic tests have their place, but they are not equal to design or documentation. Any place that uses them as such is producing shitty software which will bite them on the ass when the original devs leave.

      I note that documentation also doesn't prove that the code is correct or bug free. Tests at least prove that certain functionality is present and that certain bugs are absent. To get good design, correct code, and low bug count, you need other practices, like frequent deployment, frequent inspections, and common code ownership.

      You should also consider that both tests and documentation can be written well or poorly. For both, it's only the well-written sort that is useful to those who come later. If I have a choice between code with tests but no docs or docs but no tests, I'll always take the code with the test suite.

    39. Re:Are you serious? by CharlesEGrant · · Score: 2, Interesting
      What seems to not make it across is that anything that cannot be expressed in code cannot be expressed in documentation either.


      So how do you name your functions and variables to convey the information to convey the information that:

      "We have used an O(n^2) algorithm here because the input data is highly structured and the O(n^2) algorithm will actually be faster then the usual O(n log n) algorithm."

      ?
    40. Re:Are you serious? by fforw · · Score: 1
      In your 21 years have you ever seen a project built and run for several years, adding new features every week, never slip a single deadline, all without a single bug of any kind making it into production? I've two such projects, and both of them were using XP methedologies with less than four or five well-placed comments in the entire code-base.
      How many people work on these two projects?
      --
      while (!asleep()) sheep++
    41. Re:Are you serious? by Twylite · · Score: 1

      Please take the PHP runtime and regression test suite, and write a non-trivial application. You may NOT refer to any PHP function documentation; not even a list of functions. To make this more realistic, do it with a language you don't even know.

      Got a Clue yet?

      --
      i-name =twylite [http://public.xdi.org/=twylite], see idcommons.net
    42. Re:Are you serious? by Breakfast+Pants · · Score: 1

      If the 10 line long methods you get only ever get called in that thousand long line method, there is no reason to seperate them out.

      --

      --

      WHO ATE MY BREAKFAST PANTS?
    43. Re:Are you serious? by deKernel · · Score: 1

      Boy oh boy, do I wish I had mod points to give your statement.

    44. Re:Are you serious? by Randolpho · · Score: 1

      Any given method should have more than one test case; any given class could have dozens. Are you honestly suggesting that it's better to read and analyze all of that test code to determine what a method is and how it works -- i.e. the general context surrounding it -- rather than a simple paragraph or two in english? Do you like to chew tinfoil? Do you like to roll around on broken glass?

      As for drift, you forget that refactoring is a part of test-driven development; test case code drifts just as much as API documentation can.

      --
      "Times have not become more violent. They have just become more televised."
      -Marilyn Manson
    45. Re:Are you serious? by Haeleth · · Score: 1

      Do you want your code to me modular and reusable?

      I sure do, and that's why proper documentation is important.

      Suppose I have a generic function that takes a container and returns another container. The tests tell me that the container it returns is the same size, has the same type, and has the property that its contents are sorted in ascending order according to a generic comparison operator.

      Is that all I want to know? Fuck no. I want to know what the complexity of the sort algorithm is - how its time and memory consumption change based on the input, for example. Tests can't show me that, but the documentation can tell me. If it's a straightforward implementation of a standard algorithm, just two or three words of documentation might be enough to tell me.

      So that documentation could get out of date, in theory? Well, yes, it could. And if it did, then I'd expect the developer who neglected his duties to be fired - just as I'd expect the same for a developer who implemented an important class without ensuring that all its functionality was covered by the tests.

      Code and comments. Tests and documentation. Belt and braces. End result: fewer bugs. Developers who argue that comments are useless because they can get out of date aren't "agile", they're just lazy.

    46. Re:Are you serious? by dubl-u · · Score: 1

      Any given method should have more than one test case; any given class could have dozens.

      On my projects the last few years, it's about 50% test code, 50% production code. I'd guess it's less than one test method per method under test. Not too bad to read.

      Are you honestly suggesting that it's better to read and analyze all of that test code to determine what a method is and how it works -- i.e. the general context surrounding it -- rather than a simple paragraph or two in english?

      I'm saying that it should already be pretty clear what a given class or method does by virtue of the design: package names, object names, object members, method names, parameter types and names, and relative relationships among all those. Failing that, I'll look at the code. When that's not clear or I suspect a bug, I go to the test cases. All of which should be written in a readable way; not a lot of analysis should be needed. Failing all of that, documentation is swell. It's great, for example, for a high-level overview document with, say, one page per 20-50 kloc to let new arrivals know the broad structure.

      What you may miss if you haven't done it is that doing test-driven development forces much cleaner code. For example, I regularly see oversized methods in shops that think documentation is the only solution, but I've rarely see them in a test-driven team. It's just too hard to test. TDD also forces developers to look at their objects from the outside, yielding cleaner APIs. Once you've got 100% test coverage and have done all the refactoring you think necessary, there just isn't a lot of need for comments: 99% of the interesting information is already expressed.

      Of course, it's possible that a bad programmer will make tests that are unclear, just as it's possible that they're bad writers who will make useless documentation. But if I have to bet, I'll bet on the tests, because a) they're more likely to have one skill (coding) than two (coding and writing); b) the compiler and testing framework force some semantic rigor and verify accuracy; and c) I can use coverage tools to figure out which tests really cover which code.

      As for drift, you forget that refactoring is a part of test-driven development; test case code drifts just as much as API documentation can.

      Not even close. Tests can be automatically verified by the computer. A human has to manually review all related documentation every time the code changes. On my projects, every time code is checked in all the tests are run. How often do you check all your docs for accuracy?

      Of course, readability is still a potential problem, which is why I prefer pair programming or code reviews.

      Do you like to chew tinfoil? Do you like to roll around on broken glass?

      Actually, when I'm feeling masochistic, I try to have serious discussions with condescending blowhards on Slashdot. How about you?

    47. Re:Are you serious? by SkepticalJS · · Score: 1

      AuMatar said: "Why yes, yes they do. Thats pretty much the definition of a function- they do one logical operation. It doesn't matter if someone else decides to use it as well- its still doing the same thing for them it was for the original user."

      I'm not weighing in on either side here, but if a function is small enough that they do one logical operation, then wouldn't it just be easier to read the code to figure out what's going on than read some developer's comments?

    48. Re:Are you serious? by Arandir · · Score: 1

      "Gee Ditto, you're shit don't stink!"

      --
      A Government Is a Body of People, Usually Notably Ungoverned
    49. Re:Are you serious? by mbadolato · · Score: 1

      I have yet to see a project, in 11 years of coding, that is so complex that comments are a REQUIREMENT

      Really? We're not talking about the dumb comments that are useless like "# Initialize the array", we're talking about the useful ones that explain WHY the code is doing something, or using a particular algorithm, or whatever. Code doesn't tell you that.

    50. Re:Are you serious? by smbarbour · · Score: 1

      If the manager can't read the code, then the manager isn't qualified for the job. Code is logic, and if you can't think logically, you are in the wrong line of work.
       
      Comments ensure that amateurs will be able to follow the logic. Amateurs don't belong in a professional environment.

    51. Re:Are you serious? by dkf · · Score: 1
      if a function is small enough that they do one logical operation, then wouldn't it just be easier to read the code to figure out what's going on than read some developer's comments?
      Ah, you've got mixed up about abstraction levels; one developer's single logical operation is another dev's complex function or even a whole code module. For example, suppose you have a function DrawShadedBox. It's a single logical operation (the drawing of a shaded box of course!) but when you look inside it, it's made up of many smaller operations for things like color management, manipulating the mapping from abstract space to viewing space, shoving pixels on the screen, etc. and the way some of those operations compose might well be non-obvious. A comment explaining those tricky bits would save loads of maintenance heartache, and the advantage of a comment is that it is in the right spot; someone looking to maintain the code will see the comment, whereas they might not bother to read some PDF somewhere in the wild. The situation is often worse with internal documentation; sometimes you end up with developers who produce docs, but only in printed form (they keep the electronic form on their machine behind an agressive firewall) and you have to hope that someone can find a copy in a filing cabinet somewhere in order to be able to read it.

      I imagine at this point some smartarse is going to point out that some methodology-of-the-month ensures that comments are never necessary because they break down every function/method into named sub-functions and everything's self-documenting through appropriate long names. My experience that such systems have real problems as they get larger because you end up with enormous numbers of tiny named functions splattered all over and to get anything done you have to memorize loads of the things. It's like you've gone from a graph where the interesting things are the nodes to a graph where the interesting things are the links, and there's many orders of magnitude more links than nodes. My working memory just isn't good enough to hold all that stuff in my head at once! To cut a long story short, as in all programming tasks, there is a balance to be struck between keeping individual components small (and so comprehensible in themselves) and keeping the overall system comprehensible. What marks a really good programmer is that they get that balance right just about all the time. And (to get back on topic!) comments help a lot by making it easier to fully comprehend more complex components, freeing up more brain-cells for the bigger picture.

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    52. Re:Are you serious? by WindBourne · · Score: 1

      Personally, my advice is to fire ppl who insist on pushing that kind of view. I have seen code out there that was thourghly commented, such as:
      printf("hello world\n"); /* call function to add 1 to i */ Whenever I see tons of comments on code (particurly on line comments), I just want to strangle whoever wasted the companies money. I always have to go through and remove it all just to get to the code and to understand what is going on.

      However, a simple comment on the method/function is very useful (explain what it does and what it takes and and what it returns.). But whenever I see a firebrand on this, I just want to scream (and fire those that push this crap).

      --
      I prefer the "u" in honour as it seems to be missing these days.
    53. Re:Are you serious? by Anonymous Coward · · Score: 0

      Well, you guys are probably talking about two different types of tests - I mean unit tests vs. end-to-end ones. I would disagree that having proper unit tests increases code complexity. On the contrary, you have a strong incentive to properly structure the code since in doing so, you greatly reduce the number of input variations to check for each individual component. It is impossible to test a 1000-liner while 100x10 liners would probably require 200-300 tests in total. End-to-end can never have adequate coverage because of the complexity exploding exponentially hence those pesky bugs.

    54. Re:Are you serious? by alienmole · · Score: 1

      Intel has shipped CPUs with bugs, like the floating point division bug. They have an incredibly comprehensive set of tests of all kinds. If you think your system would prevent such bugs, then you can make billions of dollars showing Intel and other companies how to do it.

      The point is, bug-free applications are only possible in practice in the case of either simple applications, or applications that are highly amenable to testing (e.g. all inputs can be provided, or a subset of inputs is sufficient to rule out bugs even for inputs that haven't been tested). As a simple and common example of a case which is not so amenable to testing, I'm guessing you're not talking about systems with complex user interfaces, since those are notoriously difficult to test, even with the entire industry of UI testing tools that's available.

      The success you claim is probably largely due to the kinds of applications you work with.

    55. Re:Are you serious? by Anonymous Coward · · Score: 0

      "you had better explain what a function or method or class or aspect or (etc..) does, how it's used, and what the expected results are" //this function gets an employee by id. You use it by passing in the id of the employee. the expected result is that you get the employee whose id you specify
      public function Employee GetEmployeeByID(string ID)
      {

      }

      *whew* if not for that comment, I know *I'd* be like...WTF??!?

  8. Here's a comment... by HaydnH · · Score: 1

    If I haven't touched a project for 6 months it can take me a little while to get to grips with my own code if I haven't commented it properly - then again perhaps I just drink too much!

    I don't think a standardized way of commenting is necessary though, as long as there is sufficient comments for a new team member (or a forgetful author like me) to understand the code in a reasonable time.

    Haydn.

    --
    Time is an illusion. Lunchtime doubly so. - Douglas Adams
    1. Re:Here's a comment... by Anonymous Coward · · Score: 0

      Sorry to nitpick, but fix your sig boi!

      Douglas Adams, not Admas

  9. dupe? by MalaclypseTheYounger · · Score: 2, Informative
    --
    Check out the best P2P sharing website: MEDIACHEST.COM
  10. Use module/function comments by V.+Mole · · Score: 3, Insightful

    Comments won't protect you against bad programmers; they'll write bad/confusing code and comments no matter what.

    However, I've found that writing semi-structured comments for each module and function (or object/method, if that's your poison) using something like doxygen is worthwhile for ongoing maintenance. It helps others see what the intent is, and provides a basis for writing unit tests. It even helps the original coder when they come back to the module 6 months later. It's not a matter of whether it's public code, just basic internal docs.

  11. Pig Latin by Saeed+al-Sahaf · · Score: 2, Funny

    I use Pig Latin to comment my code. Job security, you know.

    --
    "Who are in control, they are not in control of anything - they don't even control themselves!" - Glen Beck
    1. Re:Pig Latin by KrisW · · Score: 1

      That could be a fun project to play around with - a (de)Pig Latin-izer.

      --


      "Think you can take me? Go ahead on. It's your move." --Joe Don Baker in Final Justice
  12. just write code that works by jim_redwagon · · Score: 1, Informative

    I think the hardest thing about forcing standards is that they get in the way of actually writing workable code.

    If I have to sit there and worry if I have added enough comments so Joe Firstjob can understand what I am doing, the project is going to be late and chances are I'll lost that train of thought that I was following to get through that function.

    My usual mode of 'documentation' use real language function returnUserShoppingCart and variable shopperLastPurchaseDate names and add comments noting loop/if-then statments and anything I know I will need a refresher on. I also use comments to state why I did something that way, ie: business rule in effect as of this date, etc.

    Your best bet is to know your staff/fellow programmers, learn their styles (or at least become aware of them enough to follow along) and make sure you have checkpoint/target status deadlines. The last to make sure you don't have someone writing 'hola world' for 5 months.

    --
    I forgot what I wanted to say, but honestly, it was important.
    1. Re:just write code that works by Ithika · · Score: 1

      You've just been re-reading the Brilliant Paula Bean haven't you? :)

      Sometimes you just gotta wonder whether the IT industry (if such a thing can be said to exist) has any pride in its work at all. I think I'll just stick to the outskirts and reading the horror stories!

  13. Retrofitting comments is admittedly a pain... by Anonymous Coward · · Score: 0

    But if "no comments" is an option, you must work on REALLY small projects.
    I've gotten to the point where I comment en evmy throwaways, because I have a
    dusty directory full of them and occasionally I pull one out again.

    Here's the simple solution that works for me: any time I have to stop and think
    about code, either to write it or when (re-) reading it, write those thoughts
    down in the form of comments. I have *one line* of code that's particularly
    subtle (it's a function approximation), so I broke it out into its own function
    and gave it a page (printed page - 60 lines) of comment explaining what it does
    and why the approximation is useful.

    But I spent a day designing that approximation, so the think time was already spent.
    All I had to do was write it down the first time.

    Sometimes the comment gets a bit long and rambling if I make multiple
    attempts at the solution, but deleting redundant text is pretty easy.

    On the other hand, some functions are so obvious as to not need anything, although
    I usually try for a one-line overall comment. I at least had to think about
    how to break the work into functions and where a good boundary would be.

  14. Doc Generation? by Telastyn · · Score: 1

    Seems like you missed a step. First you decide if you're going to use an auto-generated code documentation tool like Doxygen. That alone will dictate the majority of any comment-standard.

  15. All code should be well documented by ArwynH · · Score: 3, Insightful

    Commenting and documenting code is something all programmers should do. Not doing it is highly unprofessional and should not be allowed in any self-respecting firm. Making sure the documentation/comments are upto date is included in that statement.

    On the other hand just because code is well documented that doesn't mean it's easily maintainable. There are various techniques used to generate good maintainable code. But without documentation any code more complex that 'hello world' tends to be a pain to maintain no matter what techniques you use.

    I personaly also find the formating of code (and comments) just as important as commenting it. Reading code formated in a way you're not used to can be a pain and reading code formated in different ways doubly so. So a company-wide standard for formating code/comments would be a good idea.

  16. The one problem with comments by MarkusQ · · Score: 4, Insightful

    There is one problem with comments, but it is a show stopper as far as I'm concerned.

    Computers never read the comments, while programmers tend to read comments rather than code. The first part is obvious, and the second is easy to demonstrate. Together, they are a recipe for disaster.

    Uncommented code has a number of disadvantages, but the overriding (IMHO) advantage is that both the computer and the programmer are dealing with the same thing, the code. On the other hand, with commented code they are dealing with two similar but distinct things, that are related in exactly the same way as a fine-print contract (the code) and the car salesman's verbal promises (the comments). When push comes to shove, the salesman's words mean nothing and the contract is what matters. So why even listen to the salesman?

    -- MarkusQ

    P.S. This is not to say that I never comment code; only that I do so sparingly and never trust the comments.

    1. Re:The one problem with comments by neelm · · Score: 1

      You point out a good reason for comments... when the comments don't match the code, that's a good sign of where the bug is. When I'm going behind another programmer looking for a bug I've been tasked to fix reading his comments tells me if his logic was wrong, or the code.

      I suppose you could get away with some comments in say, a blog site, but if you're working as a developer on a team with more complex requirments, and the origional programmer may not even be with the company anymore, comments are a must.

      It's not like it takes that long either...

    2. Re:The one problem with comments by Grab · · Score: 3, Interesting

      You're misunderstanding the real purpose of comments.

      If your comment says "Increment i" and the code says "--i" then yes, things are fucked. But the purpose of comments is not to describe *what* the code does but *why* it does it (and occasionally *how* as well if it's not clear, for example if there's some particularly gnarly maths or pointer weirdness involved).

      Anyone writing comments saying *what* their code does what it does needs their code reworked at review - and if they're not on their first job then they need firing.

      Anyone *not* writing comments saying *why* their code does what it does needs their code reworked at review - and if they're not on their first job then they need firing.

      Grab.

    3. Re:The one problem with comments by afidel · · Score: 1

      That's where EIFFEL has an advantage over other languages, it's comments can't disagree with the code. The comments are part of the design by contract methodology that the language enforces. You setup your incoming inputs with an expect statement, then guarentee your outputs with an ensure block. Failing to meet either the expect or ensure conditions throws an exception which you can catch and hadle as needed.

      --
      There are 4 boxes to use in the defense of liberty: soap, ballot, jury, ammo. Use in that order. Starting now.
    4. Re:The one problem with comments by p3d0 · · Score: 1

      Comments and code should not overlap in their content, so your complaints are irrelevant. If you have code that says "x=0" and a comment that says "set x to zero" then you don't understand what comments are for.

      --
      Patrick Doyle
      I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
    5. Re:The one problem with comments by ianezz · · Score: 2, Insightful
      On the other hand, with commented code they are dealing with two similar but distinct things

      IMHO, the point of comments is not to tell other how things are done, but why they have been done in that specific way. No amount of code can tell you that.

    6. Re:The one problem with comments by SkepticalJS · · Score: 1

      How is this different than setting up automatic unit tests?

    7. Re:The one problem with comments by Brandybuck · · Score: 1

      it's comments can't disagree with the code.

      I've never used Eiffel, but I have a hard time believing that. Comments are written in English (or another human language). A limited subset of comments can be checked by a compiler/language, but it's currently beyond the technology to check all comments.

      For example, you're writing a device driver (something you can't do in Eiffel, but just imagine). You wish to communicate to other people what you are doing. Typically you include paragraphs out of the hardware spec. Stuff like "the spec says we have to wait three milliseconds after setting the bus to high." Comments like these are valuable, but I cannot believe that Eiffel would be able to enforce them.

      --
      Don't blame me, I didn't vote for either of them!
  17. Why Documentation is Absolutely Necessary by jgardn · · Score: 3, Insightful

    In the real world, you work on a project for a time then move on to something else. Then you or someone else is assigned to revisit your old code. You don't have time to relearn the code and you certainly don't have time to sit down the guy called in to fix it and tranfers your understanding of the project. (If you did, you would've documented the code properly in the first place, right?)

    When companies don't comment and don't document their code properly, they begin this vicious cycle of rewriting old code because no one know how it should or does work and no one has the time to figure it out. Let me explain why.

    Imagine you find a software package on the internet licensed in a way that suits your needs. Now imagine that software package, with very few modifications, will do exactly what you need it to do for you project. You have a choice: (1) Take that software, modify it, and deploy it, or (2) write your own from scratch.

    There is only ONE determining factor in whether you inevitably choose (1) or (2), and that is DOCUMENTATION.

    Now remember that software you find in your own company is no better or worse than software you find on the internet, only it has a much more liberal license for your purposes. But does that change the fact that in order to make use of it you have to understand it?

    On my job, I have an approach to undocumented software. I start writing documentation for it, whether or not the author wants me to and whether or not there is really enough time for it. If I have questions, I find the author, and approach him with pen and paper. We sit down and write documentation together. Inevitably, by documenting what I find in other people's codes it ends up saving me more time than if I wrote the code myself, documented it, and debugged it. So I have been able to finish a great number of projects ahead of schedule because I don't write code: I READ it. (And this is a perl world too!) And in the end, others are able to come and read my documents and notes and reuse the software as well.

    --
    The radical sect of Islam would either see you dead or "reverted" to Islam.
  18. Hey man, don't tell me what to do! by aquarian · · Score: 1

    Grow up.

  19. Theory vs Practice by SmallFurryCreature · · Score: 2, Insightful
    Commenting and Documenting both take time. Wich you often don't have, so you don't do it or worse do it badly.

    If somebody asks you to code something (and you can get away with it) tell them this, "okay that is X hours for just the code and X*3 for the code and proper documentation."

    Yes I made the *3 up. You know why? Because I have always had the misfortune on working on the kinds of projects where I either didn't get the time needed or the guy before me didn't do the documentation.

    If you want to take a ride in your car you should walk around it making sure it is in proper working order like all the lights working. It is a law and enforced by people with guns. Now how many of you do it?

    Okay, nobody. So now you are under time pressure, you are underpayed and overworked and you got a choice, either deliver on time or tell your boss your still writing documentation on the installer.

    When I was still young and fresh I thought that following procedures is the way to do it. Boy was I wrong. The secret? Code fast and ugly and make sure you have moved on before the shit hits the fan. Oh and never ever be lumbered with a maintenance project. I never even seen documentation wich was up-to-date.

    The entire discussion on wether or not to document is wrong. The discussion should be wether you will allot enough time to non-coding work. It applies to so many things, peer review of code, sharing and re-use of selfmade libraries, layout standards, knowledge sharing, etc etc.

    The larger the company the more time can successfully be spend on non-coding things that however are always badly reviewed during your evalutation. Oh yeah very nice you tought everyone else how to code securely and made sure nobody else has bugs in their code. Now how many lines did you write? Oh, no pay rise for you.

    So simply ask this of the people in favor of proper documentation. How will they find the time?

    And ask the non documentation people if they will do the maintenance on their own projects 10 years in to the future.

    My experience? I needly predict I need X to write code and then Y to write the proper documentation. I deliver the code and get the next project and if I protest that I am still working on the documentation then I am told that it can wait. I am still waiting. Oh and the risk of doing it properly? You get lumbered with writing maintenance and writing the documentation for everyone else because your good at it but a slow coder. ARGH!

    Just comment the basics, point out in a readme.txt where to start reading and tell them wich bar in the neighbourhood serves hard liquor during lunch. Oh and if you comment some code out come back later and delete it. Can be very confusing if you have to wade through a problem where 2/3's is old code.

    --

    MMO Quests are like orgasms:

    You may solo them, I prefer them in a group.

  20. Worse. It's a Trupe! by dorkygeek · · Score: 1
    Rather looks like a trupe. See this Ask Slashdot story: What Workplace Coding Practices Do You Use?.

    --
    Windows is like decaf - it tastes like the real thing, but it won't get you through the day.
  21. Tech Reviews by crmartin · · Score: 2, Informative

    The answer (40 years of experience with this) is not to set a standard on how much commenting is needed; it's to have walk-throughs of the code with an intelligent reader who isn't directly involved with the code. If they can read and understand the code, it's enough.

    Look into Fagan reviews for details on an effective way to handle this.

    1. Re:Tech Reviews by Anonymous Coward · · Score: 1, Insightful

      Agreed. Have a competant engineer give it a lookover.

      A few other points:
      Don't confuse comments and design documents.

      Focus on the "why" -- the code itself is the "how." If something seems nonintuitive, describe why you made that decision. Your goal is to get the reader to the same place in your engineering that allowed you to solve the problem and describe the trade-offs. If you have to leave a "popcorn-trail" of ideas you tried, do so. Spending a week debugging to understand the interactions of a complex system should be done once, then described so that the next person doesn't have to.

      Mandatory "flower box" comment blocks at the top of every function are annoying, a waste of time, and a liability. If they exist at the top of every function, then the important comments explaining difficult-to-understand sections get lost in the "noise" of the comments for trivial functions.
      Comments are a liability if you work on a regulated or validated system (think pharma, air traffic control, banking, missile guidance, etc. or any other system where life & fortunes are involved) -- failure to update the comments means the system is out of compliance and a simple change or refactoring turns into a huge time-waster as you go about changing dozens of trivial comment blocks to reflect a new layering or ownership structure.

      Which brings me to the final point: if a block of code is complex enough to need 1) a comment, and 2) a big comment to explain its inner workings, then you probably should refactor and simplify.

    2. Re:Tech Reviews by Anonymous+Brave+Guy · · Score: 1
      Which brings me to the final point: if a block of code is complex enough to need 1) a comment, and 2) a big comment to explain its inner workings, then you probably should refactor and simplify.

      Which may or may not be possible. Not every algorithm is as trivial as a binary search or heap sort.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    3. Re:Tech Reviews by crmartin · · Score: 1

      The "simple comment" rule isn't a bad first approximation, but sometimes you *do* complicated things. Kernel code sometimes has complicated methods in order to avoid overhead.

      I don't agree about the prologue or block comment. It can be taken too far, but something with a name, an abstract, and an author and date is usually quite helpful. The java javadocs are often less helpful thhan they could be because they're missing an overall context description of the class.

    4. Re:Tech Reviews by dubl-u · · Score: 1

      The answer (40 years of experience with this) is not to set a standard on how much commenting is needed; it's to have walk-throughs of the code with an intelligent reader who isn't directly involved with the code. If they can read and understand the code, it's enough.

      Yes! The only way to be sure that other people can understand the code is to have other people try to understand the code.

      I prefer to do this with pair programming and frequent pair rotation, but inspections are ok, too.

    5. Re:Tech Reviews by crmartin · · Score: 1

      I'm a big believer in pair programming --- long before it was a buzzzword, I taught programming by forcing people to work in pairs, and it works great then too. But I suspect Fagin reviews would add something even to paired code.

  22. The best thing to do by ogar572 · · Score: 1, Insightful

    is have all the programmers program in the same style and guidelines. Examples include all SQL statements start with $sql_, making sure code is properly indented, variable naming that are easy to recognize, where certain functions should be placed in the directory structure, and the such. Simple things like that should eliminate the need to write a novel for every piece of software that you write.

  23. Mmmm comments by skotte · · Score: 1

    May I be a sort of voice of reason, of a kind? comments are tasty things which should be used regularly and often. spelling and grammar may not be necesarry to be observed, but in my opinion, I would much rather see roughly one comment fFor every, say, 6 lines of code. I dont mean in exact ratios portioned out like rations .. you could have a whole page or two of comments sometimes which covers 3 pages of other stuff, if it's all somehow convenient. that's cool. And, you know, variables and routines with obvious names may not need everything documented .... but somewhere i should be able to get some information about much of what a system does. in my experience, it seems as though once about every sixth line or so, we do something a little subtle which a nice simple comment might help. more is good, yes. you know, and i'm talking like /* add interest, dump to screen */ or /* average RGB values */ or .. that sort of thing. simple verb noun descriptors which tell what's going on. The kinds of things your pseudocode should say -- you do remember seudocode, right? that's the stuff your CIS 101 prof told you you should always use, and you havent touched since?

    I mean, I'm inclined to say "if you don't use commenets everywhere you should be shot!" but i dont have that many bullets, and i'm just as inclined to say "you cant make me use comments if i don't wanna!" but i also don't have that many bridges so i'd rather not burn them *all* down.

    a nice sane happy medium is a good thing.

    1. Re:Mmmm comments by skotte · · Score: 1

      this guy gives better examples than I do here:
      http://ask.slashdot.org/comments.pl?sid=173417&cid =14428436

  24. The one problem with MDA by Anonymous Coward · · Score: 0

    "Computers never read the comments, while programmers tend to read comments rather than code. The first part is obvious, and the second is easy to demonstrate. Together, they are a recipe for disaster."

    So what do you think about executable models?

    1. Re:The one problem with MDA by MarkusQ · · Score: 1

      The idea is neat, though such ideas often come with their own problems--specifically, version control and change management, when the models can't be easily treated as flat text.

      Another interesting trick I've seen prototyped (but not in use) is code animation; the documentation consists of a collection of sample cases (which double as test cases) and a specification of what to show (and how to show it). To see how the code works, the tool animated the samples using the actually code. IIRC the examples included a sort, a threaded message passing application, and a cryptography (or perhaps it was data compression) routine. The key point again being that the programmer was looking the same thing as the computer.

      --MarkusQ

  25. simple rule by outcast36 · · Score: 2, Insightful

    Document at the function level (javadoc style is nice). It's easy to remember and it helps you refactor. If you are documenting the internal magic, then the magic could probably be moved out into it's own function, which then gets it's own documentation. voila.

    If you need a documentation/commenting consultant, I am available to guide your team through this process.

    1. Re:simple rule by David+Horn · · Score: 1

      Mod parent up. That's the most insightful comment so far in this topic.

      --
      PocketGamer.org - For the gamer on the go!
  26. Comments are compromise by gnovos · · Score: 1

    Basically, treat comments like you should credit card debt. Use it rarely, only when you really have to, and try to get rid of it as soon as possible. If you can write the code in a clearer way, one that does not need comments, then do so, ASAP.

    In a perfect world, the ONLY thing that you want to have comments are APIs into closed code (some outward-facing API that you aren't willing to give the source to). Everything else should only have comments when the code is too complex to be understood by reading it... and that code should be first in line for refactoring.

    And never NEVER write comments like "the doFoo(Stringx, String y) does foo by taking string x and string y as parameters". This is useless, clutters up everything, and makes the important comments less visible.

    --
    "Your superior intellect is no match for our puny weapons!"
  27. if code is hard to write... by acomj · · Score: 1

    It SHOULD be hard to understand.

    http://thc.org/root/phun/unmaintain.html

    In all seriousness. I would just enforce "header" comments to a particular style (javadoc..etc). The rest is up to the individual programmer.

    The trouble as pointed out earlier is that programmers/code reveiwer have to be always be updating comments as the code gets updated. This doesn't always happen and is the caused me personally some problems as I took the comment to be right, when clearly they were not. I use comments as a guide now.

  28. Please help me on this by bill_kress · · Score: 2, Interesting

    I keep seeing all these arguments either against commenting or against verbose languages because, supposedly, they slow development.

    Now, Maybe I've just been programming too long and have gotten too good at it, but typing is never ever a slow-point in coding; heck, even learning a new language doesn't slow you down too much!

    The slow part is designing your code correctly so that it's fully factored and as bug-free as you can manage--this takes thought and a bit of time, but no where near as much time as it would take to do the same release with cut & paste (I've seen it many times).

    So I'm trying to figure this out, why are people making these arguments? Is it that for unexperienced people it truly is harder to put comments in with your code? Maybe they don't know how they did their magic and don't want others to figure them out? Maybe they never took a typing class and it truly takes more time to code than think? I'm really at a loss here.

    Oh, and as for the authors question, you have a FANTASTIC opportunity to improve your company tenfold. Take notes of those arguing against commenting. As soon as you've collected all the votes, throw them away and FIRE anyone who was against documentation--they should not be working in any company, at least not as a programmer! If you hired people who understood programming and the development cycle, that question would have never come up.

    1. Re:Please help me on this by Anonymous+Brave+Guy · · Score: 1

      I frequently argue against excessive commenting and overly verbose languages, but for a quite different reason: too many redundant comments obscure those that really matter.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    2. Re:Please help me on this by bill_kress · · Score: 1

      When is over-commenting seriously a problem?

      Unless you have a manager that has some program to count comments per lines of code, I can't see having that complaint.

      If you have a co-worker who isn't commenting for readability, that's another thing. Bad commenting has nothing to do with volume of comments, it has to do with understanding your target audience. Commenting is like any type of technical writing--you write to communicate in a way that your audience will best understand.

      However, this is from the point of view of a heavy coder. If you write scripts or small throw-away programs, you have a completely different problem space.

    3. Re:Please help me on this by Anonymous+Brave+Guy · · Score: 1

      I suspect we're mostly in agreement here. The sorts of redundant comment I'm talking about do include banner comments at the top of each function that repeat what the line of code below them used to say, and classics like "// Increments i" after the line "++i;". However, they also include (for example) comments that basically repeat what's in the design documentation, but tied into the implementation. These don't really help anyone, but they do waste space, and as I mentioned before, they tend to obscure the really useful comments. If 4/5 comments in a 30-line function are basically repeating what's better said elsewhere, even if correct, then it reduces the impact of the last 1/5 significantly, IMHO.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    4. Re:Please help me on this by bill_kress · · Score: 1

      Yep. I really like the Java commenting system where, if done right, you get generated documents (rather than trying to correlate your code with the requirements).

      It really is important to consider your audience. You don't want to reproduce stuff in another document, but if a function implements a certian requirement, it doesn't hurt to refer to the exact requirement (with a URL). Hmm, that might even be a good tag to add to the Javadocs system...

      I think most good programmers understand this stuff and would agree with us, but you might consider the effect your statements have on newer programmers who don't understand how useless code without documentation is.

      They might put an importance on the opinion of a good programmer and try to cut their already minimal comments down rather than being smarter about crafting them to be usable at any volume.

  29. the reason for comments by CDS · · Score: 1
    The problem isn't "should we comment" or even "how many comments should there be" -- the problem is actually "what should the comments say" at my work I have seen several different styles of comments and invariably, one type of comment stands out as useful and other comments are mere distractions, at best. Comments should never be used to document how code works. The code itself shows how it works -- or at least it SHOULD. If your code isn't readable, THEN RE-CODE IT! It's not maintanable. I don't care how you were able to make 18 things occur in one line of code. that's not elegant. that's dumb. It's not maintainable. Rewrite it so it's clear. Comments should document WHY the code is written that way. I don't care that:
    while(i<10) { /* repeat until i is greater than 10 */
    That's useless. that just takes up space. and what happens if you change it to
    while(i<20)
    ? then your comment is out of date. However,
    while(i<10) { /* spin through the list, searching for blah */
    tells me the purpose of this while() statement, and tells me something about the body of the loop as well. Even better would be a block comment above it, of course (describing the entire body of the loop, for example) What I do is I write the comments FIRST -- I lay out the high-level design of the program in the comment block, then go and add the code in the appropriate place within the comments. That way my design is documented and my code is created from the design. That ensures the comments are correct, at least initially. The other thing do is document changes within the comments:
    while(i<20) { /* Spin through the list, searching for blah */ /*@01C*/
    then in the prolog of my program, I have a comment that describes changeflag 01, who made the change, the date of the change, and the location of the document describing the need for the change (bugzilla number, etc). This not only keeps the documentation up to date, but provides a paper trail. If someone else looks at the code and doesn't understand why we stop at 20, they can just look up that changeflag and come find me to talk about it.
    1. Re:the reason for comments by Just+Some+Guy · · Score: 1
      then in the prolog of my program, I have a comment that describes changeflag 01, who made the change, the date of the change, and the location of the document describing the need for the change (bugzilla number, etc). This not only keeps the documentation up to date, but provides a paper trail.

      An alternative approach is to pick a revision control system and teach people how to use it. For example, we use Subversion and can do stuff like:

      $ svn blame RetrieveRemote.py
      ...
      409 jsmith import time
      530 bmoore import xml
      412 pjones self._connect()
      530 bmoore except xml.sax._exceptions.SAXParseException:
      530 bmoore raise MSDatabaseError
      412 pjones except:
      ...

      $ svn log -r530 DBBridge.py
      r530 | bmoore | 2005-12-14 10:30:08 -0600 (Wed, 14 Dec 2005) | 7 lines

      Made RetrieveRemote.py trap XML errors (to catch another class of exceptions thrown by the server). PR#5436.
      to see exactly who wrote each line of each file in the system, and why they wrote it. Even if we never wrote a single line of comments, we still have a way of explaining every bit of code.
      --
      Dewey, what part of this looks like authorities should be involved?
    2. Re:the reason for comments by Ace+Rimmer · · Score: 1

      This is only the case if some idiot haven't reformated the whole file, haven't commited and then removed '^M' lines etc. (which happens all the time at least in this company ;)

      --

      :wq

  30. mod parent up by Anonymous Coward · · Score: 0
    Code comments are only one form of developer documentation. Other forms include design and discovery docs (e.g. UML) and change comments (e.g. this change fixes bug 2938). Put design/discovery docs in an Intranet collaboration site. Wiki or any CMS such as Plone are good technologies for this. Put change comments in your source code control system.


    If you fix a minor bug, and a week later you realize it's created a major bug, but in the meantime eight dozen commits have been made by your team, it's not always easy to just roll back to the version before the one you helpfully noted in the CVS comment as being "the" bug fix; you really do need to tag bug fixes in the code itself. The more documentation, the better. Explaining the "fix" you made should be part of this, though it can be out of the code itself, in external docs -- as long as everyone knows that that's where to it, and it's not split among five different places. That's where standardization really would be helpful. Some people still only comment in CVS, and I think that's just not enough if it's a team project.
  31. I agree, to a point by MarkusQ · · Score: 1

    I agree, to a point. "Why" (and "how") comments are far better than "what" comments, but the fundumental problem still applies. Even "why" comments can obscure bugs:

    i -= 1000 if i > 1000 # We only have room for (and only need) three digits
    --MarkusQ
    1. Re:I agree, to a point by jackbird · · Score: 1

      How does that obscure the bug in that line? It makes it much more obvious because you know what they're trying to do.

    2. Re:I agree, to a point by MarkusQ · · Score: 1

      How does that obscure the bug in that line? It makes it much more obvious because you know what they're trying to do.

      Because (and this has been well tested) people tend to read the comment instead of the code. The high tech tests tracked people's eye movements and such, but you can show the same thing by timing how long it takes people to find bugs, or just quizing them afterwards.

      The effect gets more pronounced for larger segments of code. In one example that I recall, half a group of programmers were given a ~10 line binary search routine (with no comments), and asked what it did. The other half were given the same code but with the comments from a shell sort routine ("why"-comments).

      When asked what the routine did, the first group was almost always correct, and the second got it wrong more than half the time.

      --MarkusQ

    3. Re:I agree, to a point by jackbird · · Score: 1

      But without a comment, there's no way to tell that code is buggy. It could be setting an index in a 1000-element 1-based array.

    4. Re:I agree, to a point by deadlinegrunt · · Score: 1

      It appears to me his point is valid while yours is valid as well in a different context. Context being the key point here. Without the comment you would not know that statement was buggy HOWEVER with the comment you are more likely to pay attention to the comment and not the actual bug right in front of you. Given this particular scenario it seems you would be more "correct" than the GP since the comment in this example is crucial to knowing the purpose of the code. Of course in actual practice there would be more than a single line of code thus giving a context of the purpose for the code which validates the point of the GP.

      I find commenting code resembles trying to woo the opposite sex; regardless of your style it simply doesn't work as intended in all cases. Much like programming languages I don't think there is a silver bullet for documentation either. The simple fact is that the code are the facts - not necessarily the intention; be it code or documentation - everything else is subjective IMHO including whether documenting code is good or bad.

      --
      BSD is designed. Linux is grown. C++ libs
  32. Comment my code? by stevenharman · · Score: 1

    Never! Why do you think they call it code?

    --
    90% of being smart is knowing what you're dumb at.
  33. mod parent up # reposted as me by Artifex · · Score: 1
    Code comments are only one form of developer documentation. Other forms include design and discovery docs (e.g. UML) and change comments (e.g. this change fixes bug 2938). Put design/discovery docs in an Intranet collaboration site. Wiki or any CMS such as Plone are good technologies for this. Put change comments in your source code control system.


    If you fix a minor bug, and a week later you realize it's created a major bug, but in the meantime eight dozen commits have been made by your team, it's not always easy to just roll back to the version before the one you helpfully noted in the CVS comment as being "the" bug fix; you really do need to tag bug fixes in the code itself. The more documentation, the better. Explaining the "fix" you made should be part of this, though it can be out of the code itself, in external docs -- as long as everyone knows that that's where to it, and it's not split among five different places. That's where standardization really would be helpful. Some people still only comment in CVS, and I think that's just not enough if it's a team project.

    # hah. I screwed that one up. What a perfect example of why commenting is important :)
    --
    Get off my launchpad!
  34. documentation?? what's that? by keithhackworth · · Score: 2, Funny

    I've been programing for most of my life and have only documented about 3 peices of my work where things got so complex, it was making my head hurt. Even then, my comment says "I feel sorry for the next person who has to figure this out..." or "Don't ask what I was thinking here...".

    IMO, if someone comes up and asks for documentation, they need to be fired! They obviously either 1) don't know how to read code and shouldn't be programming; 2) Don't understand the problem the code is trying to solve.

    Code is like a foreign language - you either know it or you don't. Comments are for people who don't know it; and if they don't know it, they need to find another job or learn the language.

    When I program, I get in this "state" where I can't stop. When I get to that state, I am a VERY FAST programmer. If I were to document my coding, it would take me 5 times as long to write it because I would never get in that "state". On the rare occassion that I look at code and can't figure it out, I rewrite it because, obviously, the code sucks. To keep my code from sucking, I have very strict guidlines that I use when programming (in order of importance):

    1. MOST IMPORTANT - use tabs in routines to show where routines start and stop
    2. use tabs in routines to show where routines start and stop
    3. If I do comment (yea right), Don't put parenthesis, squiglys, or brackets in the comments - it screws up vi's % command.
    4. use tabs in routines to show where routines start and stop
    5. Make variables' and functions' names intutive.
    6. use tabs in routines to show where routines start and stop
    and last, use tabs in routines to show where routines start and stop


    If you use these rules and have a decent progrmamer, there's probably very little need for comments.

    Keith

    --
    Support bacteria. They're the only culture some people have.
  35. The one problem with MDA-CVS. by Anonymous Coward · · Score: 0

    "The idea is neat, though such ideas often come with their own problems--specifically, version control and change management, when the models can't be easily treated as flat text."

    Well since for most tools the model is basically an XML file behind-the-scenes. Something like CVS is possible. Just as image-based languages .i.e. Smalltalk can have version control.

    There are open-source tools that help one do MDA, like GME, StarUML, and Openmdx. The missing part to all of these is of course TDD (test-driven-development).

  36. Re:documentation?? what's that? by ObsessiveMathsFreak · · Score: 1

    IMO, if someone comes up and asks for documentation, they need to be fired! They obviously either 1) don't know how to read code and shouldn't be programming; 2) Don't understand the problem the code is trying to solve.

    On the rare occassion that I look at code and can't figure it out, I rewrite it because, obviously, the code sucks.


    Hack Mplayer. Then come back to me.

    --
    May the Maths Be with you!
  37. Document your code or hit the road by Mr.+Slippery · · Score: 2, Insightful
    that comments are not necessary for clarity and can be dangerous if not kept up to date

    If you can't keep comments up to date in the code you're responsbile for, you're not competent to be responsbile for the code.

    There shouldn't be any debate on the need for documentation. Document your code or hit the road. The only issue is where it goes, in separate docs or in comment blocks. (Doxygen and similar systems make it easy to generate separate docs from comment blocks. Recommended.)

    Code reviews are the best enforcement - if you go in and everyone's asking "what the hell does this block do???", you need to comment it.

    --
    Tom Swiss | the infamous tms | my blog
    You cannot wash away blood with blood
  38. you are not invincible by Anonymous Coward · · Score: 0

    i work in a small shop where one of our programmers had a massive stroke the week before christmas.

    as a non-"official" programmer, picking up the slack would have been a LOT easier if his code were commented.

  39. Like a math proof by Metasquares · · Score: 4, Insightful

    Code, like a math proof, is written in a specialized language that people outside of the field are unlikely to understand well.

    Try removing all text from a sufficiently complex math proof, leaving only the mathematical notation, and see if you can still figure out what the mathematician is doing.

    Now try to publish a paper like that.

    No matter how amazing your results, such a proof will not be accepted by the mathematical community. I've run across some very good papers that were discarded because no one, including the author, could understand what all that math was supposed to *do* anymore.

    You should be writing code the same way as you'd write a good proof. You don't need to explain why 1+1=2, but you definitely do not want to skip over critical parts of a proof that are necessary to understand before reaching the conclusion.

  40. Re:mod parent up # reposted as me by anomalous+cohort · · Score: 2, Insightful

    I see your point regarding using source code control for change comments. The issue that I have run into putting change comments in the code itself is one that also happens over time and multiple changes.

    Here is an example, let's say you change line 188 to fix defect 2287. Next week, another developer needs to change the same line to fix defect 3012. Does that developer append on to your comment or overwrite your comment? What if the developer completely changed line 188 so that your changes were lost?

    I guess that there is no perfect answer so you end up putting change comments in both the code and in the CVS (or similar) system. The downside of that is the wasted resources and potential for error in duplicitous effort.

  41. What I said earlier by arensb · · Score: 2, Informative

    I wrote what I thought was a pretty decent article on comments a while back:
    http://freshmeat.net/articles/view/238/

    The gist of it is that the source tells you what the code does, and comments tell you what it's supposed to do, why it looks that way, how it connects to other parts of the program, any weird gotchas, and so forth.

    Comments help you zero in on the part of the code you're looking for when you're trying to fix a bug; and they help confirm that the code really does what you think it does.

  42. Obligatory by PMOnoTo · · Score: 0

    Use The Commentator - easy to use and very effective!

  43. Comments on Comments by mini+me · · Score: 1
    I find code that is littered with comments hard to read. It's like mixing french with english so the french-speaking people can figure out what the english means. This is what code with comments looks like to me:
    /*
    Cette phrase est au sujet de l'opinion de l'auteur de poteau sur le code de programmation de commentaire.
    */
    Comments are bad // montrer une aversion forte
    because they make code more difficult to read.

    Who wants to read something like that?

    (Babelfish used for translations)
    1. Re:Comments on Comments by metamatic · · Score: 1

      It's trivial to strip out the comments, if you really feel that way.

      --
      GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
  44. Encrypt Your Comments! by oldCoder · · Score: 1
    And email them to yourself at home with the source. Remove everybody else's comments. Soon you will be the only person who understands the code! Hell -- use a scrambler to dis-organize the code. They're called obfuscators. See this site for an example. If that doesn't work delete the source and keep on patching the binary! I'm serious! I knew a coder who kept his job for 15 years that way. I do not exaggerate. Of course, when he finally left, he was completely out of touch and obsolete, but he didn't mind! I kid you not!

    The disadvantage is that you are stuck on that project forever! They can never move you to new code since you're indispensible. A boring life but secure if you want it.

    --

    I18N == Intergalacticization
    1. Re:Encrypt Your Comments! by petermgreen · · Score: 1

      afaict thats a risk. Sometimes people get away with it and get a very secure job, other times the company decides to take the hit of sorting it out before the person does more damage.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
  45. Re:documentation?? what's that? by TLLOTS · · Score: 1

    Code is like a foreign language - you either know it or you don't. Comments are for people who don't know it; and if they don't know it, they need to find another job or learn the language.

    To take your analogy of code being a foreign language on step further then, writing a program is somewhat akin to writing a tale. I would therefore liken writing code without comments to writing a story with no naration. Yes, it can work, but a narator works well to expose the underlying purpose of the tale.

    Quite frankly it's people like yourself and apparently many other slashdotters who are wrong with the computer programming industry. Good coding standards can only take you so far without good comments and documentation to back it up.

  46. Are you? by munch117 · · Score: 1
    My advice is to fire every developer that doesn't think that comments are necessary.

    My advice is to fire every manager who would fire developers over petty deviations from the norm.

    Dissemination of information is important, and comments can be helpful for that. But there are many ways to skin a cat, and the ones that involve not skinning the cat but giving it a bowl of milk instead will earn you fewer scratches.

  47. mod parent up # reposted as me-History Lesson. by Anonymous Coward · · Score: 0

    "Here is an example, let's say you change line 188 to fix defect 2287. Next week, another developer needs to change the same line to fix defect 3012. Does that developer append on to your comment or overwrite your comment? What if the developer completely changed line 188 so that your changes were lost?"

    You append, because one of the purposes of a change control system is to establish a history of both the code, and the programmer. Plus , just because two programmers worked on the same line, doesn't mean that they worked on the same part of the line.

    "I guess that there is no perfect answer so you end up putting change comments in both the code and in the CVS (or similar) system. The downside of that is the wasted resources and potential for error in duplicitous effort."

    There's no difference. The CVS is the code, and the code is the CVS. The important things are "he who changes the code, makes the comments", and keeping the "comments" with the relevent code (a coupling problem).

  48. Re:documentation?? what's that? by gstoddart · · Score: 1
    Code is like a foreign language - you either know it or you don't. Comments are for people who don't know it; and if they don't know it, they need to find another job or learn the language.

    To take your analogy of code being a foreign language on step further then, writing a program is somewhat akin to writing a tale. I would therefore liken writing code without comments to writing a story with no naration. Yes, it can work, but a narator works well to expose the underlying purpose of the tale.

    An excellent analogy. Reading code is like reading an essay or a book -- if there isn't any help in finding the thesis of the essay, you're completely on your own to figure out what the heck is the point. It becomes so much mumbo-jumbo.

    I've maintained code which was almost utterly uncommented. It makes it really difficult to do, because you need to examine each piece in minute detail to get an idea of what it's there for. And then spelunk all over the place to figure out when it gets used and for what purpose. The first thing you usually end up doing is annotating it with some rudimentary comments so you can get your bearings straight.

    A long-standing habit has been to write the comment at the header of the function at the same time I'm declaring it. That allows me to get straight in my head what the heck I'm trying to do, as well as have a quick reference to it later when I'm perusing it.

    My favourite comment mechanism is a javadoc/doxygen type thing where you can mark up your code, and then be able to peruse it's structure from a mechanism separate from the source. And you can easily do it within the structure of your code without much pain.

    I think anybody maintaining that commenting code is a pointless excercise has no business writing code in the first place. The comments are the thread of higher-level thoughts that go into all of the highly specialized elements of actually writing code.
    --
    Lost at C:>. Found at C.
  49. The design contract by metamatic · · Score: 2, Insightful

    All projects, no matter how simple, require comments.

    The comment (or documentation) defines the supported API for the method or function. It is effectively the informal contract between the person writing the code and the person calling it.

    The importance of the design contract is that it allows you to refactor code effectively, rather than having to reproduce every single side effect and internal detail of the code in order to avoid unknown amounts of breakage elsewhere.

    And I'm with the previous guy in the thread. If you don't understand why all functions need comments, you shouldn't be writing anything even remotely important.

    And yes, even code you write for yourself should be commented, so that you can come back to it a year later and refactor.

    For example, take a very simple piece of code: something in a math library to add two vectors together. Suppose you implement it, and your initial implementation is generic and happens to work with complex numbers, rationals, dates, even strings. Well, that's great, but then you profile and discover it's a major bottleneck in your 3D graphics application. You want to refactor it to a high speed piece of inline assembler. You only intended to use the code for vectors of floats--but if you have no design contract, people might be using the routine with all kinds of data types, because it happened to give the result they wanted—and your hopes of a quick and easy refactoring are dashed. You end up having to define a new fastfloatvectoradd(), replace calls all over your code, and maybe end up with the original add() as dead code as far as your application is concerned.

    --
    GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
  50. The comments are the contract by metamatic · · Score: 1
    On the other hand, with commented code they are dealing with two similar but distinct things, that are related in exactly the same way as a fine-print contract (the code) and the car salesman's verbal promises (the comments). When push comes to shove, the salesman's words mean nothing and the contract is what matters.

    I beg to differ. If my library call is commented as "adds two integers", and you notice it also works for floats, use it, and then a new release has refactored code that crashes when floats are passed in... then when push comes to shove, I'm gonna tell you it's your hard luck. The comments are the contract; they're the specification of what I warrant the code to do. If it doesn't do what the comments say, then that's a bug, and it's my problem. If you act on the basis of what the code says, and something breaks as a result, it's your problem.

    --
    GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
  51. Sounds simple... by sexylicious · · Score: 1

    but before you draft any standards or anything crazy like that, try this:

    take your programmers, pair them up, and ask them to write some code and explain with NO comments to the other programmer what is going on in the code. If they can get the person to understand the code on the first try, great! That explanation is what you use to comment your code. If you're talking about a routine, fine, just make sure the explanation is in the comments.

    Then, take the same two programmers, switch roles, and repeat. You could even iterate over the process once or twice more and reassign the pairings. And heck, if it's an assigned task from management, like say, code a sorting algorithm, then that's even a bit easier.

    The whole point is to get everyone onto the same page for what is necessary for comments without patronizing the other person.

  52. Re: dynamically typed language by Anonymous Coward · · Score: 0

    > Good luck modifying code in a dynamically typed language that way. ... Just use a refactoring tool.

    Bzzt. Thanks for playing.

    The method I described works for all languages that have a statically defined execution that can be fully resolved at compile time. (This is the same subset of languages with which you can safely use a refactoring tool; lisp, perl, and python are not included.) Since there is no guarantee that your langugae supports such a tool, the "compile til it works" method is preferred.

    The problem is not with dynamically typed languages per say, but with dynamic execution. Just as you could not use a refactoring tool to change x["foo"]() to x["bar"]() in C++, you cannot change a perl/python member function with a refactoring tool either (hint: internally both perl and python use tables for their 'objects')!

    Things get even uglier when you include various dynamic function arguments (as opposed to say strongly typed parametric polymorphism) and runtime evaluation. These are things you cannot handle with either the "compile until it works" method or a refactoring tool.

    In short: once you cross into dynamic lanugages, you can't lean on tools anymore. You've got to become a better programmer.

  53. Re: dynamically typed language by pthisis · · Score: 2, Informative

    On the other hand, in the real world with real code, tools like BicycleRepairMan work great.

    Of course, I could have code that evals a strong, or changes the base class of a live object, or alters the inheritance hierarchy, or whatever in my Python code. That's incredibly uncommon in good code, though, and it's up to me as a developer to know when I'm playing games like that and account for them.

    In practice, for renaming a class/method/attribute, pulling up/pushing down methods and variables, etc BRM works find on 99% of my code--and the times that it doesn't are times that are obvious to anyone who knows anything about the system (it's not as though it silently fails in cases you'd reasonably expect it to work). And it integrates nicely with emacs and vim.

    --
    rage, rage against the dying of the light
  54. Here's what works for me (8+ years experience) by TechieHermit · · Score: 5, Insightful

    How to comment your project and thoroughly preserve your sanity:

    1. Ignore any standards anyone tries to force on you. Mostly such people are full of hot air, playing a role instead of just BEING a programmer. Things don't have to be buttoned-down. So, ignore the anal retentives and RELAX.

    2. Start sneaking around. Gather up everything you can get your hands on, from original user specs to whatever else. Everything you can beg, borrow, or steal, put in a folder in your desk. When you have some free time, digest it and produce short, easy-to-understand summaries. And, summarize EVERYTHING: business rules, expectations, requirements, EVERYTHING. A short, clearly written summary is worth ten pounds of worthless suit-speak memos.

    3. As you code, start each chunk of code (function, procedure, class, whatever) with a brief paragraph explaining, in your own words, what the purpose of the code is. Just briefly say "this is what I'm about to do, and this is why". Be brief, but specific. Mention anything weird, like odd parameters or whatever. If you have to return a weird string because Joe the Programmer is expecting it, explain it (without being cruel).

    4. Within your code, use self-documenting variables and make sure your indentation, etc (style) is clear and easy to read. I know I bitched about "standards" but it doesn't hurt to read a short book like "the Elements of Java Style". It's a good book. Make your code clean and easy on the eyes. It only takes a minute. USE WHITESPACE!!! Don't clump everything together like a core dump, add some extra lines here and there. A carriage return is only a byte (two if you're on Windows). It ain't gonna kill you.

    5. Whenever you do anything in your code that is non-obvious, like testing a column you got out of a database because there's junk data in there sometimes, EXPLAIN it. Just take a couple of lines to say "The import process sometimes sticks garbage in this variable, so we're doing a sanity check on it". You don't have to comment every single thing you do, but comment everything NON-OBVIOUS you do.

    And, that's about it. I think it's as easy as that. There's no need for company-wide training, or workshops, or any of that stuff. Just a little common sense, and a little effort, and your code's clear to everyone.

    1. Re:Here's what works for me (8+ years experience) by Kefaa · · Score: 1

      I wish I had points to up you. Yours is the approached I have used for far more than 8+ years and it works for the benefit of everyone. Not too time consuming but it give the person coming in some idea of what you may have been thinking. This is especially important when that "someone" is you and it has been three years.

    2. Re:Here's what works for me (8+ years experience) by trandism · · Score: 1

      Of course it doesn't hurt to read a book like "the elements of Java style".. What hurts is programming in java in the first place

      --
      www.lemonodor.com A mostly Lisp weblog
    3. Re:Here's what works for me (8+ years experience) by TechieHermit · · Score: 1

      Blah, blah, blah.

  55. Leave to individual choice, but train commenters. by seanyboy · · Score: 1

    My preference is to write self documenting code, but in the past even this has caused confusion for people trying to understand what it is that I've written. Good comments are worth their weight. However, Bad comments can cause more trouble than they are worth.

    Personally, I think that the choice to comment should be with the individual developers, and any developers that choose to comment should be forced to take some kind of workshop so that they are commenting correctly. Imposing an "everyone must comment" ethos without training will waste time and make your code base even more unreadable.

    I don't want to be "Mr No-sense of-humour", but writing deliberately hard to follow code is professionally unethical.

    --
    Training monkeys for world domination since 1439
  56. Comments and process are essential by Twylite · · Score: 1

    Process standards are essential. Make sure you have them and that you have developer buy-in. Avoid contentious issues that have little factual support.

    Off-topic: the first process standard you should introduce (if you don't have it) is source control; it has one of the highest cost/benefit ratios of good development practices. The second is configuration management (that is, proper control and version management of releases -- binaries and source code). The third is design and source code documentation.

    Typographic formatting (where to put brackets, etc) is of questionable benefit, and it's not worth pissing developers off unless they all agree on it. There are several research papers that show a small benefit in having a consistent style, but the majority of this benefit comes from a consistent style within one file, and to a lesser extent within one code base. Typographic differences across code bases have little or no implication for development and maintenance. On the other hand, most developers read all styles with similar effeciency, and write their preferred style with somewhat greater effeciency (that other styles).

    Typographic style also becomes a problem when you have legacy code that doesn't conform. What do you do when you maintain it? Update the style for the whole file; for the function being modified; just for the code you are modifying? Hint: changing the entire file or function makes it dramatically more difficult to use source control to identify (meaningful) changes. I have worked with several teams in which we have applied the rule "use the existing style for the file", with great success.

    Commenting is both a technical issue and a management issue:

    Technically, it is essential to comment code. Every reusable section of code (files, classes, namespaces, functions) should have a comment that explains what it is and how to use it. Without this, maintainers must make assumptions about what functions do, and how they are used; to confirm the assumptions they must read and understand the implementation. This is extremely inefficient.

    Aside: some people think that the use of a function can be implied from its prototype; this is often incorrect. It is seldom possible to assume parameter boundaries, object state (in the case of methods) or error responses given only a prototype.

    Every paragraph (block) of code that is not immediately obvious is a candicate for a brief comment indicating what the code is intended to do conceptually. These comments assist maintainers in navigating the code, and (in the case of bugs) understanding what it's meant to do instead of what is is doing (presumable erroneously).

    A documentation standard should prescribe what must be documented, the "syntax" of the documentation (e.g. you could use Doxygen), and what the documentation is intended to achieve (e.g. for functions, a developer should be able to understand and use the function without having to refer to its implementation).

    From a management perspective, risk related to poor coding can be mitigated by means of reviews and shared ownership; but risk also comes from the fact that intellectual property resides in people's heads not in source code. Unless you are intending doing a thorough walk-through of every legacy codebase with every new developer who joins the company, you need to have as much information as possible in the code, to allow knowledge to be transferred to new developers and maintainers. That means explaining the design and the implementation within the code.

    As for comments not being kept up to date, that is something which is trivially addressed by source control and oversight. Every check-in can be reviewed by a peer to ensure the correctness of the code, and that any relevant comments have been made or updated.

    Remember that source code is communication with other developers, not just instructions to a machine, and that makes writing style important. Sometimes it helps to think of source code like a book (the Book Paradigm).

    --
    i-name =twylite [http://public.xdi.org/=twylite], see idcommons.net
  57. Why comments instead of external docs? by Anonymous Coward · · Score: 0

    Everyone is railing on comments getting out-of-sync with code. This does happen. However, how many times has the average shop gone back to the design docs and altered them after finding out the initial design was unusable? I'll wager a lot less often then they've edited the comments in the code.

    Comments are also the only docs you *can* alter without having to do additional work - checking out the document, getting approvals, etc. You've already got the code out, so you can change the comments.

  58. That's nothing... by mindaktiviti · · Score: 1

    I use braile. In ASCII.

  59. Use a simple source code documentation covention by pabtro · · Score: 1

    Commenting Code

    Effective and practical documentation captures the intended use of modules, classes and routines in a user-manual-like form. In order to produce highly maintainable documentation, practice indicates that comments should not focus on explaining how the code works, but rather on how the code is to be used.

    If comments are used to explain how the code works, any alteration to the code will render the documentation obsolete, resulting in duplication of effort and inaccurate documentation.

    Plain English at the top of the file and each code construct should be used to describe its unique purpose and objective. Inline, detailed comments should be avoided because they cannot express the mechanics of the code more accurately than the code itself.

    By avoiding the description of "anything between the brackets", the formal documentation reaches the non-redundant level of abstraction needed to streamline the authorship, usage and maintenance of the code.

    http://www.ptlogica.com/TwinText/paper.htm
  60. If you could start from scratch by EraserMouseMan · · Score: 1

    you would have code patterns that would provide a framework for 95% of the code your company owns. I run a consulting company and here's what I did. I worked for a few years doing consulting work by myself before I had enough work to hire employees. I wanted to make my work simple and get to the point where I could do most of the coding in my sleep. I began looking at all of my code as just slight variations of the same patterns. I'd come up with a pattern, for say a persistence class, and perfect the format and consistency of it. Then for every persistence class I needed I'd copy one that matched the pattern and simply change the attribute/property names, database field & table names.

    I've written so many apps with that technique now that I've got code patterns for about 95% of everything I need. And maintenance is so easy because all of the code for all of the apps looks and works the same even the apps themselves serve completely different purposes.

    In addition I've taken all of the common facets of most custom apps and developed a common pluggable API with an underlying database that abstracts all of these details away. Things like role-based security, event logging, settings encryption/management, custom user directory and etc. So developers only tap into this API and never even need to write any code or re-invent the wheel every time user security is needed (for instance).

    So there's not really much documentation needed because most of the code is very recognizable for any developer who is used to the format of the patterns. And since we perform code reviews on each-other's code it is always kept in conformance to the patterns. I can work on anybody's code even if I've never seen it before because I instantly recognize the patterns.

    If you've got a whole team of developers who aren't used to producing pattern-based generic code it'll be hard to put a system like this into place. Especially since you have to develop the patterns over time as well as the common APIs you may need.

    In summary the best documentation strategy is:
    1) Consistent code patterns
    2) Pluggable libaries of common code tools (Aspect Oriented Programming (AOP))

  61. RE: The Importance of Commenting and Documenting C by Anonymous Coward · · Score: 0

    Martin Fowler once said: "At Object Mentor we call a comment in the source code a lie." He proceeded to explain that it was a lie because in a few months the comment and code will diverge, regardless of how much work was put in into trying to keep the two in synch.

    I tend to agree with Mr. Fowler's sentiment on this subject, because there is no need for comments in the Test Driven Development (TDD) environment.

  62. Re:documentation?? what's that? by DaveInAZ · · Score: 1
    On the rare occassion that I look at code and can't figure it out, I rewrite it because, obviously, the code sucks

    Sorry. Did you actually say you rewrite code you don't understand? If you don't understand it, you clearly can't know exactly what it's purpose is, so how can you rewrite it?

  63. Comment your DATA instead! by JCOTTON · · Score: 3, Insightful

    Ninty percent of my work when working on old programs is TRYING TO FIGGUR OUT THE DATA STRUCTURES. Not the code. The Data.
    How about the 25 different letters used in the field cryptically named "F-STATUS"? OR a date in a field named "D-Date"?
    Document your DATA structures you code-monkeys!

  64. Don't think of it as a bug... by LardBrattish · · Score: 1

    Think of it as a potential invoice

    --
    What are you listening to? (http://megamanic.blogetery.com/)
  65. Re:mod parent up # reposted as me by LardBrattish · · Score: 1
    If you fix a minor bug, and a week later you realize it's created a major bug, but in the meantime eight dozen commits have been made by your team, it's not always easy to just roll back to the version before the one you helpfully noted in the CVS comment as being "the" bug fix; you really do need to tag bug fixes in the code itself.

    No you don't, I've had to (far too regularly) go through 5 year old code riddled with tagged bugfixes of various epochs and I can tell you that generally they are more harm than good. Trust me a four year old end of line comment that reads "SRQ 5678" is not helpful to anyone.

    What you need to do is have a VCS with a good difference feature built in or read out version 1.23 pre bugfix & version 1.24 post bugfix & do a compare. THAT tells you what was changed to fix the bug better than 25 scattered tags (which may or may not be complete). Then, knowing what was changed you get 1.32 (the latest version) and undo the 1.23 -> 1.24 changes. I have used the VCS to backtrack through 50 revisions to find out who was responsible for certain braindead bugs & what I need to do to unravel them.

    Remember, VCS means never having to put bullshit comments like that into your code.

    --
    What are you listening to? (http://megamanic.blogetery.com/)
  66. Re:mod parent up # reposted as me by dkf · · Score: 1
    Trust me a four year old end of line comment that reads "SRQ 5678" is not helpful to anyone.
    It's useful, but only if you've still got the bug/issue database too. Not that having such a DB means you can get away with not having a revision control system and policy in place. Instead, you should use every tool available to try to keep track of what happened, and if putting a comment in means that you can come back to the code later and get back up to speed faster, that's an unmitigated Good Thing. Which isn't to say that the comments should be trusted implicitly, but well-commented code is so much better than uncommented or poorly-commented code since it helps you understand what other people have thought about this bit of code in the past.

    By the way, I have seen some neat systems which offer integration of issue database and revision control; they're very neat and if you've got access to such a thing, use it! (I'd offer a link, but I can't quite remember the name of it...)

    --
    "Little does he know, but there is no 'I' in 'Idiot'!"
  67. There is a bit of art to getting it right by Nelson · · Score: 1
    Commentless code is unacceptable.


    Code with comments on every line (short of certain function in assembly) is unacceptable.


    There is something to be said for consistency. I like the idea of "self-documenting" code or code that is so easy to read that it doesn't need documents but the fact is that no code is that to everyone, you have to assume a lesser engineer will at some point need to understand what you're doing. Just get used to that idea. I've seen commentless code with sentance like variable names and function names getNewHisteresisValueFromNetworkThrottleGovner(..) screw that, that's even less appealing.


    While I generally think the idea of mandatory doxygen or javadoc comments is kind of overkill and if the code is done well then it's usually fairly obvious what the code does and worse, when you do some serious refactoring all that documentation is just extra luggage to move around I think that there is another effect that requiring them can produce. It shows when someone cares or doesn't care and knowing that might be more useful than documentation.


    At one job I had, in an extremely high performance software engineering shop (world class,) they had a ton of rigid coding standards and guidelines. At the time it really seemed like a lot of extra hoops to jump through and I was younger and wanted it "my way" after a while though I had some converstaions with some people about it and they all thought that what was more important that consistent code was that if an engineer didn't care enough to follow those rules then they knew he wasn't going to work out. Mandatory code reviews, not becaues the code always needs it but it transfers knowledge, and then you oculd see them end in like 5 minutes because it wasn't formatted correctly or something wasn't documented, you go back and fix it and reschedule the review; if it takes too many reschedules then there is going to be a problem. And I kind of agree with that. You don't really have discipline unless you demonstrate it but the demonstration usually isn't really needed but it's a circular thing; you don't have the discipline to document every variable and function unless you do it but that probably doesn't really need to be done.


    At other jobs, I've seen people want to use javadoc and doxygen only to find it's nearly useless because 15% of the code is documented correctly. If you've ever dived in to a large project, poking around in doxygen is nice if it exists, while it may not be perfect it can get you a nice lay of the land. I think if you have any desire what-so-ever to use a tool like that then I think it is completely reasonable to require all classes, methods, etc. to have at least minimal documentation. Even getters and setters can be documented and it doesn't really hurt anything (turn on folding in your editor if it's too much for you) and if you have people that refuse or cannot get themselves to do that much then you know some other problems your project is going to have.

  68. One thing I don't understand by Anonymous Coward · · Score: 0

    why people take the in a lot of cases badly maintainable C/C++ (of course, it is up to the programmers to write proper code, but to what I've seen now) or VM-dependent implementations (.NET, mono etc) if they want to develop new (somewhere about 30% of the code you'll develop) crossplattform projects and either whine about bad maintainability or bad performance [both is subjective and relative, but the fact is that there are lots of whiners].

    FreePascal provides a really great middle between both - generates fast code, you aren't penetrated by aggressive memory management (while it is still required), provides a very powerful lib, provides a very powerful toolkit (as an example - smart linking). Your code will be REALLY portable and RAD is given.

    I wouldn't develop a client application in C++ (or ASM or whatever) today and I wouldn't take Java for system programming. FPC provides facilities for nearly every aspect of development.

    Well, what am I actually talking about? People don't even want to hear that their world is uncomfortable as they are just holding too much at the old world...

  69. Are you serious?-ReadySET by Anonymous Coward · · Score: 0

    ReadySET (open source)

    "What problem does this project address?

    Software development projects require a lot of "paperwork" in the form of requirements documents, design documents, test plans, schedules, checklists, release notes, etc. It seems that everyone creates the documents from a blank page, from the documents used on their last project, or from one of a handful of high-priced proprietary software engineering template libraries. For those of us who start from a blank page, it can be a lot of work and it is easy to forget important parts. That is not a very reliable basis for professional engineering projects."

  70. Re:mod parent up # reposted as me by cloudmaster · · Score: 1

    Tough to roll back to a specifiec version? Whatever do you mean? Examine the output from "cvs --help diff" and then tell me that it's hard to see what someone changed between two arbitrary revisions/dates. Sure, it's not trivial, but that shows you *exactly* what changed and when it changed. A comment says "whoops" but doesn't detail why the line above was accidentally deleted and re-added elsewhere...

    This, BTW, is why I like svn - every commit is repository-wide, not just per-file.

  71. Re:mod parent up # reposted as me by LardBrattish · · Score: 1
    Even with the issues database there's too much x-referencing required.

    I prefer (in an ideal world) the check in comment to be the issue reference + a broad brush description of what was done.

    PVCS/Tracker allegedly offers such integration but we've not got it working (not that I personally administer PVCS here) I'd prefer it if we went FOSS for issue tracking & VCS & wrote our own glue if it doesn't exist - it shouldn't be a big job & it's a nice bit of code to donate back that doesn't jeopardise any trade secrets...

    The version of PVCS we're stuck with here sucks nuts & I'm pretty sure that a FOSS alternative (in addition to saving a fortune in ongoing support that we don't use) would be at least as good and easier to fix up to meet requirements.

    --
    What are you listening to? (http://megamanic.blogetery.com/)
  72. Re:mod parent up # reposted as me by dup_account · · Score: 1

    If I find any bugs/issue numbers in code I have to work with the first thing I do is delete them. This sort of thing drives me nuts and makes me want to poke out peoples eyes with a sharp stick while chanting "Use CVS diff, Use CVS diff".

  73. Re:documentation?? what's that? by Chirs · · Score: 1

    "IMO, if someone comes up and asks for documentation, they need to be fired!"

    Okay, so how do you deal with external libraries for which you don't have the code?

    How do you deal with large projects with hundreds of designers, where you have to go in and change someone else's code? (Why do you think there are whole *books* documenting the linux kernel?)

    How do you ensure that when you come back to your code 5 years later (it happens in real life) you can figure out what's going on? If it took 2 months to get working in the first place, do you really think you can just start working on it again without introducing new bugs?

    Documentation should primarily describe *why* and *how* something is being done, at a suitable level of abstraction. Inline comments should at least describe *why* something is being done. If the code is particularly gnarly (cubic splines, discrete fourier transforms, funky optimizations, etc), then they should describe *how*.

    If you find that writing comments slows you down, then go back and add them at the end. But do it while you're fresh. There are times when I forgot, and had to sit for a while trying to figure out what the heck I was doing when I wrote it.

  74. Good comments are so rare... by RhettLivingston · · Score: 1

    that I consider the ability to hide all comments so that code is more easily read and the non-functional and often misleading comments cannot result in confusion and lost time to be critical. Far more critical aspects of code maintainability include code being formatted in the style that the viewer has become accustomed to and usage of object names that are informative and not misleading.

    One great advantage of removing comments is that auto code formatting to the style that you are use to seeing becomes nearly 100% effective. Handling of comments is always the big hangup in creating a good autoformatter. So, removing comments can have a very positive effect in this area. The need for formatting standards goes away if autoformatting to each engineer's preferences is 100% effective. This also helps in the portability of engineers as the spinup time into a different formatting standard when moving from one group to another goes away. Studies have shown that using the format that one's mind is trained to both increases code production and decreases bugs.

    I've also seen very few studies that look at the statistical question of whether the cost of commenting pays off. There are at least two major cases in which the cost of commenting will not pay off, the code doesn't need maintenance and major changes in design, platform, or development technology force a rewrite. I believe these two cases are very common. For example, when features are added to code, they are frequently added as new modules that hook into only a few places in the existing code or completely replace existing modules. In either case, the cost of commenting all code on the chance that it may need to be understood by someone with a coding personality type that requires comments may not have been a good investment.

    And that is another important point. Our current software engineering theory seems to look at programmers as all the same with all the same abilities and flaws. This causes as much trouble in our field as it does in the medical field. We need to be creating development platform technologies that allow each software engineer to be as effective as possible taking into account their specific strengths and weaknesses. This monocultural theory of software engineering we have today forces us to realizing the potential of the average of even the LCD instead of the realizing the maximum potential of each individual through techniques like automatically converting the view of the code base to each individual's needs. We are people, not machines.

  75. performance metrics by Moe+Taxes · · Score: 1

    My Company got bought by a shop with more money but less product then us. Three years went by and they were unable to assimilate us or even produce one their much anticipated new line of .NET based products. I found out why when one of their young programmers came to our location and spoke proudly of his steady improvement as a programmer, "I am up to 20% comments in my source code, when I first started I was really bad at about 5%" Good thing there were people here to hold me back, I really wanted to smack some sense into him.

    Here it is real simple: machine code is for machines, programming languages are for programmers, comments are for managers. The product of a programmers work is code that compiles and runs. Time spend producing comments and documentation is not time spend producing product. There is only one place to look and see what a program does and it is not the comments. If your programmers can't read the programming language, the comments will not help.

    For code readablity, a better metric than comment percentage would be symbol length. If you see a program with function and variable names that average 4 characters and another with a 15 character average you know which will be easier to read.

    --
    It took a real world war to end the airplane's patent wars. - Fâché Rouge -