Slashdot Mirror


Comments On Code Comments?

theodp writes "It seems like comments are on programmers' minds these days. The problem with comments, as Zachary Voase sees it, is that our editors display comments in such a way as to be ignored by the programmer. And over at Scripting News, Dave Winer shares some comments on comments, noting how outlining features allow programmers to see and hide comments as desired. 'The important thing is that with elision (expand/collapse),' explains Winer, 'comments don't take up visual space so there's no penalty for fully explaining the work. Without this ability there's an impossible tradeoff between comments and the clarity of comment-free code.' Winer also makes the case for providing links in his code to external 'worknotes.' So, what are your thoughts on useful commenting practices or features, either implemented or on your wishlist?"

472 comments

  1. Doesn't matter in the end by crazyjj · · Score: 5, Funny

    Changing the color of the comments, or making them collapsible/non-collapsible isn't going to have any meaningful impact. A rushed or sloppy coder is going to ignore them either way. And a conscientious coder is going to read them regardless.

    The real problem with comments isn't their color, it's when they AREN'T THERE AT ALL. You could have the damn things flashing in rainbow colors and it still wouldn't change the fact that the legacy code I'm going over was done by a sloppy piece of shit who never wrote any comments in the first place, or who wrote cryptic/indecipherable comments that would take a linguist 10 years to translate into meaningful English.

    Now, if you'll excuse me, I've got to go play Sherlock Holmes with some strange method written by an Indian contractor whose only comment on it was "This move thing around."

    --
    What political party do you join when you don't like Bible-thumpers *or* hippies?
    1. Re:Doesn't matter in the end by Anonymous Coward · · Score: 3, Informative

      Going even further - good code generally doesn't need a whole lot of commenting. If you are struggling with this problem of how to display comments, then that says a LOT more about your code than your comments.

      (That said, trying to deal with a legacy system, comments can be helpful.)

    2. Re:Doesn't matter in the end by D,Petkow · · Score: 0

      hahahah i wish i had some points to mod as +1 funny

    3. Re:Doesn't matter in the end by garcia · · Score: 5, Funny

      The real problem with comments isn't their color, it's when they AREN'T THERE AT ALL.

      THIS. I deal with sloppy coding convention all the time but at least when the code is commented I can get a mile-high view of what each section is doing w/o having to spend time carefully piecing the work apart to figure out what happened.

      The lack of comments for others is annoying but I really want to know how people go back into their own code several weeks (or even days) later and know what the hell they did when there are no comments.

      Many times I have run across a commented section of code that reads something like:

      /* Attention future Bill: this section of code sucks and it looks horrendous and awful but I wrote it under a tight deadline. Just hit F3 and let the bitch run; it works, I promise. */

      I can only shake my head at myself ;-)

    4. Re:Doesn't matter in the end by Anonymous Coward · · Score: 5, Insightful

      if you can't fit the documentation into your method (and variable names), that method is likely too long and complicated.

    5. Re:Doesn't matter in the end by Valor958 · · Score: 2

      For the legacy coding point, I'd like to make one suggestion on commenting. At the time that code was written, it wasn't 'legacy' code... but they still chose to comment (however poorly). I would suggest commenting where ever possible to clarify intent as you never know who will be fixing your code, and when people will be complaining that IT is legacy code. For the relatively minor amount of coding I have directly done, I commented a reasonable amount so as to locate code segments quickly and for others referencing my work to do the same for any debugging. Oh... and now, that code is considered legacy due to the nth-teen revisions made on it since 2002.

    6. Re:Doesn't matter in the end by locofungus · · Score: 1

      A rushed or sloppy coder is going to ignore them either way. And a conscientious coder is going to read them regardless.

      A rushed or sloppy coder is going to read them and rely on them regardless of what the code says.

      A conscientious coder is going to know they're wrong. Either the code is clean and self documenting in which case it doesn't need comments and even if they're factually correct they're wrong because they're not needed and might not be maintained with the code and if the code isn't clean and self documenting then it's inevitable that it doesn't things that the original programmer hadn't even thought of so the comment is, at best, a statement of what the original programmer intended to write.

      There are, of course, exceptions. But they're rare.

      Tim.

      --
      God said, "div D = rho, div B = 0, curl E = -@B/@t, curl H = J + @D/@t," and there was light.
    7. Re:Doesn't matter in the end by Dan+Dankleton · · Score: 5, Insightful

      Not necessarily. Good code can show what is being done, but it can't show different approaches which were rejected. Comments can explain why certain shortcuts are valid or not valid in a way which won't be obvious from the code.

    8. Re:Doesn't matter in the end by Sulphur · · Score: 1

      Changing the color of the comments, or making them collapsible/non-collapsible isn't going to have any meaningful impact. A rushed or sloppy coder is going to ignore them either way. And a conscientious coder is going to read them regardless.

      The real problem with comments isn't their color, it's when they AREN'T THERE AT ALL. You could have the damn things flashing in rainbow colors and it still wouldn't change the fact that the legacy code I'm going over was done by a sloppy piece of shit who never wrote any comments in the first place, or who wrote cryptic/indecipherable comments that would take a linguist 10 years to translate into meaningful English.

      Now, if you'll excuse me, I've got to go play Sherlock Holmes with some strange method written by an Indian contractor whose only comment on it was "This move thing around."

      The Zen was it not moving around.

    9. Re:Doesn't matter in the end by betterunixthanunix · · Score: 1

      THIS. I deal with sloppy coding convention all the time but at least when the code is commented I can get a mile-high view of what each section is doing w/o having to spend time carefully piecing the work apart to figure out what happened.

      // TODO: fix this

      Not all comments give you a mile high view. Some are just pointless wastes of disk space...

      --
      Palm trees and 8
    10. Re:Doesn't matter in the end by Rob+the+Bold · · Score: 2

      Many times I have run across a commented section of code that reads something like:

      /* Attention future Bill: this section of code sucks and it looks horrendous and awful but I wrote it under a tight deadline. Just hit F3 and let the bitch run; it works, I promise. */

      I can only shake my head at myself ;-)

      Preach! If anyone needs an argument for readable code and appropriate comments, it's this above, perhaps paraphrased: "The poor slob maintaining your work may be you."

      --
      I am not a crackpot.
    11. Re:Doesn't matter in the end by crazyjj · · Score: 4, Funny

      /* Attention future Bill: this section of code sucks and it looks horrendous and awful but I wrote it under a tight deadline. Just hit F3 and let the bitch run; it works, I promise. */

      Makes you want to kill Bill, doesn't it?

      --
      What political party do you join when you don't like Bible-thumpers *or* hippies?
    12. Re:Doesn't matter in the end by Big+Hairy+Ian · · Score: 1
      Or there's the sloppy git who comes to update your code but doesn't change the comments to reflect his changes so you end with code doing one thing and comments describing something different!

      On the other hand though I did like the ideas about having hyper-links in your comments just from the perspective of I can link in the original requirements from whatever ALM system they make me use and then anyone coming along could see the whole change history and hopefully identify & castrate the fucknugget who didn't update the comments to match his code :)

      --

      Build a Man a Fire, and He'll Be Warm for a Day. Set a Man on Fire, and He'll Be Warm for the Rest of His Life.

    13. Re:Doesn't matter in the end by 140Mandak262Jamuna · · Score: 1

      Now, if you'll excuse me, I've got to go play Sherlock Holmes with some strange method written by an Indian contractor whose only comment on it was "This move thing around."

      Oh, that comment? I know that guy. It must have been written by Lakshmanan Sivaramakrishnan Sethuraman Aiyer. He had the policy, "no comment I write would be longer than my name".

      --
      sed -e 's/Chuck Norris/Rajnikant/g' joke > fact
    14. Re:Doesn't matter in the end by crazyjj · · Score: 1

      I don't know what code you're reading, but the legacy code I get is anything BUT "self-documenting." Hell, I don't think Ken Burns could document most of the garbage I seem to always get stuck with.

      --
      What political party do you join when you don't like Bible-thumpers *or* hippies?
    15. Re:Doesn't matter in the end by Simon+Brooke · · Score: 5, Insightful

      if you can't fit the documentation into your method (and variable names), that method is likely too long and complicated.

      This is foolish arrogance. In my thirty years in this profession I have worked with many people who thought their code was 'self documenting'; all of them were wrong, and faced with their own code two years later I doubt any of them could immediately follow it. I've only ever worked with one software engineer who, in my opinion, documented enough; I strive to match his standards in my own code but I know I don't always succeed.

      There are, in effect, three reasons for not documenting:

      Arrogance 'My code is so clear and elegant it needs no documentation' Procrastination 'I'm too busy just now, I'll do it later' Obscurantism 'If I don't document my code, no-one else will be able to understand it so they can't sack me'

      These days I see poor documentation practice as a reason to negatively appraise an engineer; if it doesn't improve I'd seek to move them off my team. There's no excuse. Documentation - like source code - isn't, fundamentally, for you: it's to communicate with your colleagues and to the poor grunt who has to try to maintain your code, long after you've moved on to more interesting projects. And that poor grunt may not be as intellectually gifted as you are.

      --
      I'm old enough to remember when discussions on Slashdot were well informed.
    16. Re:Doesn't matter in the end by Tx · · Score: 4, Insightful

      The problem with that is there seem to be a lot of people who say, and possibly even believe, that their code is clean and self documenting, when in fact it is anything but. I would say that such people outnumber those who actually do write clean and self-documenting code by a significant margin. In those cases, where you find yourself looking at this code and realise you have no idea whatsoever what it's trying to achieve, much less whether it's doing it right or not, and you're thinking "just give me a f*@king clue, goddammit", any sort of comment, even a cryptic, half-assed effort, can be a lot better than nothing.

      --
      Oh no... it's the future.
    17. Re:Doesn't matter in the end by History's+Coming+To · · Score: 1

      As far as I'm aware (and I'm sure I'll be corrected if I'm wrong) but your average code file is simply plain text, the colour formatting is applied by the program you're using to view/edit it. So it doesn't matter how you decide to colour it, when I load it into gedit the comments are blue. Or is this a discussion of the formatting preference button for text editors?

      --
      Please consider this account deleted, I just can't be bothered with the spam anymore.
    18. Re:Doesn't matter in the end by afidel · · Score: 1

      I'd agree only if you're using a language or pre-processor which does design by contract.

      --
      There are 4 boxes to use in the defense of liberty: soap, ballot, jury, ammo. Use in that order. Starting now.
    19. Re:Doesn't matter in the end by Verdatum · · Score: 1

      The thing that really bugs me is when one has worked very hard to write the sort of code that doesn't need comments, but company policy or contractual agreements force their existence anyhow. For this reason, I think collapsable comments are wonderful. I expand them only when I hit someone's (possibly my own) WTF type code, and more often than not, I'm happy to say on my current project, I find a friendly plain-english explanation and apology for the confusion and misery. I likewise don't follow the argument that collapsed or funny-colored comments causes lousy programmers. Lax code reviews and insufficient training causes lousy programmers.

    20. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      The problem, of course, is that every programmer thinks his code is clean and self-documenting, especially at the time he is writing it.

    21. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      'The important thing is that with elision (expand/collapse),' explains Winer, 'comments don't take up visual space so there's no penalty for fully explaining the work. Without this ability there's an impossible tradeoff between comments and the clarity of comment-free code.'

      'The important thing is that with elision (expand/collapse),' explains Whiner, 'comments don't take up visual space so there's no penalty for fully explaining the work. Without this ability there's an impossible tradeoff between comments and the clarity of comment-free code.'

      FTFY

    22. Re:Doesn't matter in the end by bkaul01 · · Score: 1

      The real problem with comments isn't their color, it's when they AREN'T THERE AT ALL.

      I think that's the whole point of the color/collapse discussion, though, right? Without the ability to collapse comments, there's a real disincentive to including them, as they clutter the code and can make it difficult to read/follow directly. If you can collapse/hide them so that they don't obscure the code, then there's no longer a need to declutter by leaving them out, and hopefully more will be included. That argument, however, presupposes an intentional, aesthetic decision behind the lack of comments, while your point on lazy coders leaving sparse or cryptic comments is entirely valid. It's sloppy and lazy programmers that are the problem.

    23. Re:Doesn't matter in the end by dsvick · · Score: 1

      You could have the damn things flashing in rainbow colors and it still wouldn't change the fact that the legacy code I'm going over was done by a sloppy piece of shit who never wrote any comments in the first place, or who wrote cryptic/indecipherable comments that would take a linguist 10 years to translate into meaningful English.

      Cryptic and indecipherable!? That's terrible, I on the other hand have the luxury of dealing with comments that are completely understandable and where I know exactly what they mean. For example, the stellar programmer that wrote the legacy code I'm dealing with has hundreds of comments scattered about his code. In fact he has commented a majority of his function calls. Oh, here's one now, we call the function named getProductValues and we have helpfully commented it with get the product values - isn't that great?

      Now if the function didn't also add the item to the shopping cart and set about 30 session variables (only 2 or 3 of which are ever used), it might actually be useful. That and the fact that those types of comments are the only comments in the code. But when we declare the variable xCrfz do we comment that cryptic piece of crap .... hell no!!

    24. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      The sort of code that doesn't need comments, eh? Must be a very simple algorithm, then.

    25. Re:Doesn't matter in the end by dkleinsc · · Score: 5, Insightful

      Not at all:
      1. Sometimes you're using a confusing and complex feature of some library or server. Providing a comment with a link to the documentation on that feature makes things a lot easier for the next person to come along.

      2. Sometimes you're working around a bug in a library. You should leave a comment explaining what the mis-behavior was.

      3. Sometimes you're implementing an algorithm that's relatively new academic work. Adding a comment explaining exactly what this is, where you can find it, and why you're using it here will help somebody learn more about it.

      4. While expressive code can explain what you are doing, it can't explain why you're doing it. If your method is called "zoich_the_fleemoid", your comments about this should probably provide some kind of indication of what a fleemoid is and why you'd want to zoich it.

      5. Anything residing on a major code boundary (e.g. a library method relied on by other developers) should get the full round of documentation - what it does, what it accepts as parameters, what it does with those parameters, what it returns, and what side effects are expected. Yes, your code should be clear enough that the other devs could learn this stuff by reading your code, but they shouldn't have to dive into it to figure out what your APIs do.

      It's a very rare case where I think a programmer wrote too many comments.

      --
      I am officially gone from /. Long live http://www.soylentnews.com/
    26. Re:Doesn't matter in the end by ciotog · · Score: 2

      // TODO: fix this Not all comments give you a mile high view. Some are just pointless wastes of disk space...

      I don't see anything wrong with flagging a section of code with "TODO"... It at least let's the next person know that the code might be incomplete/buggy

    27. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      neither of which actually documents the code, it's design and intent documentation, which has no place inline the code but as a separate reference into a developer guide of some sort.

    28. Re:Doesn't matter in the end by Anonymous Coward · · Score: 1

      My problem with comments is they never seem to get updated when the code is changed - for whatever reason. So, you end up with comments explaining 'This is what the code does (or is supposed to do)' and then the code actually deviates significantly from that. I don't comment my code very much, but I will when I have to do something that appears strange when looking at the code (I once had to use a loop with a counter to iterate through a set of rows from a query because a simple foreach loop just wasn't doing what it normally would have done. This was different enough that I needed to comment it to explain why I did what I did) or to make it easier to follow in some cases.

    29. Re:Doesn't matter in the end by v1 · · Score: 4, Insightful

      That brought a smile to my face. More than a few times I've put in comments like "yes it's doing it this way for a reason. don't try to optimize it by doing xyz, it doesn't correctly handle exceptional cases x and y. leave it alone."

      I don't have a good memory, and my comments are for me as well as for others, even in projects that will never be seen by another living soul. Many times I've looked over some code and thought "that would work better / be so much cleaner if I changed that..." only to see one of my warnings that it had already been attempted and lead to unexpected complications.

      But I would like to see more of an option to "collapse" comments. I usually place a comment block above every functional block of code. Most of the time I just need to see a quick one-liner reminding me what all that block does. Other times I need specifics like "this stuff is set on entry, and these things are set on exit" etc. But the detailed comments eat up a lot of screen space and make it take longer to scroll through code looking for things. I'd like to be able to have expandable/collapsable comment details. On a global basis.

      --
      I work for the Department of Redundancy Department.
    30. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      You missed the main reason.

      coders are paid to code and meet deadlines set by business people. You can't sell customers comments.

    31. Re:Doesn't matter in the end by Splab · · Score: 1

      4th: I'm a contracter and get paid by the hour, spending time trying to untagle others (or my own) mess works in my favor.

    32. Re:Doesn't matter in the end by RabidReindeer · · Score: 5, Interesting

      I was very amused when Donald Knuth announced Literate Programming, since I'd been doing something quite similar for years, although there weren't any automated tools back then.

      First I wrote WHAT the function was supposed to do. This was the comments.

      Then, I wrote the code to DO it.

      If I did the job right - and kept the comments up to date (people really manage to do that?), then when I came back to make fixes or improvements, I'd know what the code was doing and what the likely consequences of changing it could be. Including the less obvious ones, such as things that depended on subsidiary routines.

      I have extra incentive to write good comments these days. Back then, major systems often had program logic manuals. These days, the apps are more complex, but the time to sit down and write a PLM is rarely there. However, if the comments were well-done, tools like Oxygen and Javadoc can generate a fairly decent substitute.

    33. Re:Doesn't matter in the end by Anonymous Coward · · Score: 2, Insightful

      This is foolish arrogance. In my thirty years in this profession I have worked with many people who thought their code was 'self documenting'; all of them were wrong, and faced with their own code two years later I doubt any of them could immediately follow it.

      [...]

      Documentation - like source code - isn't, fundamentally, for you: it's to communicate with your colleagues and to the poor grunt who has to try to maintain your code, long after you've moved on to more interesting projects. And that poor grunt may not be as intellectually gifted as you are.

      I always write comments with the thought in mind that the poor bastard who has to maintain this code years from now might turn out to be me.

    34. Re:Doesn't matter in the end by Anonymous Coward · · Score: 1

      That is utter nonsense. We have 20+ projects, most of which have 5 to 20 years of coding under the belt, the total code-base size is several million lines of code, and I've got yet to see a case where comments written by the person writing the code actually made impact on understanding of the code. I've maintained my own code written 5-10 years ago, and I have no problems getting back in there and knowing where things are. Some of that code remembers times when DOS didn't exist.

      The problem with comments is the same as with any other documentation, especially written by engineers - all engineers, and specifically software engineers even more so are trained to take mental shortcuts - that's how you get things done. That's why they are engineers, not theoretical mathematicians or nobel prize winners in literature. That's why we pay them the big bucks. From what I've seen, the best comments are written by OTHER engineers reading someone's code, because they know where they had problems understanding the code. Otherwise, the comments end up being a ton of useless bloat that just makes things harder to understand, not easier.

      Aside from that, code is documented in more than one way. Machine code is effectively the code without documentation. Each level of language you go up from there is a form of documentation of the code. Object orientation is popular precisely because of that - it allows you to organize your projects so you can go back in there and understand later what was happening. Spending effort on proper organization of the code will always beat spending time on some hazy comments which ultimately are most likely readable only to the person who wrote them in the first place (which is exactly the same as writing bad code).

      Finally, that's where you get your bug-tracking and change management in place. If those two are integrated, all the relevant information regarding what is good and what is bad is automatically in your bug-tracking system. If your bug-tracking and change management consists of code comments, you have a problem.

      Learn to engineer.

    35. Re:Doesn't matter in the end by Brian+Feldman · · Score: 1

      If you can't get that from the class/directory/whatever structure of the program/system then no amounts of comments are going to help -- you need a manual or to simply dive in to ever understand a system like that. Code clarity is not a localized concept. You need to work hard to make sensible naming schemes and hierarchies and to make it very clear when crossing boundaries where things tie together (e.g. the Model/View/Controller paradigm). This absolutely eliminates a large amount of comments and if your comments are so thick and heavy that they are overwhelming the code, it sure as hell better be because you actually are describing a difficult algorithm, not just duplicating your code into English.

      --
      Brian Fundakowski Feldman
    36. Re:Doesn't matter in the end by jandersen · · Score: 2

      The real problem with comments isn't their color, it's when they AREN'T THERE AT ALL

      Bad comments are worse than no comments. And good comments become bad when they are not being maintained along with the code.

      I think it is a question of attitude; people in general do not think of documentation and comments as being as important as the code, and it starts at management level. But there is another side to this problem: people have not been taught how to comment well, so actually, the problem to some extent starts even before project leaders get their grubby hands on things.

      And writing good comments isn't easy; but I think the best way is to write relatively few, relatively large blocks of explanations, which DO NOT point out the obvious, but explain things like which part of the code the comment concerns, what the parameters and return value mean (not what they are, what they mean) and how other parts of the environment influence the execution. And not least, how and why this code is deviates from what you would expect to find, if applicable.

    37. Re:Doesn't matter in the end by c++0xFF · · Score: 5, Insightful

      Code, by definition, tells the computer how to do something, but not why. The computer doesn't care why it's adding two numbers together, it just obeys.

      Likewise, self-documenting code will only ever tell the programmer how the computer does something, but will never tell the programmer why. That's the job of the comments.

      The problem is that most people focus on "how comments," instead of "why comments." They spend their time on the function comment block, describing even the most mundane function in detail (but never actually saying when to use the function or how the algorithm works). Or they spend their time on the comment block at the start of the file (doing the job of your version control software). (The occasional "signpost" comment is a good idea, of course, as is documenting the API. Some "how comments" are still very useful.)

    38. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      Good code is augmented by good comments which makes maintenance much easier for everyone. I typically write the comment header for each function/method/procedure before writing any of the code of the section. Then after finishing the code revisions I add comments internal to the function/method/procedure as appropriate and revisit the comment header to ensure it explains the purpose, the input and output and any side-effects. If I need half a screen to explain the code, I restructure the code; at most the code should require to screens and the comment header less than 10 lines.

    39. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      Totally agree, and this is the only reason comments are in our codebase at all. We do away with the comments that don't explain edge cases and implementation trade-offs. Most documentation (including comments in src) tends to get forgotten when the implementation changes. Further, the requirements get forgotten if they are not implemented as integration tests, so we don't bother trying to update them from sprint to sprint in document form.

    40. Re:Doesn't matter in the end by mothlos · · Score: 1

      Oh the ire of the to comment/not to comment controversy. Confusing uncommented code is frustrating, but so is confusing overcommented code. The no-comments side is trying to fight the very real specter of those programmers who think that writing big, bad code is acceptable if you comment the hell out of it. An overly complicated function with a lot of comments is now two problems, the code, and the maintenance of the in-source documentation of that code.

      I will admit I think that ideological objection to comments is too extreme for my taste, but there is validity in their concerns. If you can't explain an entire function in a couple of lines, then that function is likely going to be difficult to maintain. If you write something hacky (which is sometimes legitimate, but don't let the youngins hear you say it) then you had better document the hell out of it. When there is the ability to choose the language for a project, consider how readable the code is going to be so that less effort needs to go into creating and maintaining the comments.

      In the end, the argument shouldn't be to comment or not to comment, but how can we write code--including comments--which is easier to understand and maintain.

    41. Re:Doesn't matter in the end by internerdj · · Score: 0

      Nor should it. If your code needs explaination of that detail (read your organization is willing to fund your documentation to that level) then it is likely that plain text is a poor method of communicating your design.

    42. Re:Doesn't matter in the end by Hillgiant · · Score: 3, Insightful

      If your comments are not getting updated, then I suspect you have very poor revision control. I recommend that you take a step back and consider why you are revising the code in the first place. Once you understand why, you need to document it for the next poor sap (recognizing that YOU might be the sap). Only then should you consider how the code should be changed.

      --
      -
    43. Re:Doesn't matter in the end by digitalaudiorock · · Score: 2

      I couldn't agree more. No matter how well you code there are always reasons for comments...especially when the nature of what the code is trying to accomplish is complex. Even if your code is perfectly structured and understandable by any good programmer, making someone else reverse engineer that is inexcusable. Another example is when your code needs to do something in what may appear to be round about or unusual manner for some specific reason...because, for example, a more obvious approach causes some sort of problems...that is, so someone doesn't come along and try to "fix" it.

      People have a lot of weird ideas about comments, and I don't get it. It seems pretty clear to me what parts of my code require some sort of explanation...and not just for someone else, but for me as well. I can't tell you how many times I've read my own comments to remember why I took a specific approach to something.

    44. Re:Doesn't matter in the end by Hillgiant · · Score: 2

      So basically you are stupid and cannot explain design choices. What other reasons are there to not document it?

      --
      -
    45. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      Kudos.

    46. Re:Doesn't matter in the end by jythie · · Score: 4, Insightful

      That is one of my major complaints. When time is short and changes are being made fast and furiously, or prototyping is being done, time spent commenting comes out of time getting something completed under a harsh deadline... which means comments are often not updated to reflect the new state of the code.. and incorrect comments can often be worse then no comments at all.

    47. Re:Doesn't matter in the end by locofungus · · Score: 3, Insightful

      Exactly my point.

      The people who write code like this don't know what it is doing when they write it. Therefore, by definition, at best their comments will tell you what they *meant* to write.

      Given that this code is now 10, 15, 20 years old, other programmers along the way will now be relying on what this code *actually* does.

      It's one of my pet peeves that people want to rewrite code when they *can't* understand it. But in order to rewrite code like this you *have* to understand it. I've seen so much rewritten code that is even worse than the code it replaced because it's full of hacks reproducing all the accidental behaviour in the original code and introducing its own accidental behaviour along the way.

      It is a wonderful thing to be given the chance to rewrite a piece of obnoxious code. But it's an expensive process with a lot of up front research and, is always harder than fixing that obscure bug in the obscure code *except* when you've already proved that the obscure bug *cannot* be fixed in the old code. But in that case you're already admitting that the rewrite will change some behaviours.

      Tim.

      --
      God said, "div D = rho, div B = 0, curl E = -@B/@t, curl H = J + @D/@t," and there was light.
    48. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      neither of which actually documents the code, it's design and intent documentation, which has no place inline the code but as a separate reference into a developer guide of some sort.

      Because it is much more practical to have that information in separate document than shown by GUI when you look at the code. It is so much faster to open other document and search in it then to have the information right there. Yep.

      All those little popups when you hover over the method that explain what API does and which exceptions can be thrown are equally useless. We do not need that. We would prefer to look it up via google each time.

      Righ.

    49. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      you know, java is not the only language on earth.

    50. Re:Doesn't matter in the end by TheSpoom · · Score: 4, Insightful

      So basically you are stupid and cannot understand code. What other reasons are there to write cute little comments?

      Ah yes, the arrogance category. Thank you for your example.

      --
      It's better to vote for what you want and not get it than to vote for what you don't want and get it.
      - E. Debs
    51. Re:Doesn't matter in the end by richlv · · Score: 1

      that does sound a lot like reason one from http://developers.slashdot.org/comments.pl?sid=3101553&cid=41259653 :)

      also, if your code can really document _why_ it does everything somebody might have a question about... nah. reason one ;)

      --
      Rich
    52. Re:Doesn't matter in the end by siride · · Score: 1

      I don't think revision control has anything to do with it. It's a matter of taking the time to change the comments near a block of code when you change that block of code. Revision control neither helps nor hinders in this process.

    53. Re:Doesn't matter in the end by serviscope_minor · · Score: 4, Insightful

      Likewise, self-documenting code will only ever tell the programmer how the computer does something, but will never tell the programmer why. That's the job of the comments.

      Yes.

      Hands up who has seen a piece of code like this:

      //Add 1 to i
      i++;

      Bonus points if it's pre/proceeded by a complex block of uncommented, impeneterable code.

      --
      SJW n. One who posts facts.
    54. Re:Doesn't matter in the end by Lord+Lode · · Score: 1

      Documenting code is useless, documenting code means something like this:

      int i = 5; //Declare an integer called "i" and set its value to 5

      I agree with the grandparent post that comments in the code with references to papers, the "why" or something, the design decisions, bug fix references, etc... is very useful.

    55. Re:Doesn't matter in the end by devent · · Score: 1, Informative

      No, that is for what tests are. Tests and a Version Control System for the old approaches.

      You implement a solution, then you experience a bug for which you write a test case. Then you re-write your solution so the test passes. No need to write any comments, you have a test that documents the bug. Also in the future if you re-write the solution again, you are sure that you will not experience the same bug again.

      Of course that approach means you have actually write a test and fix the bug. More easily is of course to write a comment like "Don't touch that, it's a corner case Foo that I experienced in 1988".

      My opinion on hide or collapse stuff is very easy: it's a bad idea. Sooner or later developers will hide a lot of stuff, code, comments, it's like why it is a bad idea to hide stuff under the carped: clean up your room and not hide the dirt under the carpet.

      --
      http://www.mueller-public.de - My site http://www.anr-institute.com/ - Advanced Natural Research Institute
    56. Re:Doesn't matter in the end by Hentes · · Score: 1

      But I would like to see more of an option to "collapse" comments. I usually place a comment block above every functional block of code. Most of the time I just need to see a quick one-liner reminding me what all that block does. Other times I need specifics like "this stuff is set on entry, and these things are set on exit" etc. But the detailed comments eat up a lot of screen space and make it take longer to scroll through code looking for things. I'd like to be able to have expandable/collapsable comment details. On a global basis.

      What I do is put my comments in the same line as the code. When I need to read the comment I just scroll right, but otherwise it doesn't distract me or eats up screen space. If it's too long, I split it up between different parts of the code. For example, I explain what a function does in the line before it, but I detail how it does that (if explanation is necessary) in the body after the lines.

    57. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      In-code comments are usually insufficient for explaining the difficult concepts, which are higher level, and unnecessary for explaining the obvious concepts, which are what the instructions do. There are only three sane use cases for in-code comments: One is to warn against "obvious improvements" that are actually not going to work (and why). The second is to "extend" names that are used in the code (what kind of information is in which variable and parameter). The third is to give a high level description of a code block's purpose (what it does, not how).

      The difficult concepts are hidden in the design of the software, not in the implementation details. The most useful documentation and the one which is most often absent is that which explains how the parts make the whole and which design choices and constraints influenced which parts of the architecture. This is the stuff that is usually hidden behind APIs, but when you have to dive into someone else's code instead of just using it, you need that kind of documentation most of all. Once you know why a piece of code is there and what it's supposed to do in the big picture, detailed comments are usually not even necessary anymore.

    58. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      THIS. I deal with sloppy coding convention all the time but at least when the code is commented I can get a mile-high view of what each section is doing w/o having to spend time carefully piecing the work apart to figure out what happened.

      // TODO: fix this

      Not all comments give you a mile high view. Some are just pointless wastes of disk space...

      I agree that the comment you quoted is poor -- it really should have been expanded to include at least some idea of what to fix.

      However, I'd disagree that the comment you have is pointless. At least you know that there's something to do, even if you don't know what it is.

    59. Re:Doesn't matter in the end by Hentes · · Score: 1

      True, but documentation can also be achieved by other means than just comments.

    60. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      emacs is not the only code editor. java isn't the only one that does those things and it is likely more tied to the IDE than to the language.

    61. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      /**
        * Todo
        */

    62. Re:Doesn't matter in the end by Anonymous Coward · · Score: 1

      Code as hypertext, with links to the notes and recordings of the auditing and design meetings per section sounds like an interesting idea.

    63. Re:Doesn't matter in the end by nynexman4464 · · Score: 1

      I'm not sure it's always arrogance why developers think code is clear. I think it's more that you are knee deep in the code you just wrote, and know it so well that it *seems* very clear. It's only when you come back to it much later, or have to explain it to someone else that you realize "oh, I guess that wasn't so clear at all".

    64. Re:Doesn't matter in the end by gr8_phk · · Score: 1

      Going even further - good code generally doesn't need a whole lot of commenting.

      I keep hearing that, but it's just not true. Suppose you have a function to compute sin(x) and it doesn't say that it uses a particular taylor series to compute the answer - it's just a big fat equation. If anyone ever questions it, you're going to be googling around for various ways to compute sin(x) and figure out which one this is. Perhaps it's an approximation that made sense at one time, but someone finds it's not good enough for what they are doing. The name of the function is a good indicator what it does, but without comments you may not have any idea HOW it does it or what its limitations may be.

      Now that I've written that, I notice what I quoted says "doesn't need a whole lot" and I agree after all. It's people who say "doesn't need any" that I disagree with. One comment to indicate the method and/or accuracy of computation would suffice for my sin(x) example in my opinion.

    65. Re:Doesn't matter in the end by gr8_phk · · Score: 1

      Nice sarcasm but as an example, do you think people learn OpenGL by reading the Red Book, Blue Book, Orange Book, and writing code or do the learn it by reading the header files? External documentation has its place and can be important.

    66. Re:Doesn't matter in the end by TuringTest · · Score: 1

      I think he mentioned revision control because the diffs showing how the code logic has changed should also include the diffs of updated comments to reflect those changes. Commit time is the best point to ensure that all accepted changes have been properly documented.

      --
      Singularity: a belief in the "God" idea with the "demiurge" relation inverted.
    67. Re:Doesn't matter in the end by EmperorOfCanada · · Score: 4, Insightful

      Agreed. I find commenting is a good diagnoses for either OCD or micromanagement by a quasi non programmer. It drives me bonkers to see a function like this:

      //*********
      //GetNumberOfUsers is a function that will return an integer
      //describing the number of users that match the parameters entered
      //category_id is an integer containing the category of user
      //country_id is an integer containing the country code
      //company_id is an integer containing the company identifier.
      //Created:BOB_MILLER:2008-08-09:14:24:34
      //Edited:BOB_MILLER:2008-08-09:14:24:39
      //Edited:BOB_MILLER:2008-08-29:10:24:39
      //Edited:BOB_MILLER:2008-09-09:16:24:39
      int GetNumberOfUsers(int category_id, int country_id, int company_id)
      {
      //this will hold the number of users
      int num_users=0;
      //Get a connection to the database
      DBConnection db=new DatabaseConnection('central_database');
      //check to see if connection is good
      if(db==null){explode();}
      //good didn't explode so do next statement
      ...
      //Close database connection
      db->Close();
      //Now return the number of users
      return num_users;
      }//GetNumberOfUsers(int category_id, int country_id, int company_id, int some_param_that_used_to_be_here)



      The key information should be put into the naming of the variables, functions, and classes. Comments should be reserved for almost a conversation with another programmer. Magically perfect code should in theory have zero comments.

      x=x+1; //This compiler acting is screwy so I didn't use the more efficient x++ here
      x=sqrt(sin(log(y)/pi)*e);// this is the lambert/highlander formula
      x=lookup_table[y]; //This look-up table speeds things up by 100x.
      x=sin(tan(cos(x)));// If I knew my trig better there must be a better way to condense and speed this up.

    68. Re:Doesn't matter in the end by Jake+Griffin · · Score: 4, Informative

      That's why you have TEST CASES for cases x and y; so that if someone ignores the comment, tests will break alerting of an issue!

      --
      SIG FAULT: Post index out of bounds.
    69. Re:Doesn't matter in the end by Zero__Kelvin · · Score: 2

      "You implement a solution, then you experience a bug for which you write a test case."

      Great example of the implications of Godel incompleteness! Unit Tests are awesome, as are other kinds of automated tests, but they are not without their own problems. Say I fall for your argument of adding levels of indirection to the documentation and go to the test for the answer. Will I then find the why of the implementation? Will I find important information about the code, like that it does something different than the documentation says because the documentation is in error for version x.y of the API, and that I should change it back to the documented method if they fix the API in a later version? If yes, have I not then still documented the code with comments? If no, wouldn't I make a better Janitor than programmer?

      --
      Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
    70. Re:Doesn't matter in the end by Anonymous Coward · · Score: 1

      I agree. The code says "what". The comments say "why".

    71. Re:Doesn't matter in the end by Chris+Mattern · · Score: 1

      Wrong, wrong, wrong. Good code doesn't need comments that explain what the code does, yes; that should be clear from the code itself. But even the best code can't explain *why* the task is being performed, why this method of performing it was chosen, or what calls to other code (for which there may or may not be available source) do exactly. All this needs to be commented.

    72. Re:Doesn't matter in the end by nschubach · · Score: 1, Insightful

      Until the resource no longer exists.

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
    73. Re:Doesn't matter in the end by Zero__Kelvin · · Score: 1

      "My problem with comments is they never seem to get updated when the code is changed - for whatever reason."

      Your problem is not with comments, but rather with incompetent programmers who don't know how to write software properly.

      --
      Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
    74. Re:Doesn't matter in the end by Jake+Griffin · · Score: 0

      Or worse, this:

      //Make it lowercase
      $s = strtolower($s)

      //Convert $s into a string
      $s = "" . $s . ""

      "Are you freaking kidding me?! It was ALREADY a string! And PHP does automatic conversions anyway! And those comments are USELESS! WTF?!?!?"

      --
      SIG FAULT: Post index out of bounds.
    75. Re:Doesn't matter in the end by SQLGuru · · Score: 1

      The reason they spend so much time on the comment block at the beginning is because of the auto-doc / code-context tools. If you put the "magic comment" info in, then you get pop-up text telling you the details about the arguments, for example.

      Personally, I think commenting too much of the why in the code takes away from the design document. The design document should be a lot more complete (and in proper language instead of sentence fragments) -- including images and flowcharts and links to business rules. If you rely on the comment to understand the code, you miss a lot of the key information that a design document provides.

      Comments that a brief but include references to the location in the design doc (i.e. version / page / section of the document) are more useful (and less clutter).

    76. Re:Doesn't matter in the end by VortexCortex · · Score: 1

      This is foolish arrogance. In my thirty years in this profession I have worked with many people who thought their code was 'self documenting'; all of them were wrong, and faced with their own code two years later I doubt any of them could immediately follow it.

      I claim my code is Self Documenting, and I can absolutely & immediately catch the past train of thoughts by following tracks of code lain down even a decade ago or longer. Not that I'm saying you're foolish or arrogant yourself (although this may be the case), it's just that what you call 'self documenting code' I call 'self commenting code' -- There is a subtle but significant difference.

      I never liked the term 'self documenting code' meaning expressions that describe themselves implicitly. I always thought 'self documenting code' would be better defined as code with good descriptive comments along with the reasonable symbol names. I consider my comments part of the code when I say that my code is self documenting. I use descriptive doc-comments, as well as code-comments and generate documentation from the code itself with Doxygen. My source code editor understands the comments. When I hover over or [context-key] while on an occurrence of a variable, function, structure, etc I'm shown the remarks for that symbol or its type. This helps considerably increase my productivity; Eg: The order of method parameters and descriptions of data fields can be accessed immediately as I type rather than requiring me research external documentation. Thus, taking the time to write good documentation within the code itself actually pays off by allowing me to write more code faster. Since my source code files are sufficient input for the generation of a fully descriptive HTML (or LaTex, PDF, etc) documentation I assert that my sources are 'self documenting code'. As for merely using symbol names that comment on their purpose: I call this 'self commenting code' instead.

      For my fist games I used ANSI / ASCII art necessarily for "graphics", so naturally I insist my source code editor include line drawing and texel raster tools at the very least in order to make self illustrating comments. It's too bad the text based image formats (like SVG) are so damn verbose, and code editors don't display such as graphics within the source. Addressing this and adding graphical features to my source code editor is on my //TODO list; Now, that would be truly Self Documenting.

      So much to do, so little time.

    77. Re:Doesn't matter in the end by locofungus · · Score: 1

      Huh?

      The OP I replied to was saying why a sloppy programmer would ignore comments while a conscientious programmer would read them.

      My reply was why, IME, a sloppy programmer reads and relies on comments while a conscientious programmer will ignore what they say and rely on the code.

      IME code is either so new that it's clear and concise that comments aren't really required or was written by someone who employs coincidence programming (making changes until it appears to work without understanding why it works) in which case comments aren't going to help.

      Or, code is old, maintained by hundreds of people over tens of years with differing priorities and skills in which case the comments are incomplete, inaccurate, or just plain wrong.

      I have seen major business affecting bugs caused because someone believed a a function did what the comment said and not what the code said.

      I know someone who is a rather good musician. When she is analyzing a piece of music from the score she puts on a different piece of music in the background. This is because if she just reads the music then sometimes she hears what she thinks is there rather than looking at what is actually written especially if the music unexpectedly fails to follow some fairly standard progression.

      Comments can have the same effect in code. They can be useful but they can also mislead. They can even stop you seeing bugs in the code.

      Throughout my more than twenty year programming career I have, almost exclusively, been given other peoples old, buggy, inefficient code to "sort out". Whether that be to fix some obscure, intermittent bug, speed it up or make it work in some new use case.

      I am envious of these people who manage to only work on clean, well documented code. I suppose there are two possibilities: 1 - that I'm so good at making sense of utter crap that my skills are too valuable to waste on code that anybody can understand or 2 - that my style of coding is so appalling that nobody dares to let me loose on this beautiful code that everybody else deals with.

      Tim.

      --
      God said, "div D = rho, div B = 0, curl E = -@B/@t, curl H = J + @D/@t," and there was light.
    78. Re:Doesn't matter in the end by nschubach · · Score: 2

      Otherwise, the comments end up being a ton of useless bloat that just makes things harder to understand, not easier.

      This right here is more of the reason I completely skip comments when reading code. I haven't read much code where the comments put any valuable content that the code didn't explain better.

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
    79. Re:Doesn't matter in the end by complete+loony · · Score: 1, Flamebait
      And then the how changes....

      // Add 1 to i
      i+=2;

      --
      09F91102 no, 455FE104 nope, F190A1E8 uh-uh, 7A5F8A09 that's not it, C87294CE no. Ah! 452F6E403CDF10714E41DFAA257D313F.
    80. Re:Doesn't matter in the end by SDF-7 · · Score: 2, Informative

      Yeah, that sounds much more efficient. Nothing like letting the developer work through the (bad) optimization design, code it... get the test failure and then waste more time debugging it instead of just warning them off up front.

      Belts and suspenders -- test your corner cases, but document the pitfalls.

    81. Re:Doesn't matter in the end by SuricouRaven · · Score: 2

      My comments tend to be more along the lines of 'Don't quite know how I wrote this, but it seems to function.' I'm just a hobbyist, but I suspect that more than a few mega-corp software engineering projects are the same. At least I don't use 0xB00B135

    82. Re:Doesn't matter in the end by SuricouRaven · · Score: 2

      If I saw that, I'd conclude that the convert-to-string bit was put in first, and the make-it-lowercase a later addition to the code.

    83. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      There are diminishing returns on comments and also bad comments, but virtually all total refusal to comment boils down to one of the three reasons this guy has pointed out, and the arrogance argument is usually used to cover the other two.

      If you don't comment your code at all, you are a shitty coder. A mechanical engineer can't get away with leaving his diagrams unlabeled. An electrical engineer can't get away with leaving his schematics unlabeled. A chemist can't get away without documenting and explaining his formulas. So why the fuck do programmers think it's okay to design something without explaining what its purpose is or how it's supposed to work?

      Nobody is too good for documentation, and the resistance to comments all comes down to attitude. It is a shitty, lazy attitude that produces a programmer who refuses to comment at all. What really baffles me is why so many Open Source supporters embrace this attitude. When you don't comment your code, you are needlessly making it that much harder and more time consuming for someone to maintain a project you've worked on contrary to the philosophy of transparency and collaboration that the movement calls for, and you are also making it needlessly more difficult for other people to learn from what you did and become better programmers themselves. I don't understand how this conduct flies in any professional commercial environment (where deadlines and long term support have price tags attached to them) but apparently it's endemic to the trade.

    84. Re:Doesn't matter in the end by jeremyp · · Score: 1

      I think he means change control, not revision control.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    85. Re:Doesn't matter in the end by ch0ad · · Score: 1

      Hehehe...in my old job i was maintaining a lot of code written by the boss' son (yeah...) and he would comment *every* *single* *line* with gems such as "// Add One To IntNumMgrxXDYGZ" next to a ++ operation, with no mention anywhere of what "IntNumMgrxXDYGZ" stood for, what it was used for or anything remotely useful, and even at the end of tiny 4 line blocks he would write "} // End If" or "} // End For" i assume because he learnt with visual basic and found it helpful. Always Capitalising The First Letter Of Every Word For Some Reason.

      Still, it was very therapeutic purging it all and condensing it down in to elegant readable code with a small paragraph of comments explaining the "why".

    86. Re:Doesn't matter in the end by angel'o'sphere · · Score: 1

      Your comment still makes not clear what you would like to comment.
      And I myself also have over 30 years experience in programming/software engineering.
      I would say: either people know how to code, or they don't. Comments are only necessary as e.g. Javadoc comments to explain what a class/module or method/function is doing and what the parameters are for.
      Your parent is completely right. If you need comments inside a method/funtion then your code is wrong.
      However there are two exceptions:
      a) a comment indicating a non obvious business requirement
      b) something like a loop that starts after the first element or ends before the last one, then I would like to know 'why'.

      I'm working right now in a team of 11, soon 15 developers. During the year we wrote 1500 classes with roughly 45000 lines of 'executeable' code.
      The amount of non API comments is roughly 75 Eclipse // TODO / FIXME comments and basically ZERO "green comments". All developers agree: this is how it should be!
      If you don't understand the code: read its unit tests and integration tests.

      However, said this above: that all belongs to business development. If I would write a game engine there likely would be need to document low level stuff. Or if I write avionics software, or if I write code very low level on an embedded device when I read a value from an obscure memory address, saying: this is supposed to hold the rpm of the engine. However, exactly for that you would make a macro 'loadRPMEngine1' or not?

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    87. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      even a cryptic, half-assed effort, can be a lot better than nothing.

      Not always true, I've worked on code that was updated, but the comments weren't.
      When the code says one thing and the comments say another, it gets REALLY tough to figure out what's going on.

      In my (limited) experience the more cryptic the code && comments, the more likely one or both are wrong.

    88. Re:Doesn't matter in the end by Guignol · · Score: 1

      I have to admit you are probably trying to get through some of my code right now and I appologize
      But I am getting better and better, so if it is old code, well you should just rewrite it it's not efficient and it's buggy
      if it's recent code, well, it overalls is better so if after reading it you don't feel safe, well, rewrite the thing, otherwise, just let it be or improve on the comments in place
      You will know it's recent code precisely because there are some comments, pretty much every method / class begins with this:
      // TODO: comment it

    89. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      > Either the code is clean and self documenting in which case it doesn't need comments

      This assumes you're familiar with the problem space. Clear code that does something only a SME would understand is useless to you if you're not the SME.

    90. Re:Doesn't matter in the end by angel'o'sphere · · Score: 1

      Would you care to comment, what a PLM is? Well, commenting obscure TLAs makes sense :)

      However, the way you code is the way how I teach programming. My own coding works different. I use the modern IDE features. Writing the main algorithm, before the needed subroutines exist. Then I let the IDE generate the missing methods as skeletons and I fill them with flesh.

      As I use very self explaining method names, the main algorithm looks pretty 'literate'.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    91. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      It's called a meta comment. // This is what this shit does. I'm not talking about what each part does(yes it has a for loop we don't describe each part) // but what it's used for, when to use it, how to use it, limitations, etc. // ... // ... // META: This is why I did it this way. e.g. The old HP server needs x,y,z ... It's better to do it like a,b,c, but library L(proprietary can't change) has bug B and so it won't handle circumstance C properly.

      maybe even adding other timely data. // META: Old HP server is scheduled to be taken offline by 09/12/2013. This patch will no longer be needed. Verify.

      But you said it correctly WHY the hell did you do it this way? "Self documenting code" is the only answer is naive, and why some bugs never get fixed, or in some cases old code remains causing code rot and further bugs because it never gets removed/updated. If you don't understand the why, it can never properly be maintained; hence, that is why we have so many "rewrites" of code instead of proper maintenance.

    92. Re:Doesn't matter in the end by jeremyp · · Score: 1

      Good code doesn't need comments that explain what the code does, yes; that should be clear from the code itself.

      Yes, but any code only documents exactly what it does. It does not document what the person who wrote it thinks it does.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    93. Re:Doesn't matter in the end by Jake+Griffin · · Score: 1

      I thought the same thing, but git shows that they were written by the same developer in a single commit. This same developer has caused the developers at my company SO much trouble. He documents the stupid things, and performs useless 'no-op' conversions (another example from Python, str is already a string: str = "%s" % str... not only did is the code confusing [str() anyone?], it's a no-op). On top of that, our code is filled with comments such as "This is a hack" followed by 400 lines of illegible, undocumented code (unless you count "This is a hack" as documentation).

      --
      SIG FAULT: Post index out of bounds.
    94. Re:Doesn't matter in the end by jeremyp · · Score: 1

      the comment is, at best, a statement of what the original programmer intended to write.

      Which is an important piece of information to have when you are trying to figure out what the bug is.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    95. Re:Doesn't matter in the end by Jake+Griffin · · Score: 3, Informative

      I'm not saying that you shouldn't document it too. Sorry for misleading you. I'm all for documentation of these things too. But people frequently ignore documentation, so having the test case there too helps to prevent broken code from getting into production.

      --
      SIG FAULT: Post index out of bounds.
    96. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      Not really true. I remember calling a kernel function from within an interrupt routine because the comment explicitly said it was ok. Well, it crashed so I went to interview the maintainer of the code, who immediately said you should never call the function in an interrupt context.

      The code is always self-documenting in that it at least does what it says it does. Comments are not maintained. They are random ideas some developer had at some point in time. Or they are cut-and-pasted from a different routine. Or they are written with no expressive skills whatsoever.

      I would almost go so far as to recommend: never read comments or software patents.

    97. Re:Doesn't matter in the end by polebridge · · Score: 1

      >seek to move them off my team
      My wife teaches programming to 7th graders, and marks down for bad/incomplete comments.

    98. Re:Doesn't matter in the end by element-o.p. · · Score: 1

      Only in the short term (in the case of your own code). If it's my guys writing indecipherable code, then, yeah, that's not your fault, and I wouldn't hold you responsible for it. However, if it's your code that's indecipherable, I'll probably try to find someone else next time.

      --
      MCSE? No, sir...I don't do Windows. Yes, I am an idealist. What's your point?
    99. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      Your right about that, I've had a lot of heated discussions with coders that refused to read comments and instead resorted to clumsy guesswork. It's not like the comments on projects I've worked on are hard to understand, I make it a point to review the code on every project I work on once a week just to clean up hard to understand comments and add in comments where it's really needed. Yet we always wind up with people that are utterly baffled and ask questions that are answered in the comments.

      I would be pissed if someone forced me to use an IDE that doesn't support collapsing comments because they thought that was the problem. The problem has been around since long before collapsing mechanics have been put into IDEs.

    100. Re:Doesn't matter in the end by necro81 · · Score: 1

      But then you are faced with the stark reality that, although all your hard work totals up to 1000 lines, it only amounts to 100 lines of code!

    101. Re:Doesn't matter in the end by Nerdfest · · Score: 1

      If you want well-written, code with only the required amount of documentation, do code reviews. I actually usually end up getting my developers to remove documentation and re-write sections, or rename methods ... documentation can actually be a 'code-smell'. There are time's when it's needed as well of course. I find the key though is code reviews. Not formal, big-production code reviews at the end of a release of fearure (those are fairly useless and way too late), but informal walk-throughs with another developer or two (a junior and a senior ... great teaching/learning exercise) while a feature is being coded, or at commit time, if you haven't done it before that. It does amazing things for the code quality.

    102. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      That sounds like a halfway step to literate programming. With real literate programming, you would write your description of what the function does and that description is converted into code.

    103. Re:Doesn't matter in the end by mypalmike · · Score: 2

      It seems every single anti-commenting post in this thread is posted AC. There's a reason for this.

      --
      There are 0x40000000 types of people: those who understand 32-bit IEEE 754 floating point, and those who don't.
    104. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      You are thinking too imperatively. Great code tells the computer what to do--not how to do it. This is true now and will be even more true in the future as runtime systems become more sophisticated.

    105. Re:Doesn't matter in the end by MobileTatsu-NJG · · Score: 1

      Not necessarily. Good code can show what is being done, but it can't show different approaches which were rejected. Comments can explain why certain shortcuts are valid or not valid in a way which won't be obvious from the code.

      My comments are usually an apology for not doing it the right way.

      --

      "I like to lick butts!" by MobileTatsu-NJG (#32700246) (Score:5, Informative)

    106. Re:Doesn't matter in the end by Bigby · · Score: 2

      Those shortcuts are not obvious at the time of coding. I always go back to my code weeks later, when I forgot what I wrote. Then refactor and comment where appropriate.

    107. Re:Doesn't matter in the end by gbjbaanb · · Score: 1

      But I would like to see more of an option to "collapse" comments.

      Isn't this part of what TFA is on about - because you can collapse comments simply means hiding them from view making them less useful.

      What I'd like to see is the ability to collapse the comments and code block *together*. Often you can collapse a block of code, or the block of comment above it.. but you can never tie the 2 together so you can view the section of code (that includes the comments, AFAIK comments are non-functional code) you're working on as a whole.

    108. Re:Doesn't matter in the end by Eponymous+Hero · · Score: 1

      you're at +5 Funny, but you should be at +100 Sad But True

      --
      insensitive clod overlords obligatory xkcd car analogy russian reversals whoosh pedant fanbois ftfy in 3...2...1..PROFIT
    109. Re:Doesn't matter in the end by gbjbaanb · · Score: 1

      absolutely.

      But you forgot 2 other reas^H^H^Hexcuses:

      "Malpracticed":
      I could comment it, but all the other comments are obsolete/out of date and no-one updates them, so why bother.

      "Misdirected":
      I've written a unit test so why do I need to write a comment too? The test explains what it does.

      Personally, I consider comments as non-functional code. Just like some requirements/specs are functional "click the blue button and the image will change to red", but some are non-functional "the colour change will occur within 2 seconds". You'd want to write code to cover the functional specification (obviously), but you also need to write "code" to cover the non-functional stuff too. This code is called comments. At least that's one way of reminding a junior developer why he should put them in.

    110. Re:Doesn't matter in the end by Eponymous+Hero · · Score: 1

      there are so many code editors that offer this feature (and good ones too, not just that steamy pile eclipse), i can't believe you don't use one yet. even vim has a plugin to collapse comments. notepad++ can do it too. in fact, what are you using that doesn't offer this feature? it's easier for me to find one that does than not.

      --
      insensitive clod overlords obligatory xkcd car analogy russian reversals whoosh pedant fanbois ftfy in 3...2...1..PROFIT
    111. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      Well no fucking shit, Sherlock.

    112. Re:Doesn't matter in the end by Eponymous+Hero · · Score: 2

      what i see the most is there's no separate set of eyes looking at a bit of code about to be released to production. the developer is left to test his own work (usually without test suites, because if you have those then you are probably not the only one looking at the code either), and there are so many ways he can get it to work on his own machine while it breaks for everyone else. bigger companies/bigger projects will have a qa/qc/uat/whatever process before release, but it seems like the majority of programmers are cowboys who trust themselves way too much.

      --
      insensitive clod overlords obligatory xkcd car analogy russian reversals whoosh pedant fanbois ftfy in 3...2...1..PROFIT
    113. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      5th:
      Unreasonable deadlines
        Do I comment my code and have to stay late every night as well as work weekends or do I forgo commenting and at least be able to spend my weekends with my family though I still will have to work late every night

    114. Re:Doesn't matter in the end by Eponymous+Hero · · Score: 1

      you're that guy! god, i hate you! you're the motherfucker who leaves comments in the code i inherit that says shit like, "this should never happen." i could strangle you! please tell me you're just trolling.

      --
      insensitive clod overlords obligatory xkcd car analogy russian reversals whoosh pedant fanbois ftfy in 3...2...1..PROFIT
    115. Re:Doesn't matter in the end by IdolizingStewie · · Score: 1

      I haven't coded since college, but I'm guessing that PLM is the "program logic manuals" referred to in the previous sentence.

    116. Re:Doesn't matter in the end by richlv · · Score: 2

      code usually will not tell you why something is done this or that way. at most it will tell you how it is done (and even then, not always).

      also, even when you think you know what exactly code does, you usually do not see the "big picture". in any software that's more complex than a few operations there will be algorithms that can not be understood from a couple of functions. this is where comments can help enormously, as the overall logic can help to avoid silly mistakes.

      the problem with "code does not match comments" is that... the project is done anyway. if that is the case, code quality is so horrible, nothing good can come out of it.

      another somewhat interesting thing is that in way too many cases, when talking about slightly more obscure low level operations, nobody really knows how it should work - unless there's a comment somewhere, explaining what and why is done there. yeah, one can figure what the code does, and there might some ugly hack in there. so that is kinda cleaned up, only to discover two months later that the old logic was correct (as impossible it seemed two months ago...), just some asshole did not bother adding a comment about it.

      --
      Rich
    117. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      Highest comment I ever get is 'your code is easy to read'.

      Then I met the guy who 'if (x == FALSE) {}' was too much for him and gave him an 'headache'. 'It checks to see if the var is FALSE what more do you want?' 'you can write it more concisely...' At that point it was useless to even convince him. He is one of those 'the code is smaller so therefor it is better' guys. You can write more naturally the better it is for everyone to read. Skip the shortcuts the language gives you so you can save a few chars. Those are easy to read NOW. But 6 months from now when it is 3AM and you are debugging it you will hate every second of it.

    118. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      Meh, if it was hard for me to write it, it should be hard for you to understand it.

    119. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      The code says how (instructions), the comments should say what (algorithm). The why (architecture) is often deferred to auxiliary documentation (or not explained at all).

    120. Re:Doesn't matter in the end by nschubach · · Score: 1

      Honestly... how much code have you written that's really that complex? Most of the stuff you probably do day in and day out is trivial by most standards.

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
    121. Re:Doesn't matter in the end by nschubach · · Score: 1

      But what if it does the correct calculation, but the person who wrote the comment didn't fully understand (or couldn't accurately articulate) what it was doing?

      Now you have two factors of confusion; Did the commenter part of the person know what they were doing (Did they properly write down what it's actually doing?) or did the coder part of the person know? What if they knew how to code up the solution, but explaining it was harder to do without using code. Maybe the code is correct, but the comment leaves out a key point. Now you assume that the code is obviously incorrect because the comment doesn't mention something.

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
    122. Re:Doesn't matter in the end by SuricouRaven · · Score: 1

      I'm a dabbling hobbyist. I'm allowed to do that, because my code isn't Serious Business. The most popular program I've written is a utility that analyses and displays the headers from Windows Media files. It's a handy thing, if you're trying to figure out why one of those files isn't playing at it should, but hardly world-changing. As proof of my non-trolling, I submit this extract from a program I wrote to research de-duplication for hard drive image backups:

      //16777619 is a number needed for this to work. I don't understand the math fully, but I know being prime matters.
      unsigned int hval=2166136261; //Also somehow special mathematically.

    123. Re:Doesn't matter in the end by nschubach · · Score: 1

      What if what they meant to write would give the wrong result, but the code they wrote is correct?

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
    124. Re:Doesn't matter in the end by TemporalBeing · · Score: 1

      That's why you have TEST CASES for cases x and y; so that if someone ignores the comment, tests will break alerting of an issue!

      Test Cases only work when you can actually have a test environment to test in.

      Not all code is testable in-house. A good bit of the code for where I work cannot be tested until we are in the field delivering it to a client. It's just not possible to do it in-house.

      --
      Truth is like the sun. You can shut it out for a time, but it ain't goin' away. - Elvis Presley (source: imdb.com)
    125. Re:Doesn't matter in the end by nschubach · · Score: 1

      Hyperlinking relies on the content remaining in that same location and if said documents ever move... all your links now need to be updated adding another layer of busywork to coding.

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
    126. Re:Doesn't matter in the end by TemporalBeing · · Score: 2

      What I do is put my comments in the same line as the code. When I need to read the comment I just scroll right, but otherwise it doesn't distract me or eats up screen space. If it's too long, I split it up between different parts of the code. For example, I explain what a function does in the line before it, but I detail how it does that (if explanation is necessary) in the body after the lines.

      One of my colleagues puts all the comments in his code in a certain column at the right side, typically on the same line as the code itself (following the GNU coding-style). While the comments are useful, they are completely useless in that location; it would be far better to have them on the preceeding line, or in a larger block so that it can actually be seen without scrolling the screen left/right.

      --
      Truth is like the sun. You can shut it out for a time, but it ain't goin' away. - Elvis Presley (source: imdb.com)
    127. Re:Doesn't matter in the end by crazyjj · · Score: 0

      fucknugget

      I just learned a new favorite word today.

      --
      What political party do you join when you don't like Bible-thumpers *or* hippies?
    128. Re:Doesn't matter in the end by defcon-11 · · Score: 1

      I agree, I always try to refactor commented code into self-documenting code, and I try to eliminate as many comments as possible before pushing a change. However, there are some legitimate reason for comments. Code should be commented any time it is non-obvious. Examples of non-obviousness include algorithms, performance hacks, bug work arounds, and strange business requirements.

    129. Re:Doesn't matter in the end by defcon-11 · · Score: 1

      Can you give an example of code that's not testable?

    130. Re:Doesn't matter in the end by godefroi · · Score: 1

      As you've noticed, comments should explain WHY something was done. The code itself should explain WHAT is being done.

      --
      Karma: Poor (Mostly affected by lame karma-joke sigs)
    131. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      1. Sometimes you're using a confusing and complex feature of some library or server. Providing a comment with a link to the documentation on that feature makes things a lot easier for the next person to come along.

      Fun fact: you can drop links into most C-derived languages without putting them in a comment block. Suffice it to say that some of the code I've seen has a lot of http labels that are never referenced in the code :-)

      It's a very rare case where I think a programmer wrote too many comments.

      That's only true upon initial delivery. When you're called upon to make significant changes to a codebase that's heavily commented, updating the comments becomes a major chore which, when the deadline approaches or when your estimates are challenged, is frequently ignored. The best programmers know when to write comments and when not to. The latter is just as important as the former.

    132. Re:Doesn't matter in the end by crazyjj · · Score: 1

      Oh yeah, I've ran into THAT guy too. I guess I can say at least he's trying. But yeah, I probably don't need this:

      //add 1 to i
      i++

      --
      What political party do you join when you don't like Bible-thumpers *or* hippies?
    133. Re:Doesn't matter in the end by James+McGuigan · · Score: 2

      When writing computer code, and either using or reusing previous sections of code, the key question is how much mental energy and attention units will it take for the next programmer (who may be you in a months time), to gain a workable understanding of the function.

      As humans, we only have attention units enough to keep a limited subset of items (maybe 5-7) in our heads at any one time.

      If code is badly written and/or documented, then its going to take more mental energy (and time) to relearn the code than it would otherwise. This is time and energy that could be better spent solving useful programming tasks.

      Generally I believe functions, especially those in reusable library code, should be well documented in terms of inputs, outputs, plus any assertions, assumptions, exceptions and with a view to programming by contract. Static languages like Java force you to do alot of this in terms of syntax and compiler checks, but for dynamic languages like javascript, the language doesn't enforce this and thus the explicit effort is required to add this information in the form of function, class and variable documentation.

      Inline comments should assume the reader is able to read the code itself, but should describe any hidden implications, design tradeoffs, links to useful external documentation, gotchas, bugs etc. Its also often useful to give inline examples of the data is likely to process, such as HTML strings or JSON data hashes, especially when the structure is not statically defined by the language. The sort of things that are not obvious from directly reading the code itself or would require time to go off and google or lookup in another file.

      Here are a selection of useful inline javascript comments from my own codebase archives:


      data.values = {}; // {Hash} = {Number}

      eventManager: null, // {EventManager} reference to js/libs/EventManager.js, passed in via init.js

      delay = delay || 10; // 10ms is enough time for this.el.target:mouseenter to trigger

      tooltips: $([]), // empty jQuery - shared between all instances of this class

      typeof a === "function"; // Oops, false in IE and Opera, true in FF and Safari ("object")

      listenerId: "_" + (++this.lastListenerId), // BUGFIX: Chrome does array ordering, rather than insertion ordering for hashes with numeric indexes
      // Force syncronous browser caching to ensure all files are in order, bug in Opera and IE
      // if( !this.contexts[uidType][contextUid] ) { continue; } // if the contextUid has no associated listeners, no point looking for them
      // Context is required, listenerIds for a context can be looked up via this.contexts[uidType][contextUid]
      // Loop over uids in json - should be faster if json.keys().length is smaller than this.listeners[uidType].keys().length - TODO: profile
      // Read attribute, overrides this.options.ajaxRewrite
      // If you want a double slider, this.el.selects needs contain two select elements
      // Ensure that specified data range actually covers given data
      // This really should be part of this.parseOptions(), but we need access to this.xy.valueSpacing
      // HACK: Do the loop twice, starting from the origin. In theory we should be able to do this a single loop
      // Note all angles in radians. circle = 2 pi radians
      // Just check if the total is 0 and draw circle as fallback
      // Note: Object literals declared here will shared between all instances

      this.wrapper.height( this.getInitHeight() ); // Canvas is position absolute so we need to explictly define wrapper size
      // fadeOut when the mouse is over the tooltip

    134. Re:Doesn't matter in the end by crazyjj · · Score: 1

      /**
          * Todo
          */

      Maybe he was making a satirical comment on the nature of existence.

      --
      What political party do you join when you don't like Bible-thumpers *or* hippies?
    135. Re:Doesn't matter in the end by ShanghaiBill · · Score: 4, Insightful

      And then the how changes....

      // Add 1 to i
      i+=2;

      I have seen worse. I worked on a project that had a lot of "magic numbers" in the code, so our manager told us to make symbolic definitions for them. One guy put this in a header file:

      #define FOUR 4

      and then used FOUR everytime he needed that number. Then, you guessed it, someone decided that 4 was too few, so they changed the defintion to this:

      #define FOUR 5

    136. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      As a maintenance programmer, I have to say that the only thing worse than no comments is comments that are inconsistent with the codebase. And since code is more likely to change than comments, I find that for a sufficiently old codebase (~8+ years old) most comments are worse than useless for debugging.

      Personally I've found that I tend to completely ignore all comments when trying to debug unless I've hit a real roadblock. What tends to happen when I read comments first, is that I ignore pieces of code that I'd otherwise scrutinize.

      Also remember, that the place a bug is most likely to exist is where the last person to change the code was confused. Confused code and confused comments go hand and hand, and if the code is wrong so will likely be the comment. What's worse is that the comments don't get executed, and so there isn't even the rest of the codebase to enforce any consistency there either...

    137. Re:Doesn't matter in the end by Rob+Kaper · · Score: 2

      The "TODO" flag isn't what's wrong there, the "this" part is. It's obvious that the TODO relates to the nearby code (this, not that). It's still not obvious what needs to be fixed. It could be a lack of performance, error handling, input validation. Some use-cases/states/values might not be covered/tested/identified or implemented. But the answer is always: why. Ask yourself "why am I adding a comment here" and the answer is the perfect comment.

    138. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      > Likewise, self-documenting code will only ever tell the programmer how the computer does something, but will never tell the programmer why. That's the job of the comments.

      Huh?

      void withdraw(double amount) { // why?
              balance -= amount; // how?
      }

      I want to withdrawn money from an account.

      How? subtracting the amount from the account's balance.

      Why? because the callee wants to withdrawn money? :-S

    139. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      Favorites:

      stop; /* hammertime */
       

      stop; /* collaborate and listen */

      // hours wasted here = 24


      // I dedicate all this code, all my work, to my wife, Darlene, who will
      // have to support me and our three children and the dog once it gets
      // released into the public.
       

    140. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      My code doesn't need comments! It's so clean and wonderful, it documents itself! If you can't figure it out, you obviously shouldn't be a programmer because you're not smart enough.

    141. Re:Doesn't matter in the end by pkinetics · · Score: 1

      Sounds like someone needs to be taken out back behind the wood shed and given 40 lumps.

      However as this is generally frowned upon, if someone is patient, the wee scripter needs a code review.

    142. Re:Doesn't matter in the end by SuperDre · · Score: 1

      Stop right there... WHAT IS 'good code'? it's all in the eye of the beholder.. A fellow coder said to me once: 'good written code explains itself' to which I responded: 'Yep, bad written code too'..

      The problem is that everybody has his/her own vision of what good written code is.. There are so many ways to write code, and you know, there really isn't ONE good way.. Some people swear by Test driven development, others actualy swear on TDD..
      Always just make sure you comment your code (especially with the intention of what you want to do), that way it never really hurts, unless ofcourse, as someone already said, the comments are written with such bad grammer.

      And remember that every line of code you write will become a legacy system..

      Personally I'm using a color that closely resembles the background color, so you still can read it, but it blends into the background and the code it what stands out.. But then again, the first thing I do when I install a new IDE is change the colors dramatically as white background is really bad....

    143. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      Big surprise.

    144. Re:Doesn't matter in the end by Alex+Belits · · Score: 1

      All code is "not testable" as far as all aspects of its behavior are concerned. Tests never guarantee anything other than two pieces of code, code under test and the test itself, happen to have bugs that are complementary under one given condition.

      --
      Contrary to the popular belief, there indeed is no God.
    145. Re:Doesn't matter in the end by mark-t · · Score: 2

      I've seen similar things many times in my career, and I've come to call them "anti-comments", because they describe something that is *NOT* what the code it is supposed to be commenting is doing.

    146. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      Not Enough Time

      Management usually doesn't budget enough time to properly write and test the code. When you are given half the time you need, things like comments take a back seat to actually writing the code.

    147. Re:Doesn't matter in the end by mjtaylor24601 · · Score: 1

      I need an account at your bank

      Step 1: myAccount.withdraw(-100000);

      Step 2: ???

      Step 3: Profit!

      But seriously I think you're engaging in Reductio ad absurdum here. Most pragmatic people will totally agree that trivial code, where it's very obvious what the code does and why, doesn't need extra comments.

      However the more complicated your code is the harder it becomes to make it "self documenting". ie I don't think anyone wants a method named

      withdraw Positive Amount Or ThrowOverdrawnException IfAmount GreaterThan Balance Or ThrowInvalidArgument Exception IfAmount LessThan Zero (double amount)

      --
      I wish I were as sure of anything as some people are of everything
    148. Re:Doesn't matter in the end by ThreeKelvin · · Score: 1

      A feedback controller is a good example. Sure you can test it against a model, but you just won't know until you've had it running against the hardware. Also, models are expensive, so clients often don't want to pay for their development, but will allow for a bit more debugging and tuning against the hardware instead.

    149. Re:Doesn't matter in the end by plover · · Score: 1

      I think he was talking about unit testing, not system or integration or even feature testing. Effective unit tests do not rely on external dependencies. You don't need or even want a poorly configured or missing "test environment" to mess up your ability to run the tests. Instead, you provide fakes that yield exactly the expected values to trigger your program's behavior. You can have fakes that drive you in the direction of the happy path, fakes that steer the code down the sad paths, and still other fakes that take you down exception paths. Mock objects can provide everything from simulated database data to simulated service responses. And the values are all coded into the tests, where they provide documentation to anyone who can read code: if you call the Add(2,3) method you should expect a result of 5, if you call the Divide(5,0) method you should expect a DivideByZeroException will be thrown, etc.

      And if you have code that is not unit testable today, you can certainly refactor it until it is testable. Once you learn a few patterns and anti-patterns, it's not even that hard to do. The real question is whether or not your boss thinks it's worth it to go back into a working million line project and add unit tests until you achieve 100% test coverage. (Sadly, the reply is generally "you want to spend HOW MUCH on testing code that already works? Get out of here, you psycho!") But is it worth it to add unit tests around any changes you make going forward? Absolutely.

      --
      John
    150. Re:Doesn't matter in the end by drew_eckhardt · · Score: 1

      When time is short and changes are being made fast and furiously, or prototyping is being done, time spent commenting comes out of time getting something completed under a harsh deadline...

      That's a naive simplification that's not really true. Software development is _not_ a zero sum game and time doing things which "don't ship to customers" both reduce total time and make it more predictable so your time commitments are less likely to become harsh.

      Your milestone is _not_ code complete. It's delivering a product to customers which meets some requirement set including quality. The time to get there is something like

      Requirements
      + Functional spec
      + Write and comment tests
      + Design
      + Write & comment code
      + Manual test execution
      + New feature bug count * (interrupt overhead + average time to fix new bugs)
      + Regression count * (interrupt overhead + average time to fix regressions)
      + Bug count from previous releases * (interrupt overhead + average time to fix previously latent bugs)

      where some steps may be trivial and there are nested feedback loops around others.

      The terms are neither constant, functions with project size as the only input, nor independent.

      Generating a good comment causes your ideas to flow through other parts of your brain so you develop a better understanding of what's going on thus reducing the defect rate in terms of new bugs.

      Having done so before means you have a better understanding of what was already going on, so you have fewer regressions and where they happen there's less context switch overhead figuring out what was going on so you can fix them.

      The reduced bug count from previous releases multiplied by lower interrupt overhead means you loose less time there.

      Better test coverage means more bugs are found early where the time to figure out what you were doing when you caused them is lower. Lower level test coverage means everything is more isolated so the time to correct each one is lower.

      Designing for validation so that's manageable encourages better encapsulation within components and smaller component size which reduces both bug count and the time to correct each one.

      Etc.

    151. Re:Doesn't matter in the end by c++0xFF · · Score: 1

      You're right. The names of functions, variables, classes, etc. can serve as part of the "why." But, that's that's not enough. For a one-line function, sure. But imagine if you used a fixed-point library to hold the value instead of a double, and that withdrawing money from an account requires interesting authorization. And then how do you handle overdrawing an account? Etc. etc. etc.

      No matter how complicated and descriptive you make the variable and function names, at some point this system breaks down.

      Some languages have additional features that make it easier to go beyond the "how." Contract programming comes to mind. Maybe one day a language will come out where self-documenting code will be a reality. But for now, the features aren't there, and it's the job of the comments to tell us why the code does what it does.

    152. Re:Doesn't matter in the end by RabidReindeer · · Score: 1

      I haven't coded since college, but I'm guessing that PLM is the "program logic manuals" referred to in the previous sentence.

      Give the kid a cookie! Ironically, this is exactly why "self-explanatory code" ... isn't.

      To pick another example, consider mathematical equations. Many formulas are elegantly simple, but unless you know the context, what, exactly does E = mc^2 mean in real-world terms? Same thing with algorithms. They show the "how", but not the "what" or the "why". That's what the comments are supposed to be for, since most systems don't have that much of an external universal context to go back to for explanations.

      Incidentally, one of the things I spend a fair amount of time doing is advising people who let an IDE write their programs not to rely on the IDE to write their programs. An IDE can be a wonderful help, but it's no excuse for actually knowing what the code is doing, and IDE-generated code is even less self-explanatory than most hand-written code.

    153. Re:Doesn't matter in the end by TemporalBeing · · Score: 1

      I think he was talking about unit testing, not system or integration or even feature testing. Effective unit tests do not rely on external dependencies. You don't need or even want a poorly configured or missing "test environment" to mess up your ability to run the tests. Instead, you provide fakes that yield exactly the expected values to trigger your program's behavior. You can have fakes that drive you in the direction of the happy path, fakes that steer the code down the sad paths, and still other fakes that take you down exception paths. Mock objects can provide everything from simulated database data to simulated service responses. And the values are all coded into the tests, where they provide documentation to anyone who can read code: if you call the Add(2,3) method you should expect a result of 5, if you call the Divide(5,0) method you should expect a DivideByZeroException will be thrown, etc.

      And if you have code that is not unit testable today, you can certainly refactor it until it is testable. Once you learn a few patterns and anti-patterns, it's not even that hard to do. The real question is whether or not your boss thinks it's worth it to go back into a working million line project and add unit tests until you achieve 100% test coverage. (Sadly, the reply is generally "you want to spend HOW MUCH on testing code that already works? Get out of here, you psycho!") But is it worth it to add unit tests around any changes you make going forward? Absolutely.

      The nature of the system relies on the external dependencies, which are very hard to virtualize in a meaningful manner for testing especially once you add them all up and how they all interact with each other. Not impossible, but very very expensive.

      --
      Truth is like the sun. You can shut it out for a time, but it ain't goin' away. - Elvis Presley (source: imdb.com)
    154. Re:Doesn't matter in the end by iamwahoo2 · · Score: 1

      I do the same thing and would like to add that outlining a larger block of code in comments before writing any code also helps me to stay focused on the overall design. If you just start hammering away at coding then it is easy to forget about what the code in its entirety is going to accomplish. Its like making a drawing of what you are about to construct before you rush in and just start hammering in nails.

    155. Re:Doesn't matter in the end by angel'o'sphere · · Score: 1

      If you don't find it in the tests, the programmer likely does not know what to comment anyway.
      If he knew what to comment and wrote some tests, one of the tests would cover it ...

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    156. Re:Doesn't matter in the end by angel'o'sphere · · Score: 1

      ... IDE generated code is even less self-explanatory than most hand written code ...
      How can that be when it is exactly the same code?

      I call a method, that does not exist: doIt("hard", 3).

      The IDE generates:
      ResultType doIt(String s, int i) { // TODO auto generated code
      }

      I have to write the body and fix the parameter names.

      If my original call to the non existing method would have been: int res = doIt(what, times); whre what is a String variable and times is an integer the IDE would generate:
      int doIt(String what, int times) { // TODO autogenerated code
      }
      So with context information abiut variable names the IDE generates exactly the same code as anyonw would write.
      I is just faster to "forward program" using non defined methods than always stepping one step back and write that method first before you call it.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    157. Re:Doesn't matter in the end by Zero__Kelvin · · Score: 1

      You aren't grasping the point at all. The whole discussion is about how to properly program. Your "counterpoint" amounts to: "If the programmer can't properly program he is unlikely to properly program", which clearly falls in the "no shit sherlock" category.

      --
      Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
    158. Re:Doesn't matter in the end by jgrahn · · Score: 1

      Going even further - good code generally doesn't need a whole lot of commenting. If you are struggling with this problem of how to display comments, then that says a LOT more about your code than your comments.

      (That said, trying to deal with a legacy system, comments can be helpful.)

      You realize, of course, that the new code you write today is the legacy code of tomorrow?

    159. Re:Doesn't matter in the end by jgrahn · · Score: 1

      if you can't fit the documentation into your method (and variable names), that method is likely too long and complicated.

      People are fond of saying that, but that's not helpful. We live in an imperfect world. We modify old code which isn't perfectly designed. New code which we write can't always be made perfect either. Comments can be a quick and safe way to make it tolerable.

      I don't ever want to hear the excuse "this sucky code I wrote isn't commented, but that's because perfect code doesn't need comments!"

    160. Re:Doesn't matter in the end by jgrahn · · Score: 1

      That is one of my major complaints. When time is short and changes are being made fast and furiously, or prototyping is being done, time spent commenting comes out of time getting something completed under a harsh deadline... which means comments are often not updated to reflect the new state of the code.. and incorrect comments can often be worse then no comments at all.

      I don't belive that's a valid excuse. Decent (e.g. not too detailed) comments are close to the code you're changing, and take very little time to change. At the very least you can quickly add an XXX or remove comments which are no longer correct.

      Also, at least where I work there's a review stage. We never ship something immediately to customer after an all-night hacking session. Then it's rather easy (for the reviewer and for you) to see that a function has been changed heavily yet the docs stayed the same.

    161. Re:Doesn't matter in the end by Capt.Albatross · · Score: 1
      Dan Dinkleton said:

      Good code can show what is being done, but it can't show different approaches which were rejected. Comments can explain why certain shortcuts are valid or not valid in a way which won't be obvious from the code.

      to which you replied:

      No, that is for what tests are.

      Suppose you have a situation where, because of the unusual distribution of the data, what would appear to be an obvious implementation would actually be inefficient. What are you going to do - write a test that times the execution of the code on a large sample of data? Even if you did, it would be inordinately and pedantically obtuse not to make mention of the issue with a comment in the code. We cannot assume that it will be obvious that this test refers to this particular algorithm (for example, due to cross-cutting concerns such as concurrency, the implementation may not be localized to a module), we cannot assume that the reason why there is a problem will be obvious from the test, and we cannot assume that there is an efficient way for the person reading the code in question to determine which tests' results are influenced by it, and therefore which tests should be read in conjunction with the code.

      As Zero_Kelvin also mentioned, tests don't explain why the code was written the way it was, and what I have presented above is just one example that should make this point clear to anyone (I'm assuming that you would not allow comments in the test code, as that would seem to defeat your purpose.) Understanding code is hard enough without its author turning it into some sort of puzzle that can only be solved by deducing the intent of the author through an examination of the tests he wrote for it.

      I find it difficult to believe that believers in self-documenting code understand how much, and what sort of information goes into the writing of software, and therefore I find it difficult to believe that they can do it effectively.

      My opinion on hide or collapse stuff is very easy: it's a bad idea. Sooner or later developers will hide a lot of stuff, code, comments, it's like why it is a bad idea to hide stuff under the carped: clean up your room and not hide the dirt under the carpet.

      The judicious hiding of information is what abstraction is all about, and abstraction is the main technique we have to cope with the complexity of software. It only works if the hidden stuff has well-defined semantics, and to communicate those semantics we need documentation that is at a higher level of abstraction than code.

    162. Re:Doesn't matter in the end by devent · · Score: 1

      Stop using comments as Bug-Tracker. We have Bug-Tracking software for that. Stop using comments for everything. I just counted from the Slashdot posts here what comments are all for: For Bug-Tracker, Documentation, Source Control System.

      You need to understand that comments are only for one entity only: for the developer as a human. For the compiler comments are just non-existent. They don't have a syntax, they don't compile and they don't run. If you start writing a comment like: This algorithm must run in 50ms and needs to assume that corner-case and that issue. Then why are you not writing a test that ensures just that?

      Just be true to yourself and just realize that you just being lazy. That's it. Maybe you don't have the time to write a test, maybe the code is a mess and you can't write a test without re-write the code or whatever. Bust stop making excuses.

      You can use the language to hide things. Hide the code is not a language construct, it is an IDE "feature". The OOP brings everything you need: packages, classes and methods, inheritance and composition. If you want to hide code, why not just move the code in a new class and use composition. Because you are lazy again, that's it.

      In Eclipse you even have a menu item for that. Just go to refactoring and chose extract class and Eclipse will do the rest for you.

      --
      http://www.mueller-public.de - My site http://www.anr-institute.com/ - Advanced Natural Research Institute
    163. Re:Doesn't matter in the end by betterprimate · · Score: 1
      Comments should *NEVER* be a conversation. Comments should list objectives. If you can't read the code, your fault. Learn.

      Good luck!

    164. Re:Doesn't matter in the end by angel'o'sphere · · Score: 1

      No, the whole discussion is about: does a properly programed piece of code need comments. IMHO: only in rare cases, which usually are not even obvious for the programmer himself.
      In my previous bigger project we wrote a kind of a facebook clone to be integrated into the news page of a big internet provider.
      90% of the code has no comments. Perhaps 95%. Because they are not needed. Every commit comtains the number of the issue from the issue tracker containing the business requirements,
      The system was exposed via a REST API. All API calls are documented via an extensive manual, explaining the API and giving for every success case and every failure case an example. Finally there where JMeter tests using those example calls as integration or high level system tests. And all those documents where checked in with the issue number from the issue tracker motivating that particular development.
      And frankly ... I'm in the lucky situation that I never saw a line of code that needed a coment anyway. I mean a working line or piece of code. I saw code that did not work at all, with comments and without. It usually was more prone to simply rewrite that code than 'fixing' it.
      The 5% comments we have on the code above are for the access layer to the NoSQL DB.
      Ofc that project was conducted by 4 über programmers plus 3 'normal' programmers, perhaps if it was done by mere mortals alone, it would have needed more comments? No idea.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    165. Re:Doesn't matter in the end by RabidReindeer · · Score: 1

      ... IDE generated code is even less self-explanatory than most hand written code ...
      How can that be when it is exactly the same code?

      Because it usually isn't. For example, my IDE is far more to generate a prototype with "helpful" argument names like arg1, arg2, arg3. Which a lot of people don't bother to alter to more meaningful names.

      But you're just using the IDE to generate stubs, and I do that. I start filling in the comments from there.

      What I was referring to was when people use IDE wizards to generate big clots of one-size-fits-all chunks of code - usually platform-specific - which does things they don't understand because someone hired a monkey-with-an-IDE instead of paying more for someone with proper training. The monkeys then come running to me because they started to tweak the code and broke things because they didn't know what they were fooling around with.

    166. Re:Doesn't matter in the end by angel'o'sphere · · Score: 1

      If the documentation is in error for version x.y of the API, then there is a STORY in youor backlog to ask for the fix. That story is in your issue tracker.
      After fixing the code you commit with giving the number of the issue.
      As your issue tracker is linked to your version controll system, you have now crosslinked: the ticket (why did you change it), the commit (who did change it when), the tests (as they have the same issue number as reference) and if you do stuff like that, the issue tracker will show you the commit, the comments and allow you to branch into a code review on that commit.
      If you really find it necessar you ofc, can comment the afected lines/methods with in code comment like: changed because if UC-1234. But as the tools give that away by themselves ... why bother?

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    167. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      Hands up who has seen a piece of code like this:

      //Add 1 to i
      i++;

      Bonus points if it's pre/proceeded by a complex block of uncommented, impeneterable code.

      Seen that, also seen assembly code used to comment other assembly code. Great way to clarify optimizations I guess...

      jmp funciton ; jsr function
                    ; ret

    168. Re:Doesn't matter in the end by Zero__Kelvin · · Score: 1

      "No, the whole discussion is about: does a properly programed piece of code need comments. IMHO: only in rare cases, which usually are not even obvious for the programmer himself."

      No. There is no such discussion among competent programmers. The only discussion competent programmers have about comments is how to do it properly. If you want to question if properly written code requires comments, you need to enter into a discussion with an incompetent programmer.

      The 5% comments we have on the code above are for the access layer to the NoSQL DB. ... Ofc that project was conducted by 4 über programmers plus 3 'normal' programmers"

      Your project was done by incompetents. Even more so the "Uber" programmers.

      --
      Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
    169. Re:Doesn't matter in the end by Zero__Kelvin · · Score: 1

      Never do through indirection that which can be done directly.

      --
      Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
    170. Re:Doesn't matter in the end by Capt.Albatross · · Score: 1
      Devent says:

      Stop using comments for everything. I just counted from the Slashdot posts here what comments are all for: For Bug-Tracker, Documentation, Source Control System.

      You correctly identify the first and third uses of comments as being wrong, but for alerting the reader to the fact that there is some non-obvious reason behind the design of some section of code, there is no better way than using a comment. Even if the design is documented elsewhere (as it should be), a reference to the appropriate part of the documentation placed in the relevant parts of the code is very helpful in preventing someone overlooking it. This is particularly helpful for cross-cutting concerns that are not localized to one part of the code.

      You need to understand that comments are only for one entity only: for the developer as a human. For the compiler comments are just non-existent. They don't have a syntax, they don't compile and they don't run.

      This is completely irrelevant, because the whole reason behind high-level languages is for them to be human-readable. The goal is to make the program more understandable to human, but a language that has the necessary and sufficient syntax to be compiled is insufficiently expressive to explain the reason for its existence and the intent behind its writer's choices (for example, showing that code is secure often involves proving certain theorems about it.) This requires additional, non-compilable documentation, and once again, comments are the best way to alert the reader to these facts, even if (or preferably) only as references to external documentation.

      Perhaps you are one of those people who believe that all code can be self-documenting? If so, then before you ever use or assert this opinion again, please complete this exercise: implement the quicksort algorithm in the language of your choice in such a way that the code alone clearly explains 1) a proof of its correctness, and 2) a proof that it is O(n lg n) on average but can be O(N^2) in the worst case. (that's just the starter: there are many more difficult problems, some involving concurrency and security, if you complete this one.)

      If you start writing a comment like: This algorithm must run in 50ms and needs to assume that corner-case and that issue. Then why are you not writing a test that ensures just that?

      Writing a test would be the right thing to do, but why stop there, when you could also add a comment? The criterion being tested for is a fact that you must necessarily know before you write the test, and before you write any code that is specifically designed to satisfy it. You, as author, have this knowledge, and you also know what steps you took to ensure the code satisfied the requirement. The subsequent reader initially does not know any of these things and needs to learn them. It seems that your preferred way is to set a trap in the form of a test that is triggered if they happen to unknowingly violate the rule, as if it were some sort of dungeons-and-dragons game. If this is the way you work, I would hate to have to read your code, and I would never contract you to write any.

      Perhaps you are one of those people who believe that all testing code can be self-documenting? Because testing can, in general, require Turing-equivalence in its implementation, my comments about self-documenting code apply here. Furthermore, there is the question of knowing which tests cover which parts of the code, which is not necessarily obvious, especially where the issues are cross-cutting concerns such as concurrency, security and performance. Finally, you should be aware that no amount of testing can prove the correctness of code. Let us suppose you have developed some tricky aspect of the code through a reasoned argument for its correctness, as is often the case for security issues. No amount of test cases will serve to explain to the reader the logic by which you derived the implementation. Perhaps you

    171. Re:Doesn't matter in the end by Capt.Albatross · · Score: 1
      VortexCortex; While I think I understand what you are saying, most of the time the phrase 'self-documenting code' is used, it refers to comment-free code, and the idea that it alone is all the documentation you need. To go against common usage invites confusion; for example, you and Mr Brooke do not seem to be in disagreement, though at first appearance, you seem to be.

      What you describe seems to be close in spirit to Knuth's idea of Literate Programming (though not his specific implementation of the idea.)

    172. Re:Doesn't matter in the end by Capt.Albatross · · Score: 1

      True, but documentation can also be achieved by other means than just comments.

      Comments are still useful as a link from the code to the relevant part of the documentation, in cases where there are some non-obvious issues being attended to.

    173. Re:Doesn't matter in the end by code-dweller · · Score: 1

      I used to believe (and teach) that comments were a good and necessary thing. Especially "why comments" even bordering on telling the "why" story along side the "how" in the code. The theory was that keeping the two parts of the story together acted as a cross-check during code review and a guide during development and maintenance. That methodology worked really well for a long time, though it did have it's occasional problems. I have now abandoned that methodology and have begun teaching and requiring a fully integrated alternative.

      It was a painful transition, but I have been convinced that the best code does a good job at telling both the why and the how. Source code should not be viewed simply as instructions for the computer but rather as an intermediate language that can be shared between the software developers and machines. Both hardware and wetware should be able to interpret the source code with precision and some deeper understanding. It is harder to write that kind of code, but the extra effort has made a profound difference in the quality and maintainability of my code since... Now I teach it the new way.

      Here is a blog post I made at the beginning of that transition: http://www.lifeatwarp9.com/2011/02/comments-are-not-literature-i-must-be-mad/

      A case in point: I recently had to hand off some of my code to a developer who was completely unfamiliar with the project without much time budgeted for getting them up to speed on it. I was prepared for all the usual breakage and frustration associated with that kind of forced hand-off. Since that code was written with a fully integrated approach in mind the new developer was able to get up to speed quickly and complete their project without any significant learning effort and without any significant errors along the way. Comparing this case with similar cases in the past the "costs" associated with this new methodology are "in the noise" compared to the old.

    174. Re:Doesn't matter in the end by lonecrow · · Score: 1

      While I appreciate the comments when looking at someone elses code, I find the general readability of the code itself to me more useful.

      But more useful still would be a nice graphically diagram of the entire application giving an idea of the components and how they are put together, and where the interfaces are to outside systems. The diagram could include naming conventions and file locations as well and a map to where any important keys are :)

    175. Re:Doesn't matter in the end by lonecrow · · Score: 1

      Perhaps the conceptual MVC should be changed to MVCD

    176. Re:Doesn't matter in the end by datavirtue · · Score: 1

      I was watching a C# video series on Pluralsight conducted by Scott Allen and he laid down his top ten rules of coding at the end. To my surprise, and much delight, he said not to use comments. I was delighted because of his reasoning. He insisted that your methods, classes, variables have names that convey their meaning or action. When you follow this throughout your code these is no need for comments. You will have a rare comment of course, and I'm sure that rare comment will catch someone's eye. I'm done with comments--I now make sure all of my methods, classes, and variables are completely meaningful so that my code logic can easily be followed. If someone is sloppy, I doubt their comments are going to add much to the mess.

      --
      I object to power without constructive purpose. --Spock
    177. Re:Doesn't matter in the end by datavirtue · · Score: 1

      You are scaring the shit out of me.

      --
      I object to power without constructive purpose. --Spock
    178. Re:Doesn't matter in the end by datavirtue · · Score: 1

      global actuation?

      --
      I object to power without constructive purpose. --Spock
    179. Re:Doesn't matter in the end by datavirtue · · Score: 1

      This is embarrassing to our industry. Maybe we should just keep this quiet.

      --
      I object to power without constructive purpose. --Spock
    180. Re:Doesn't matter in the end by angel'o'sphere · · Score: 1

      If you think so ...

      I would say you lack experience. Otherwise you would agree with me :D

      On the other hand, if you disagree: bring examples and not just hot air.

      Most code I saw last 5 years, I would not even know what or where to put a comment, because the code was crystal clear. If you have never seen such code ...

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    181. Re:Doesn't matter in the end by angel'o'sphere · · Score: 1

      What I was referring to was when people use IDE wizards to generate big clots of one-size-fits-all chunks of code - usually platform-specific - which does things they don't understand because someone hired a monkey-with-an-IDE instead of paying more for someone with proper training.
      Reminds me at the old COM and MFC days, luckily I only made that experiences at the periphery of projects that used such shit. Half of the generated code was in "do not edit" comments and the microsoft IDE enforced that you could not even edit those parts, even if they had obvious errors.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    182. Re:Doesn't matter in the end by Zero__Kelvin · · Score: 1

      OK.  Tell me what you need to know about UCODE_SIZE:

      #define UCODE_SIZE                      134
      struct cb {
              __le16 status;
              __le16 command;
              __le32 link;
              union {
                      u8 iaaddr[ETH_ALEN];
                      __le32 ucode[UCODE_SIZE];
                      struct config config;
                      struct multi multi;
                      struct {
                              u32 tbd_array;
                              u16 tcb_byte_count;
                              u8 threshold;
                              u8 tbd_count;
                              struct {
                                      __le32 buf_addr;
                                      __le16 size;
                                      u16 eol;
                              } tbd;
                      } tcb;
                      __le32 dump_buffer_addr;
              } u;
              struct cb *next, *prev;
              dma_addr_t dma_addr;
              struct sk_buff *skb;
      };

      --
      Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
    183. Re:Doesn't matter in the end by angel'o'sphere · · Score: 1

      This is not "well weitten code" as it is without comments uttery uncomprehendable :)

      Furthermore, with variable names like that, you have to dig into the comments everytime you use one, otherwise you are prone two mix some up.

      If one in my company had written this then his first task would be to fix te errors (hint, the very first define is already wrong) and then he had to fix the field/variable and struct names. AND after that comes comments.

      If you had read more of my posts, you likely had noticed that I explicitle extempt low level code from my point of view. Very low level code needs comments.

      Furthermore I explicitely stated: data structures and public functions and methods need a comment for every parameter/field.

      Finally: arguable, your argument is not even code. It is a data structure definition (see above: which should be DOCUMENTED with comments).

      So, after you have fixed the given structure with meaningfull names, and short descriptive comments, THEN show me some code working with it :) And I rewrite it for you in a way that it does not need any more comments.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    184. Re:Doesn't matter in the end by Zero__Kelvin · · Score: 1
      I hate to break it to you, but I got this code directly from a repository of some of the best code in the world, maintained by real Uber programmers. It is from linux/drivers/net/e100.c. The missing comment is "/* Important: keep total struct u32-aligned */". I specifically chose this excerpt because Linus is very much against commenting except when absolutely necessary, so this is a perfect example of when it is absolutely necessary.

      Everything else you wrote is just a failed attempt at weaseling out of admitting that you are completely wrong. It is code. You don't get to say what is and what is not code; that is the compiler's job.

      "So, after you have fixed the given structure with meaningfull names, and short descriptive comments, THEN show me some code working with it :) And I rewrite it for you in a way that it does not need any more comments."

      No. You won't. The code is already clear. It is you who would make the mistake of thinking that it isn't. There is no such thing as a descriptive name that would make it clearer. And your argument is that if I move the comments elsewhere then I don't need to comment my code. Again. Just a phenomenally stupid and failed weaseling attempt.

      --
      Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
    185. Re:Doesn't matter in the end by Anonymous Coward · · Score: 0

      if(!x){}

      or in some languages

      unless(x){}

      is more clear because it doesn't contain redundant information.

      So why not write in a more clear fashion

      All if(x==FALSE) does is highlight incompetent programmers.

    186. Re:Doesn't matter in the end by Meski · · Score: 1

      There's worse.

      a = 0; // loads a with 0

    187. Re:Doesn't matter in the end by angel'o'sphere · · Score: 1

      The code is without comments absolutely not clear. And again: most people would not call it code but a data structure definition. The code is not clear because none of the data field explains what it actually means. Every single "variable" is meaningless.

      Your first sentence must be a joke or? "Best Code in the world", no that code would give on a scale of "a" to "e" just a "c": it works. To get a "b" or "a" it needs to do more then "just work".

      On top of that: no I'm not completely wrong. You claimed: code without comments is impossible. I claim (among others) it is. You brought one example of code that I consider bad code. You consider it good code.
      Furthermore your "good" code, needs comments. That in no way contradicts my claim that "my good code" does _not_ need comments.
      The one who is faling, and is weaseling around, is you; as you are completely unable to step in some one else shoes and take his standpoint.
      You know: not all code in the world is low level device driver C code. Likely you did not even read my comment fully but jumped to conclusions.

      tell application "iTunes"
              delete track 7 of library playlist 1
      end tell

      So, what comment do you miss for this script?

      Ah, yes: when you grow up and start to be more polite I show you how to enforce alignment without a comment ;D (that the code was from the linux kernel or a device driver was obvious anyway, __le16 and other types are not really used outside of the linux world)

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    188. Re:Doesn't matter in the end by Zero__Kelvin · · Score: 1

      You contradict yourself at ever turn. Because you don't develop network drivers you have decided that the variable names are meaningless when they are not. Then you want to get around admitting that comments are important by claiming actual code isn't really code, and that commenting elsewhere is equivalent to not commenting. Furthermore, your suggestion to comment elsewhere violates important sound software engineering practices. In short, you are part of the 80% of people involved in software development who would do the world a great favor if they switched to janitorial work. Your claim that most people wouldn't call compilable source from a .c file actual code is patently absurd and supports my factual assertion that as a software developer you'd make a hell of a janitor.

      --
      Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
    189. Re:Doesn't matter in the end by angel'o'sphere · · Score: 1

      The only one who is absurd here, is you.
      You did not post a compile able "*.c" file but a "*.h" file.
      The rest of your pathetic attempt to keep face is again "a weaseling attempt" as you accused me before to get out of it.
      Sorry, my claim was simple: it is possible to write celar code that does not need further commenting.
      If you believe otherwise bring some facts and stop insults ad hominem.
      Good night.

      BTW, as a side note: "... hat as a software developer you'd make a hell of a janitor." Perhaps you are not a native english speaker ... I thought you would be, but well, you never know. I suggest you consult your favorite dictionary what a 'janitor' is :D

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  2. Contrast by Bogtha · · Score: 2

    If your aim is to make something more visible, don't pick a yellow-on-white colour scheme.

    --
    Bogtha Bogtha Bogtha
    1. Re:Contrast by crazyjj · · Score: 3, Funny

      Could be worse. They could use white on white.

      --
      What political party do you join when you don't like Bible-thumpers *or* hippies?
    2. Re:Contrast by flyingfsck · · Score: 1

      In most cases, white on white comments are best.

      --
      Excuse me, but please get off my Pennisetum Clandestinum, eh!
    3. Re:Contrast by Hentes · · Score: 1

      Coments that are only visible when you select them and otherwise don't distract you are not necessarily a bad idea (I use light grey for comments).

    4. Re:Contrast by Anonymous Coward · · Score: 0

      Agreed, I found the first set of comments 'more visible', maybe just closer to what I expect comments to look like.

  3. We need STRUCTURE by For+a+Free+Internet · · Score: 1, Funny

    In order to better utilize synergies and business genius patterns of excellence, comments need to be stored as XML in a cloud-based LDAP database that partners, stakeholders, clients and yourmom can access via an iPhone app. If you don't do this you are a monkey, or maybe a horsepig.

    --
    UNITE with the Campaign for a Free Internet because today, our future begins with tomorrow!
    1. Re:We need STRUCTURE by Anonymous Coward · · Score: 0

      Tell Laura I said Hi, and thanks for the other night (and the next morning).

  4. In My Opinion This Is a Non-Story by eldavojohn · · Score: 4, Interesting
    There's not much material to those links -- at least nothing even close to addressing the full problem. The "adjusted" code in the first link is trivial. Furthermore, that is how we comment code where I work. I'm surprised there isn't an annotation driven doc-generating friendly comment block at the top of that signature in their example (along with the inline comments)!

    The reason editors let you collapse comments is that you sometimes have to make really ugly code -- whether it's for performance or time constraints. And the only way to really describe it actually larger inline blocks that can obfuscate the code. So they make them collapsible for those who have read them already.

    Winer also makes the case for providing links in his code to external 'worknotes.'

    Yeah, we use an internal wiki.

    So, what are your thoughts on useful commenting practices or features, either implemented or on your wishlist?

    The biggest complaint I have is people who use comments to explain bad object/procedure/function/method/script/class/whatever naming. For example, a guy I worked with calls everything a "driver." Main method? That's a driver. Class holding the main method? Of course DriverClass. Package? Of course YYY.ZZZ.NNN.Driver. On it goes. Another guy likes to use the verb "interrogate" where as I like to use the verb "inspect" and I think that's just more about your origins (I think he's Spring background while I'm a little more on the Ruby/Groovy side of things). A common and well defined vocabulary inside your team and embedded in your actual code will take you much further than trying to explain it all out in the comments.

    --
    My work here is dung.
    1. Re:In My Opinion This Is a Non-Story by antifoidulus · · Score: 2

      The reason editors let you collapse comments is that you sometimes have to make really ugly code -- whether it's for performance or time constraints. And the only way to really describe it actually larger inline blocks that can obfuscate the code. So they make them collapsible for those who have read them already.

      Lets not forget (probably misguided) policy. A lot of places have policies that say you MUST have multi-line comments for each class/function/whatever. Being able to collapse those down makes it a lot easier to just bypass such forced comments.

    2. Re:In My Opinion This Is a Non-Story by devent · · Score: 1

      I understand that sometimes you need to make ugly code, for what ever reason. And you better document that ugly code if it's not clear. But why you want to hide that ugly code I don't understand at all. Are you hiding your trash under your carped? Trash is ugly and you should see it every time you look at the code, so you see how ugly it is and maybe one day you say: enough if enough and I'm going to fix that ugly hack now.

      Collapsed comments/code blocks are only make the ugly code disappear for the eyes, so nobody will care anymore. The result is, that it will be dragged on forever. And after 5 years you have hidden so much ugly hacks that the only solution is to re-write your whole application.

      Another reason for collapsed blocks of code are often that a class or method gets so big, you need to collapse out code to have any oversight. But you can also very easy split a big class in multiple classes (composition) or split a big method into smaller. For example, if you have one big method, then you can very easy put that method in a new class and use composition.

      --
      http://www.mueller-public.de - My site http://www.anr-institute.com/ - Advanced Natural Research Institute
    3. Re:In My Opinion This Is a Non-Story by Capt.Albatross · · Score: 1
      Devent says:

      Another reason for collapsed blocks of code are often that a class or method gets so big, you need to collapse out code to have any oversight. But you can also very easy split a big class in multiple classes (composition) or split a big method into smaller. For example, if you have one big method, then you can very easy put that method in a new class and use composition.

      Factoring can definitely be taken too far. If you were to convert every block into a method, you would have a great many methods with long argument lists, and it would be difficult to come up with meaningful names for these methods, as each block's purpose is so closely tied to the context in which it appears. You would end up with code that jumps around so much that it would be very hard to see what it does. This happens, and there have been many times when I would have liked a composing tool to convert a deeply-nested tree of tiny methods into a sequentially-readable algorithm.

      I think you are missing the point that comment- and block-collapsing within an editor/viewing is temporary and reversible. You can start by reading the comments, but once you understand them, you might want to collapse them selectively to get a better look at the code. Think of it as a form of variable and adaptive abstraction (the root of the word abstraction is the Latin for 'draw (pull) away'.) Hiding exception-handling blocks can be helpful, too, so long as exceptions have been used correctly and are not used for control flow in the normal execution of the algorithm.

  5. Use vi by Anonymous Coward · · Score: 3, Insightful

    Use vi. Always works for me.

    1. Re:Use vi by Anonymous Coward · · Score: 1

      :s/\.\($\)\@!/m\./g

      I agree now that it's fixed :-)

      Proof of point, I learned something (negative look-ahead assertions) about vim since I started typing this comment ! I love my text editor!!!

    2. Re:Use vi by Anonymous Coward · · Score: 0

      :s/vi/vim/

      Now you've learnt something about economy of typing :D

      I learnt something from your overly complex regex though, so thanks!

    3. Re:Use vi by Anonymous Coward · · Score: 0

      I love vim. I no longer need to know it. My fingers do all by themselves.

  6. There's No Impetus for Comments by Anonymous Coward · · Score: 3, Interesting

    ...because most organizations are total failures that make you write and maintain thousands of pages of "design" documents that are actually just the code-base itself converted line-by-line to English sentences. Thus, no comments are ever written, because the developers are already maintaining two instances of the entire code-base.

    1. Re:There's No Impetus for Comments by Anonymous Coward · · Score: 0

      Too true. That reminds me of software that creates flowcharts from code or ER diagrams from a database.

    2. Re:There's No Impetus for Comments by parkinglot777 · · Score: 1

      And I believe that is one of the problems too for not having comment. How would one know that the code is up to date to the design document, or vice versa -- if there is any hack in the code that does not match the design document? Not to be offended, but both are developer's responsibilities (not only maintain codes but also documents).

    3. Re:There's No Impetus for Comments by Kergan · · Score: 1

      Where this argument falls apart lies in the fact that the documentation is seldom written whereas the code actually is.

      Typically, this is because the code gets maintained; whereas the documentation/spec, by contrast, seldom is. When it is, it all too often turns into an endless list of how to work around known bugs.

    4. Re:There's No Impetus for Comments by Anonymous Coward · · Score: 0

      This is complete sillyness. When this happens, the docs quickly bit rot. Use a tool like doxygen and have a single comment base with various autogenerated formats. Then use the @mainpage to describe the high level design. I also add custom tags to doxygen. This is very useful for things like Qt signals, slots, and connects. My tags look like: /** @Qt - Slot - Describe why my slot is needed. All my Qt comments can be gathered together on one page automagically.

      it is even slicker to have a cron job on your webserver machine do an svn up, run doxygen to create html and place it on the server automatically every n hours. If other devs are using your libs and have up to date docs available like this, they will love you.

  7. Getting developers to comment by laffer1 · · Score: 4, Interesting

    At my current job, most of the developers think commenting is weak. I've dealt with this problem before, but it's awkward when I'm the only one that wants to comment. Funny thing is, every time we hit a program that a former developer wrote that my boss can't understand, he makes us rewrite it. Having comments in the code might save a lot of development time.

    When I managed a team, I required commented code. It saved our butts more times than I can count. I also use it to look for bugs. It's amazing what code review can do a few weeks after you wrote something or having another developer look at. When code doesn't match comments, there's a bug.

    1. Re:Getting developers to comment by Anonymous Coward · · Score: 0

      When code doesn't match comments, there's a bug.

      Uh, that, or someone rewrote the code but forgot to change the code comments. As they say, "Code comments are not compiled".

      Now, someone is going to exlpain that this someone was "sloppy". I think this is an oversimplification. The guy who always comments his work, always changes comments when he makes changes, always writes tests and uses them for every change, always makes diagrams of the work, and so on and so on... I never met that guy. Ever. Except in news groups and the like, i.e. when there was no way for me to actually inspect his work to chech whether the actually did all these things. It is my theory he does not exist.

    2. Re:Getting developers to comment by QuietLagoon · · Score: 1

      When code doesn't match comments, there's a bug..... When I managed a team, I required commented code. It saved our butts more times than I can count.

      What if the code is correct, and the comments are wrong? Sure, that may be a bug in your eyes, but why spend the time writing incorrect comments?

      .
      If the "required comments" saved your butt more times than you can count, that shows that your coding team members can write sentences better than they can write code. Perhaps your team members are in the wrong profession, or maybe you need to improve the ability of your team members to write high quality code.

    3. Re:Getting developers to comment by rwa2 · · Score: 1

      I think developers would enjoy having docs auto-generated by something like doxygen... that way their comments kinda get wrapped up in some kind of deliverable that sort of looks professional and would actually be accessible to non-coders (i.e. their bosses or even maybe their family). They'd feel more pressure to provide comments (so their API doctree doesn't look pathetically empty), and it would be part of maybe an official deliverable and not something only seen by other developers. Plus, devs like getting a lot of nice-looking work done "for free" by the doc generator.

      I also like the way Python does things with doctest, so devs are encouraged to put examples of their functions and modules working in their docstrings, and it becomes part of an automated unit test for their code.

    4. Re:Getting developers to comment by Dixie_Flatline · · Score: 2

      Not at all. Extremely complex systems can be hard to trace the codepath through. Someone putting comments into a function to explain how it interacts in the greater scheme of things can be extremely helpful.

      Comments aren't meant to explain code. You should be able to read a for loop. But if I'm in the middle of a function that's crashing and there's a comment telling me how this function interacts with the SYSTEM, then I can understand the CONTEXT of the code and more easily find the error. Otherwise, it's 20 minutes or an hour of reproducing the problem and then parsing the stack trace and then figuring out where this variable has been modified instead of where it SHOULD have been modified, etc., etc.

    5. Re:Getting developers to comment by parkinglot777 · · Score: 2

      What if the code is correct, and the comments are wrong? Sure, that may be a bug in your eyes, but why spend the time writing incorrect comments?

      Then go back (or refer) to one of reasons that Simon Brook's comment pointed out -- Procrastination. It is the programmer/developer responsibility to do it at the same time when update codes. The comment concept works if and only if every programmer/developer is at the same level (everyone does it and does it right). If one or more are not, that could easily screw the whole concept of having comments. It is a good practice, but not everyone does good practice.

      your coding team members can write sentences better than they can write code

      Writing comment does not require to be perfect. An average write up about what it does may be suffice. If you are talking about the time spent in writing comments, then you should already know that it could be as much time spent as in coding. That's normal.

      write high quality code

      Please define the phrase above. It is too broad and there aren't many (if none) programmers/developers who can actually write a whole software/program codes that are correct, robust, optimal, and maintainable. If you are talking about a module or a small function/method, then I would see that is much more possible. However, it is not practical for real work because it is very rare to use only one function/method/module for a program/software.

    6. Re:Getting developers to comment by Anonymous Coward · · Score: 0

      laffer1 did not say that the code is wrong or that the comments are wrong he just says there is a bug as the two do not match.
      1) It was documented to do A
      2) It does not do A
      There is a bug. 1) may be wrong. 2) may be wrong. It does not alter the fact that something is fishy about it.

    7. Re:Getting developers to comment by Anonymous Coward · · Score: 0

      All you need is code review and a competent version control system (with easy universal access to the equivalent of "git gui blame"). No need for tradeoffs between documentation and readability: all documentation is in the commit log, and review means that it is all correct.

  8. Other Things on Programmers Minds by xxxJonBoyxxx · · Score: 1

    >> It seems like comments are on programmers' minds these days

    Really? I'll bet the new round of browsers, iOS, Windows 8 (have you seen how many APIs and visual paradigms are broken?) and any number of other major platform changes are much, much more on the minds of programmers these days.

    >> Winer also makes the case for providing links in his code to external 'worknotes.'

    Oh God - one of those people.

    1. Re:Other Things on Programmers Minds by Cenan · · Score: 1

      Yeah and what happens when the 'worknotes' server is taken offline or moves? If you can't explain what your code does in the space you have, you're doing something wrong.

      --
      ... whatever ...
    2. Re:Other Things on Programmers Minds by Anonymous Coward · · Score: 0

      If you can't explain what your code does in the space you have, you're doing something wrong.

      More like:

      If you can explain what your code does in the space you have, you're doing something easy.

      I've lost count of the amount of code that eventually collapsed to:


      for (int i=samples.start;i<samples.end;i++) for (int j = kernel.start;j<kernel.end;j++) samples[i-j] += samples[i] * kernel[j];

      ... but actually explaining what that single line does including the mathematics by which the kernel is derived, and the reason why we're doing that can take many screen-fulls of text. Personally, I just stick the information straight in there with the code. If it takes a 4-screen-long comment, then that's what it takes.

      Not everyone is working on code that can be summarised in 2 lines.

    3. Re:Other Things on Programmers Minds by Anonymous Coward · · Score: 0

      Oh God - one of those people.

      I hereby give this man a field promotion to Anal-ist!

      Bad pun aside, it's this kind of methodical thinking that goes a long way in producing a solid & complete analysis.
      I think he'd also make a great tester, another place where dotting the i's and crossing the T's makes the difference between good & great.
      As developper he might be shooting himself in the foot, unless every dev is required to use this level of commenting. Someone else who works on his code (while he's on vacation or sick) and who doesn't uphold this high level of commenting will appear to code alot faster, because he won't be commenting and the commenting will help him to understand the code alot faster.

  9. Good comments are good. by darkwing_bmf · · Score: 5, Insightful

    I don't really understand why we're going over this for the 50 thousandth time on slashdot, but as always, good comments are good, bad comments are bad. Comments that describe the interface of the function you created and how its supposed to be used are good. Comments that say "increment the variable" are worthless and perhaps worse than worthless as they add maintenance problems when the underlying code is later changed and nobody bothers to change the comments as well.

    1. Re:Good comments are good. by Anonymous Coward · · Score: 0

      // Enter for-loop, increment variable and execute block
      for (i=40000; i>=-256; --i) { //some code here for the lulz
      }

      And you're done

  10. Save time by bill_mcgonigle · · Score: 3, Informative

    Comment first, fill in the code later.

    --
    My God, it's Full of Source!
    OUTSIDE_IP=$(dig +short my.ip @outsideip.net)
    1. Re:Save time by ShanghaiBill · · Score: 4, Insightful

      Comment first, fill in the code later.

      Yes. And as you write the code, make it clear enough that you can then eliminate the comments. If your comments are this:

      // process command line arguments
      // read input files
      // process the data
      // output the results


      Then your code should look something like this:

      void
      main(int argc, char *argv[])
      {
          processCommandLineArguments(&argc, &argv);
          readInputFiles();
          processData();
          outputResults();
      }

      and now the comments are no longer needed. So you should write comments first, then write the code, then look at each comment and try to eliminate it by making the code clear enough that the comment is superfluous.

    2. Re:Save time by medcalf · · Score: 2

      Yes, exactly. When I write code anything more than a bog-standard getter/setter method, the first thing I do is write a comment describing everything coming in and everything going out, and how "in" and "out" differ. Then I write a series of comments going through the entire set of steps that have to happen (at 50000' level) to get the in, do the transformation to produce the out, and actually send off the out. For those parts where the 50000' view isn't obvious ("read in the file from the passed filehandle, throwing an exception if you can't" covers it, but "now combine the two streams" doesn't), I break it down further in more comments. Only when I'm sure that the comments are a good approximation of the final flow do I actually write the code. During that process, I eliminate those comments that are now superfluous (for example, because the code is obvious and common, or because the why is otherwise unimportant for that block). The end result is a small increase in the time to write the code, and a vast decrease in the time needed to debug the code, along with dramatically better maintainability.

      --
      -- Two men say they're Jesus. One of them must be wrong. - Dire Straits
    3. Re:Save time by Cenan · · Score: 1

      Better yet: don't write comments you know you are going to delete, write tests. That way you wasted no time typing.

      --
      ... whatever ...
    4. Re:Save time by CrazyBillyO · · Score: 2

      Sounds similar to the pseudocode programming process.

    5. Re:Save time by DahGhostfacedFiddlah · · Score: 1

      Interesting strategy. I'm definitely going to try out a comments-first writing style. Thanks for the idea.

    6. Re:Save time by brausch · · Score: 2

      This!

      --
      "Almost every wise saying has an opposite one, no less wise, to balance it." - George Santayana
    7. Re:Save time by Tarlus · · Score: 1

      Sometimes it's easier to just write down what you intend to do, in the order you intend to do it. Then the actual code and function-naming can come later.

      --
      /* No Comment */
    8. Re:Save time by Cenan · · Score: 1

      Agreed, but we weren't looking for 'easy'. If the concept you're trying to put into code needs comments to help you wrap your head around it, that smells exactly like a piece of code that needs thorough testing.

      --
      ... whatever ...
    9. Re:Save time by Anonymous Coward · · Score: 0

      Perfect example. My code is self-documenting like this. I use variables and function/method names which describe what they are and what they are doing. If you need a comment to know that readInputFiles() reads input files...then you probably shouldn't be coding.

      I don't mind the lack of comments but I hate the use of lame variables names. I'm currently cleaning up some code where every query is named "q"...so it's nearly impossible to find the one query you are looking for. Likewise, all of the variables are single characters...so you have no idea what they represent. How about naming it "buildingType" instead of "t"?

    10. Re:Save time by betterprimate · · Score: 1

      True. That's a great method; something to consider adhering to. However, the best code isn't always written in those steps. Here, let me tell you what no one on this thread can deduce it to: Comments are meant for bullet points: objectives. That's all.

  11. Clarity by Missing.Matter · · Score: 1

    Without this ability there's an impossible tradeoff between comments and the clarity of comment-free code

    As far as I'm concerned, there's no such thing as comment-free code that is clear.

    1. Re:Clarity by h4rr4r · · Score: 1

      Really?
      So even a simple method that just load some stuff into a hash and then returns the value that matches the key it was given should be commented?

      At some point the code is so simple it comments itself.

    2. Re:Clarity by Anonymous Coward · · Score: 0

      It still doesn't comment itself, UNLESS the method has a descriptive name.

      I would propose a general principle: one should not have to look at anything between the opening and closing braces (C-syntax) of a function in order to understand what it does. If the names of the function and its arguments are not sufficient to explain the function, a comment is needed.

    3. Re:Clarity by thePowerOfGrayskull · · Score: 1

      i++

      Those sweeping generalizations will get you every time.

    4. Re:Clarity by tommituura · · Score: 1

      I, for one, am of the school of thought that within the method, stuff should be so clear that it isn't necessary to add any comments clarifying a line or two. Of course, sometimes, somewhere needs to exist a big function or method which does a whole lot of stuff to bring everything together. That one can get its inline comments. Even those should be used sparingly.

      But every (and yes, I do mean * every single one *) method/function (1) has to be given a heading comment block that explains what it takes as arguments, what it does with them and what it returns (and especially important is what happens on those nasty corner cases).

      And if your method is really so dead-simple one-liner thing ... it should be asked if the method really needs to exist at all?

      (1) Well, okay. Depending on the language, sometimes the simplest of closures do not need this.

    5. Re:Clarity by jsmyth · · Score: 2

      Really? So even a simple method that just load some stuff into a hash and then returns the value that matches the key it was given should be commented?

      At some point the code is so simple it comments itself.

      Sure, because then the next coder, instead of saying

      "Huh? Why is he filling a hash only to return a single value?"

      can say:

      "Oh, that's what he was trying to do. What a kludge. I'll fix it."

      ...and write it properly.

      --
      jer

      We may be human, but we're still animals
      - Steve Vai
    6. Re:Clarity by betterunixthanunix · · Score: 1
      Really, that's the example you chose? That is not at all clear. That might increment i (so that the new value of i is one greater than the old value) -- but that might also cause an integer overflow. If this is C++, you might have a type that overloads the ++ operator: maybe that is a type for saturation arithmetic, so i++ might not even change the value of i.

      Really, if you want to see code that clearly specifies what it does, you need to look at higher level languages. Prolog comes to mind here, as do those languages Backus created for "function level programming." If you know Prolog syntax, then this code requires no comments:

      rev([],x,x).
      rev([x|xx],y,z) :- rev(xx, [x|y], z).

      --
      Palm trees and 8
    7. Re:Clarity by h4rr4r · · Score: 1

      You have a list of companyids to company guids. You take the company name in from the users, but you need the guid, so how would you do it?

    8. Re:Clarity by betterunixthanunix · · Score: 1

      At some point the code is so simple it comments itself.

      That really depends on your language. Consider this EmacsLisp code:

      (defun fact (x) (if (<= x 1) 1 (* x (fact (- x 1)))))

      That sure looks like a definition of factorial, but on my system, that will only give you the right answer if x is less than 12. The reason, of course, is that in EmacsLisp numeric values have fixed precision, and you get an integer overflow. There are two possible answers to that situation:

      1. Well duh! Just use an arbitrary precision type. Write one yourself if EmacsLisp does not have it built-in. That code can still be self documening!
      2. Add a comment warning other programmers that the function will only work for some limited range of possible input values.

      Or perhaps this third option: don't code in a language where such a thing can happen. I wonder how many C programmers would try pushing for that option...

      --
      Palm trees and 8
    9. Re:Clarity by thePowerOfGrayskull · · Score: 1

      Yet the number of people who would be able to decipher that without comments is vastly lower than those who could decipher my example - an example that works the same way in any number of languages.

      As far as overflow possibility: sure. but a comment wouldn't tell of that possibility either.

    10. Re:Clarity by Anonymous Coward · · Score: 0

      that only tells what it's doing, not why

    11. Re:Clarity by Dog-Cow · · Score: 1

      In languages such as Java, one liners will probably become the bulk of the code.

    12. Re:Clarity by betterunixthanunix · · Score: 1
      True enough, although if you are not a prolog programmer, you really should not be reading through prolog code (unless you are just trying to learn). A comment might specify some behavior that the code does not exhibit -- you need to be able to read both.

      As for the overflow, a comment could clarify things -- for example, if you know that the variable is constrained to some range of values, then just writing that in a comment (say, "0

      for(i = 1; i < n; i++) res = res*i;

      A quick comment clarifying that n will be in some range for which this will not wrap around could be really helpful -- if, say, you are debugging and seeing some strangeness, such a comment gives you something you can check (is n really in that range) or at least a clue about a possible issue (maybe the comment was written assuming 64 bits for res, but you are using a 32 bit type -- but the comment still provides a clue that an overflow can easily happen in this code).

      The problem with writing clear code is that even seemingly simple code can have some non-obvious behavior; i++ is a perfect example. It looks like it only says, "increment i;" what it actually says is, "increment i modulo 2^n," where n is typically 32 or 64 but could be something else. That is not obvious, especially when you almost always see i++ being used as a way to increment integers. It is not enough to demand that programmers train themselves to think differently, and there are cases where just using a language with more natural definitions (e.g. one in which arbitrary precision arithmetic is the default, or perhaps one in which an overflow causes an exception to be thrown) is not really an option (if you have a million lines of C code, you need to write at least some C code).

      --
      Palm trees and 8
    13. Re:Clarity by betterunixthanunix · · Score: 1

      Speaking of non-obvious problems...slashdot ate a few < characters in there...

      --
      Palm trees and 8
  12. The problem with comments ... by Dark$ide · · Score: 2
    Isn't whether they are displayed, isn't wether they exist or not it's whether they add any value, whether they describe why the code has been written in such an obscure way.

    There's also nothing worse than a comment that states the bloody obvious. If I'm clearing a register to zero I don't need a comment next to the SR 6,6 or XR 6,6 that is performing that action. I can read the code to see what the bloody code is doing.

    The time that code needs a comment is when you're shifting bits or multiplying something by a funky/obscure value for a sensible reason but the reason isn't obvious by simply reading the code.

    Also remember you don't get the comments in the post mortem storage dumps when you're trying to fix someone's programming error at 2:30am with a few managers breathing down your neck panicing that it won't be fixed and running by 8:00am.

    --

    Sigs. We don't need no steenking sigs.

    1. Re:The problem with comments ... by Anonymous Coward · · Score: 0

      This!, so so much this.

      When I comment my code, I don't just annotate the actions I'm taking, but the intention as well as my own opinion as to the elegance (or lack of it) of the solution in the written code, this way code maintanance and/or revisiting code for optimization is a damn sight less frustrating experience.

      You might know why you did something the way you did when you wrote it, and how happy you were with the route taken but can you honestly say the same if you have to revisit it later?

  13. Keep them short but pertinent by danbuter · · Score: 1

    I think all code needs comments, unless it's something incredibly basic. However, keep the comments short and to the point. Don't write a paragraph when all you need is a sentence. Also, don't use slang unless it's extremely well known.

    1. Re:Keep them short but pertinent by nschubach · · Score: 1

      What if you can write your code so that every method is incredibly basic?

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
  14. You're missing the point by For+a+Free+Internet · · Score: 1, Funny

    Hey asshole, I don't know about you, but I make my comments on Slashdort , where they are appreciated and honored by the Slashdort community, whereas you are a noxious pigfart sniffer and dogsmoocher.

    --
    UNITE with the Campaign for a Free Internet because today, our future begins with tomorrow!
  15. Removing comments from code by Latent+Heat · · Score: 4, Insightful
    I think it is a good design rule that if you have a comment describing some inglorious hack, maybe you could rewrite the code to remove the comment along with the hack?

    I also think that comments describing interfaces are better than comments describing processes. This is the old thing of "describe what the module does and leave the description of how the module does what it does to reading the actual code." So preambles describing the parameters a function takes and valid ranges on those parameters are most useful.

    The other thing about comments is not so much the writing of them but the keeping them up to date. The compiler doesn't check that the comment is still relevant to a function you have changed.

    1. Re:Removing comments from code by RobertLTux · · Score: 4, Funny

      in the case of some inglorius hacks documenting WHAT YOU WERE DRINKING at the time may be the most useful (or what you were on or the fact that you were on hour 47 of your shift...)

      --
      Any person using FTFY or editing my postings agrees to a US$50.00 charge
    2. Re:Removing comments from code by parkinglot777 · · Score: 2

      "describe what the module does and leave the description of how the module does what it does to reading the actual code."

      If I understand you correctly, it means that only one description should be there but not the other? If so, I have to disagree. The description of what module does should be placed on the top of the module, but the description of how the module process should be inside the code (inline). What module does could be taken from the design document; where as, its process is related to the algorithm used. Leaving out the description of the algorithm (process) is similar to encrypting the code because those who inherit the code may not understand why certain thing is there. Both type of descriptions should be there but in different places.

    3. Re:Removing comments from code by Anonymous Coward · · Score: 0

      That is very good advice and should be heeded whenever hacks crop up. Unfortunately I have also encountered a lot of situations where the hack is just a symptom of a problem somewhere else, out of your control. This can make it very difficult or impossible to replace the hack with something sane. All the more reason to document your code well.

    4. Re:Removing comments from code by Anonymous Coward · · Score: 0

      We have __FILE__ and __LINE__, but when, oh when will we have __INTOXICANT__?

  16. What other engineering disciplines do. by trout007 · · Score: 5, Informative

    I'm a mechanical engineer. Our "code" is models and drawings. These are what represent the real world objects in our designs. But you don't just deliver a set of drawings as a product. You have Analysis Reports, Design Manuals, Operation Manuals, Maintenance Manuals, Parts Lists, Concept of Operations, and about 20 other documents that describe the system you built. Sometimes a good engineer can pick up the drawing package and figure out how the thing works. But if you really want to understand the design you have to read the other products. If those products don't exist you end up reverse engineering from the design.

    --
    I love Jesus, except for his foreign policy.
    1. Re:What other engineering disciplines do. by retep · · Score: 1

      I'm an electronics designer and I'm in the exact same boat, although where I work we're pretty lax on all the other stuff, so often we just have schematics to work from. Granted I'm at a schedule-driven startup, so being lax can be a valid tradeoff between time spent on documenting stuff, and time wasted due to forgetfulness and the bus factor. Just like with programming (a former career path of mine) even just some simple notes on what equations you used to design something can be hugely useful I find.

    2. Re:What other engineering disciplines do. by scamper_22 · · Score: 1

      Exactly.

      The problem with software design is simply that we don't have any reasonable professionalism or time to make sure this stuff gets done. It is ALL about speed of innovation and cost-effectiveness. It is one thing to expect the business side to worry about these. It's quite another to have most of the people in the profession be on side with the business on these.

      There are most certainly valid uses for in-code comments. Little exceptions, workaround...

      Yet, most supporting material can and should be in another form. Diagrams, documents...In some fantasy world of mine, I could link from the source code to an external document. Perhaps a good editor actually loads that section inline.

      I never blame any individual developer as this is the system we have.

    3. Re:What other engineering disciplines do. by trout007 · · Score: 1

      Don't get me wrong. There are plenty times when you are doing a preliminary design or a prototype where all you do is model the parts in CAD and have a machinist make them with standard tolerances. Then when you find problems with fits and interferences you modify the parts to make them work and never follow up with good documentation. This will only work for a one of kind stand alone product. Because you have no guarantee the next one you build will work the same way. This also only works with a small design team that can keep the whole project in their heads at one time.

      Once you add interfaces and different groups working design and analysis and different subsystems you need real documentation of the interfaces otherwise you will waste lots of time and money getting things to work together.

      --
      I love Jesus, except for his foreign policy.
  17. Trust by MrSome · · Score: 1

    For me, when it comes to comments, is it's about who wrote them.

    There are people I work with, who, no matter how much commenting they do, I still don't trust they knew what they were doing. So I'll always step through and analyze what the code is doing myself. Could that be classified as "Don't judge a book by it's cover." ?

    Here's a question, if the code is written well... doesn't it document itself? I mean, as a developer/programmer, shouldn't I be able to read/speak that language fluently enough that I don't need a full english translation?

    1. Re:Trust by multipartmixed · · Score: 1

      > Here's a question, if the code is written well... doesn't it document itself?
      > I mean, as a developer/programmer, shouldn't I be able to read/speak that language fluently enough
      > that I don't need a full english translation?

      No. Comments explain what and why. Code explains how.

      --

      Do daemons dream of electric sleep()?
    2. Re:Trust by nschubach · · Score: 1

      Proper naming can explain what and why...

      importSettings(... <-- what it's doing
      importSettings(settingsFile, sqlNode); <-- why it's importing the settings... you need the sql node of the settings file
      Also, can be written as (depending on the language, etc):
      sqlNode = importSettings(settingsFile).sqlNode;

      The 'how' is the method itself.

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
  18. Write clear code, remove comments by ShanghaiBill · · Score: 3, Informative

    I used to put a lot of comments in my code. Then I read the book Clean Code, and it changed the way I look at comments. Basically, every comment you leave in your code is an admission of defeat: you were unable to write your code clear enough to eliminate the need for the comment. Today, I write my code with comments, and then I go back and try to eliminate each comment by making the code clearer instead. So instead of

    do_args(&argc, &argv); // process command line arguments

    I do this:

    processCommandLineArguments(&argc, &argv);

    and the comment is no longer needed.

    Today, my code has far fewer comments, but is easier to read and understand. The few comments that are left are usually block comments that explain why something is done, or outlining how the code could be improved or expanded in the future.

    1. Re:Write clear code, remove comments by Anonymous Coward · · Score: 1

      I haven't written actual useful code for many years now, but when I did my comments were about how I was attacking a particular problem or why I did things a like I did and not in any of the other ways I thought it could be solved; and the reason wasn't to make the code easier to read; it's more about provinding more useful data to another method down the line or some clever workaround to get the thing to go a tiny bit faster.

      I never ever got feedback from any of that since no one, aside from a teacher at university, or a close colleague/friend that I asked to look at something in particular. Thus, I can't tell if that's a right way to comment code.

    2. Re:Write clear code, remove comments by Compaqt · · Score: 1

      Something that's often said in combination to what you said is to keep your functions short (like 7 code lines).

      Most people will whine at that, but the fact is you can't hold more than 7 lines in your head anyway. And, like you said, your code should just be a sequence of very explicit functions:

      adjustColor();
      scalePicture();
      cropPicture();
      addWatermark();

      and the same in each of those functions.

      (These guys say 62, YMMV)

      --
      I'm not a lawyer, but I play one on the Internet. Blog
    3. Re:Write clear code, remove comments by Anonymous Coward · · Score: 0

      So much this.
      Leaving comments just for the sake of it is stupid.
      Describing interfaces and APIs is useful.

      I think the code in the example linked to in the summary would be better served by renaming things like skb, kauditd_send_skb to something clearer.
      His choice of colors also makes the comments stand out more than the code itself.
      That can't possibly be how it's supposed to be.
      What the hell does /*shouldn't happen*/ mean? what shouldn't happen, an error? no shit.
      If you're going to put a comment at least make it something useful like: the error should always be ECONNREFUSED

      we might get lucky and get this in the next auditd?
      Does that mean the next time this function is called?
      What if it's not the next time, but the one after that?
      And what happens if we do get it?
      That comment explains nothing.
      You can remove it without losing any understanding of the code.

    4. Re:Write clear code, remove comments by cognoscentus · · Score: 0

      This should be a prerequisite, but is half the battle with a lot of code. The rest is explaining how all those descriptively-named functions do what they do, why they do them in a specific way, and known issues and gotchas. But generally, the more human-readable meaning we can impart to the actual commented code, the more meaningful our stack traces, logs and diagnostics will be. The more code can be written in an easily human-readable form without comments, marking the intended purpose and context of use, the harder it is to hide (and write) buggy code. See BDD, where one defines pre- and post- conditions for every function. In an ideal world, we would express tasks in a precise declarative language, with the minimum of hints as to how to perform them, and the compiler/runtime would deduce the implementation. Unfortunately, Prolog and constraint programming languages have so far fallen short of this dream. In the meantime - the 'what' should be in the code, the 'how, why and watch out' should be in the comments.

    5. Re:Write clear code, remove comments by Anonymous Coward · · Score: 0

      That's excellent. You saved yourself by saying you have fewer comments not none. I completely agree that naming functions and variables appropriately make it work.

    6. Re:Write clear code, remove comments by Dixie_Flatline · · Score: 5, Informative

      Comments aren't just there to explain the code. Of course you should write clear code. But I work in the games industry; there are times where clear code is thrown under the bus for the sake of efficiency. There are annoying convoluted constructs that are optimisations but they read like someone just showing off.

      But this speaks to a fundamental misunderstanding of what comments are for. You're not explaining the code, you're explaining the algorithm and the basic thing that your code is meant to accomplish. You don't write comments to let people know that you're looping over an array, you write comments to let people know WHY you're looping over an array and why they should care. I'm all for verbose variable names, but if you're going over 132 columns I'm already irritated. Go on for 80 more and it's tremendously annoying to read the 'clear' code.

      There are a lot of different ways to solve problems. Ideally, your comments should lay out what your thought process was when you were solving this particular problem. If you leave, someone will understand the problem you were trying to solve, and that context makes reading the code easier.

      And even if you don't leave, it's a good shortcut for yourself if you have to come back to that code several years later. I've saved myself a lot of time by commenting things well. Five years is long enough for my thought process and problem solving methods to change, so when I look at the code and wonder why in the hell I did something in such a dumb way, the comments tell me what was going through my inexperienced head.

      Lastly, and perhaps most importantly, humans don't agree on the meanings of words. There is some research (that I've read in passing; no citations at the moment) that says that we all have our own meaning of words, and we all speak completely unique languages that just happen to overlap with other people's unique languages. To write code that is universally understandable, you need to write code that has a completely unambiguous context to all people at all times (well, more or less). As someone that works in a heavily bilingual office (in Montreal), you can't guarantee that the programmer before you had the same interpretation of things that you do.

    7. Re:Write clear code, remove comments by larko · · Score: 1

      I'm glad you mentioned this book - it's what I follow now too. The post says there's no penalty for a full explanation of the code, but there are lots of penalties: 1: The explanation is a translation from one language to another, and there will be inconsistencies 2: When the code changes, the comment might not change, which can be misleading, and 3: When the code changes, that's a ton of work to update every comment! If I use a refactoring tool to change the names of a function, that might be dozens of places automatically changed... I'm going to read each one to see if a comment needs changing?

    8. Re:Write clear code, remove comments by prefec2 · · Score: 1

      You still have to document what the purpose of the code is. Good identifiers, for example, are only helpful when they can be understood by another developer. Therefore you have to explain the domain these vocabulary comes from. In your example, it should be known to da developer, as command line arguments should be a known construct, as it is a technical term.

      Beside that, comments should state what are the boundaries of your function. For example, what happens when it is called with null,null. And if it forces a state change. A good IDE will provide that information when asking for it. Instead of opening the code (which could be unavailable, as it is part of a library or developed somewhere else).

      So clean code is a good thing (I would call it required), but it is not sufficient.

    9. Re:Write clear code, remove comments by birdspider · · Score: 1

      Darn, hitting options->save while editing on ./ ate my msg, so I just say:

      Yes, also comments need maintenance as well as code does. Guess which is more up to date.

    10. Re:Write clear code, remove comments by Anonymous Coward · · Score: 0

      brilliant

    11. Re:Write clear code, remove comments by Anonymous Coward · · Score: 0

      Exactly. A nice point from Clean Code is that comments often violate the DRY principle.

    12. Re:Write clear code, remove comments by MrSenile · · Score: 5, Insightful

      Ok.

      And if I'm off the street, new to the company and see your line:

      processCommandLineArguments(&argc, &argv);

      Sure, I know what the function -likely- does, based on the name.

      Now how about the other questions.
      1. why does it need to process the command line arguments.
      2. what are the command line arguments that you are passing in.
      3. what is the error control of that function if given improper values.
      4. what is the error control of that function if given too many values.
      5. how many arguments total can it handle.
      6. what is the syntax it expects for the arguments
      7. are there any global variables being defined or redefined in that function.


      You take a lot of things for granted that a lot of other developers will be looking for.

      This, is why documentation is needed. I don't believe at all it's an admission of defeat. I believe it's an earmark of a beautiful programmer. Just because your code is insanely clean and documented, in itself, does not mean you should omit the block of description for variable calls, error return calls, exceptions, limits, and any global declarations. And while including this into a centralized wiki is good, I'm sure coders will not be inspired to cross-reference a program with a wiki and keep doing searches for function names. It breaks down their train of thought and frankly slows down productivity.

      Assuming others can just understand it without the documents would be arrogance.

    13. Re:Write clear code, remove comments by swan5566 · · Score: 1

      For simple programs this might make sense, but for more complicated scientific programming, a function may do something rather complicated, have caveats, and may do something similar to another function (but not quite). You're going to end up with a function name that's 5 lines long. Comments have their place.

      --
      In debates about Christianity, there are two groups: those looking for answers, and those looking to just ask questions.
    14. Re:Write clear code, remove comments by fredrated · · Score: 1

      Code as documentation only works for bug-free code. Congratulations if that is all you write.
      Otherwise, the bug in the code says that this bad thing is what we want to happen.

    15. Re:Write clear code, remove comments by retep · · Score: 1

      Linus Torvalds has an interesting comment regarding your style of programming: plain-old C can make a lot of sense precisely because abstractions wind up being implemented with relatively verbose code. Compare C++ code using operator overloading, vs. object-oriented C code using functions, or at the very extreme, lisp where the language itself is different due to heavy macro use. It's the C code that's most likely to be readable by other maintainers, even if it takes more lines and typing to do what it does. The Linux kernel has a lot of developers with relatively little management structure or co-ordination, as well as being relatively simple programming in the sense that they can avoid a lot of the more complex logic more often seen in, say, GUI code, so you can see why that kind of trade-off can make a lot of sense.

    16. Re:Write clear code, remove comments by Anonymous Coward · · Score: 0

      You're not explaining the code, you're explaining the algorithm and the basic thing that your code is meant to accomplish. You don't write comments to let ponies know that you're looping over an array, you write comments to let ponies know WHY you're looping over an array and why they should care.

      People wrote books and movies, movies that had stories so you cared whose ass it was and why it was farting, and I believe that time can come again!

    17. Re:Write clear code, remove comments by parkinglot777 · · Score: 1

      Today, my code has far fewer comments, but is easier to read and understand.

      That's very subjective. If the code really explains itself, then it is good. However, each person usually thinks that his or her code is clear to himself/herself. Also, not every code the person does would have the same quality (self explanation). Remember, nothing is perfect. I would rather leave more comments than think that my code is clean and clear to everyone else.

    18. Re:Write clear code, remove comments by multipartmixed · · Score: 3, Interesting

      You missed the most important one:

      8 - Why the hell are you passing in *pointers*? Is your broken-ass processCommandLineArguments() actually going to screw with them?

      --

      Do daemons dream of electric sleep()?
    19. Re:Write clear code, remove comments by MrSenile · · Score: 1

      *grin*

      Actually, #7 covered that since it would be considered global to the calling function ;)

    20. Re:Write clear code, remove comments by Anonymous Coward · · Score: 0

      Completely disagree with your "comments are an admission of defeat" idea.

      It doesn't matter how clean and buzzword compliant your code is. There are situations that require comments.

      The first example that springs into mind is a legacy system that was designed to use normal command line options, BUT if only a single filename was provided (no -f, just legacyProgram filenamepath , the argument was treated as a filename. The behavior was deeply embedded in the 10 year-old system -- hundreds of scripts called out to these programs without the -f. Comments are required to tell the hot-shot programmers that removing the feature may make them feel better, but will break the hell out of the system.

      And anytime you're playing the Legacy System Support game, the phrase, "But it shouldn't ..." gets you automatically thrown off the show.

    21. Re:Write clear code, remove comments by Anonymous Coward · · Score: 0

      I agree somewhat with your point - a lot of comments I used to write were redundant, since the code itself explained reasonably well what is going on.

      But I've also been in arguments with hard-line people who argue that good coders write no comments at all (no exceptions), because - in their opinion - good code always explains itself. Which of course only really works when you have a perfect compiler that has no bugs or weird things, a perfectly designed programming language, use only well-designed APIs and implementations of them without bugs, and are perfect yourself.. which will never actually happen.

    22. Re:Write clear code, remove comments by periodic · · Score: 2

      1. I guess it should be obvious why command lines needs to be processed. If there is some special processing then a comment is needed, it the function does what it says, I see no need for comments.

      2. This is hopefully documented so even a user can read it. "--help" is a common way of doing this. Then this information can be found in the function itself or by running the program.

      3. Should be easy do find from the function interface and how it is used in the code. Also reading the code of the function will help out a lot.

      4. Stated in the code of the function.

      5. Stated in the code of the function.

      6. Combine answer 2 and 4

      7. Hopefully no, but yes if it does it needs documentation.

      8. Normal in C (Hopefully no modification of the arguments is done, if modifications are done: Comment!) In C++ this would be documented in the function interface f(const type& foo) or f(type& foo). First case tells me no modification is done second that I should expect the value to be modified, in the first case your compiler will check that your design rule of not modifying the argument is followed. Writing the same in a comment will sooner or later be broken and the comment being wrong can cause more headache then trying to understand code.

      However documentation about architecture giving an overview of the application and explanations as to why and what each module do is important.

      My rule of thumb is if functions do what you think they do no comments are really needed. Comment unexpected behavior or portions of code that are complicated (hopefully for a good reason)

      Now if you would write an API where you don't expect programmer to have access to the source code. Documentation and not comments (they can be the same thing but not always the case) is needed.

      In my opinion comments that are wrong is more detrimental then no comments.

    23. Re:Write clear code, remove comments by Anonymous Coward · · Score: 0

      And that's why they invented the keyword "const". For example, the basic rule I follow is that if a parameter is marked const, it will not be modified. If it is unmarked, it may be modified. I does not matter whether you use pointers or references. Even when passing variables by value (say, an integer) I'd still mark it as const. This logically does nothing, however it does give more optimization flexibility to the compiler.

      Long story short:

      void processCommandLineArguments(const int * argc, const char ** argv); // does not "screw" with parameters
      void processCommandLineArguments(int * argc, char ** argv); // may "screw" with parameters
      void processCommandLineArguments(const int & argc, const char * & argv); // does not "screw" with parameters
      void processCommandLineArguments(int & argc, char * & argv); // may "screw" with parameters

      On a related note, this is why I hate library code that randomly places const on some function parameters and leave them absent on others *glares at the win32 API*. Library code should ALWAYS take parameters as constants unless the goal is to actually return something via those parameters. Hacks such as not applying const just so you can screw with user-supplied memory to save yourself some stack space is downright stupid.

    24. Re:Write clear code, remove comments by Anonymous Coward · · Score: 0

      While that holds true for simple operations, I find that as soon as complicated algorithms are required, separating things out like that causes more problems than it solves. Every one of those sub-methods needs access to most of the data the parent methods is working on. Do we put that into the instance or static members of the class containing the method? Do we pass them to every method? That makes a mess. Do we make the algorithm into a class itself for better encapsulation, even if that makes little sense semantically? What about all those function calls in loops that wreak havoc on performance?

    25. Re:Write clear code, remove comments by nschubach · · Score: 1

      You don't write comments to let people know that you're looping over an array, you write comments to let people know WHY you're looping over an array and why they should care.

      getItemsWithValueOver(array, minValue) { for(...

      There's your why. As far as if they should care? I don't know if there's any reason I can make anyone care, but I'm guessing they should care because you use the value(s) later.

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
    26. Re:Write clear code, remove comments by serviscope_minor · · Score: 1

      Linus Torvalds has an interesting comment regarding your style of programming: plain-old C can make a lot of sense precisely because abstractions wind up being implemented with relatively verbose code.

      Linus torvalds has a lot of rather strange ideas about how C compares to other languages, because he suffers from acute C hacker syndrome.

      It's the C code that's most likely to be readable by other maintainers, even if it takes more lines and typing to do what it does.

      Not even slightly. Or, in other words, I completely disagree. Good libraries make the *meaning* of the code clearer because they hide the implemntation details.

      Consider, for instance the following example (in pseudo C++):

      Vector v;
      Matrix M; //Stuff happens here

      Matrix M_next = (Identity - 2*outer_product(v, v)) * M;

      In C++, it's blindingly clear to anyone versed in the right topic that M_next is M reflected by a Householder transformation. This kind of thing crops up a lot and would be very obvious to anyone who has any bisiness messing with the function. It requires no comment either.

      Imagine the same type of code in C.

      You'd have a few lines of code, which would have to be commented, or stick those few lines of code. There is no way it will be more readable.

      The thing is in C you have to implement everything in tiny little steps, because it lacks abstractions. When commenting, you should say what anything bigger than a tiny little step is supposed to be doing, otherwise it's not obvious, or some poor sap has to obsess over every single for-loop to figure out what its purpose is.

      The purpose of all those abstractions means that the code is closer to reflecting the meaning of what you intend to do.

      #

      --
      SJW n. One who posts facts.
    27. Re:Write clear code, remove comments by Anonymous Coward · · Score: 0

      1. With something that reflects the intention:

                          configureDatabaseConnectionFromCommandLineArguments(argc, argv)
            or:
                          DatabaseConfiguration config = new DatabaseConfiguration(argc, argv)

          I think names like processSomething are too generic, they don't explain what kind of "processing" will be done.

      2+6. Could be explained reading the called code (using more code!).

      3+4. Looking at the signature of the called method and naming the exception classes appropriately (with intention revealing as Kent Beck explains in his books):

            public DatabaseConfiguration(String[] args) throws TooManyArgumentsException, InvalidArgumentException, ...

      7. Shouldn't be done. Avoid global variables and/or singletons! :-p

    28. Re:Write clear code, remove comments by Anonymous Coward · · Score: 0

      You, sir, deserve all the mod points in the world. I've seen mostly ridiculous anti-comment posts here today, but your breath of fresh air sanity, logic and obvious experience in the world of software development is a thing of beauty. You get it, sir, but sadly you are in the minority, a point this thread proves in spades.

      I can always tell a fellow professional when I see one from the obvious "fake" developers who shouldn't be working in this industry. We recognize one another easy enough, and you clearly are in that fellow professional category. Kudos, sir!

    29. Re:Write clear code, remove comments by Dixie_Flatline · · Score: 1

      It's true, if I wrote nothing but simple array iterators all day, I would probably not need any comments at all.

      Unfortunately, the code I write has a significant amount of complexity. Worse, I have to write code that integrates with code that is arcane and complex itself. Years and years of use have made the codebase I work with difficult to cope with without occasionally doing something more clever than trying to get the values in an array bigger than a minimum argument.

    30. Re:Write clear code, remove comments by Anonymous Coward · · Score: 0

      Comments are missing in the above post. Please provide a summary of the intent so we can verify all the words are functioning as intended.

    31. Re:Write clear code, remove comments by Anonymous Coward · · Score: 0

      > [...] but the fact is you can't hold more than 7 lines in your head anyway.

      Hahahahahahahahahahahahahahahahahahahahahahahaha. Speak for yourself.

    32. Re:Write clear code, remove comments by kumanopuusan · · Score: 1

      That seems like it would work if you call each function exactly once.

      --
      Use of the words "good", "bad" or "evil" is almost invariably the result of oversimplification.
    33. Re:Write clear code, remove comments by Anonymous Coward · · Score: 0

      Every single one of your 7 questions can be answered in the form of a comment at the start of the function processComandLineArguments explaining what it does.
      Or are you going to add that block of text everywhere you call ?
      Question 5 is ambiguous by the way. Do you mean how many command line arguments, or how many function arguments?

    34. Re:Write clear code, remove comments by angel'o'sphere · · Score: 1


      Now how about the other questions.
      1. why does it need to process the command line arguments.

      Because the programm/command is started from the command line or via a start script.
      In the first case the man page explains the command and the why, in the second case the help files for the application explain the arguments.


      2. what are the command line arguments that you are passing in.

      Judging from your parents coding style, this is explained in a function called "usage()" which is called in the function processCommandLineArguments(), and the if's when to call usage() should be 'obvious'.


      3. what is the error control of that function if given improper values.

      That is shown at the top of each of those called functions: if (notExpected(arg)) raiseError(x);
      And is not needed to be documented in processCommandLineArguments(). If at all, you document it in usage().


      4. what is the error control of that function if given too many values.
      As above.


      5. how many arguments total can it handle.
      As above.


      6. what is the syntax it expects for the arguments
      As above.

      7. are there any global variables being defined or redefined in that function.
      Hopefully not ;D because that would be really bad design.

      So, for some reason you want the whole program documentation attached to that single function "processCommandLineArguments()" ... how reasonable is that?

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    35. Re:Write clear code, remove comments by multipartmixed · · Score: 1

      8. Normal in C (Hopefully no modification of the arguments is done, if modifications are done: Comment!)

      Honestly, I'd slap your hand in a code review for that; if you're not modifying arguments of type int or type pointer, passing them as pointers is a) unclear and b) produces poor code on average.

      --

      Do daemons dream of electric sleep()?
    36. Re:Write clear code, remove comments by periodic · · Score: 1

      Honestly, I'd slap you right back for stating such an obvious lack of understanding of C.
      Naturally a function modifying the contents would have arguments like (int* arg) and non modifying (const int* arg) or to be real safe (const int* const arg)

      as for the specifics
      a) no its not.
      b) no it doesn't. Passing larger data structures by value is bad performance vise.

      Now this goes for C. For C++ I could somewhat agree with you since I can use call by reference.

  19. It depends on the comments by betterunixthanunix · · Score: 4, Interesting

    "This does not work"

    "What the f*** is this doing?"

    "TODO: fix"

    All of the above are useless comments, yet they seem to sneak into everything. Worse still are comments that are meaningless to anyone who did not write them, or comments that make reference to undocumented conversations (e.g. "This is the implementation we spoke about on Tuesday").

    Don't waste time writing useless comments. If you do not have time to fix a function, the comment should explain what needs fixing so that someone else can do it without first spending half a day debugging.

    --
    Palm trees and 8
    1. Re:It depends on the comments by Anonymous Coward · · Score: 0

      I've seen this before. I really think it's accidental, though. You put those comments in your local files while you're trying to figure stuff out or working on a fix, get sidetracked, and absentmindedly commit them to the main repository. Then nobody else knows why they are there, and leaves them in. I've seen '#FIXME' lines in code that didn't seem to have anything wrong. Looking through the history, you can SEE the fix going in and the comment being left behind.

    2. Re:It depends on the comments by VortexCortex · · Score: 1

      All of the above are useless comments,

      Incorrect. When I write: //TODO: fix I usually include a little bit about what needs fixing, however, even the simple comment allows my code editor to build a "To Do" list automagically that includes the context (file, function, line number, method signature, etc). So, when I write merely: //TODO I get:

      To Do: r-engine.cpp : ParticleSystem.EnsureCapacity( ne_uint32 capacity ) : 445 [visit]

      Within the To Do List I can hover or [context-key] the class, or method name to get the doc comments for them to give me even more context, or visit that line with a single click. That's far from useless. If I include a bit of text like:
      //TODO: Conditionally recycle near death particles if over system limit.
      then that's just icing on the cake.

    3. Re:It depends on the comments by betterunixthanunix · · Score: 1

      When I write: //TODO: fix I usually include a little bit about what needs fixing

      Which in my opinion is the right thing.

      even the simple comment allows my code editor to build a "To Do" list automagically that includes the context (file, function, line number, method signature, etc).

      Sure, but it does not tell you what needs fixing; that comment alone does not even tell you why the code needs fixing. You might have to spend an hour running tests or debugging to even figure out why the comment is here. Maybe the function returns the wrong value for one in a hundred test cases. Maybe you never run a test that breaks the function. Maybe the function works fine on 64 bit systems, but breaks on 32 bit systems, and your workstation is 64 bit.

      A comment like that is no different from having your grandma say, "my computer is broken." Does that mean it won't boot up? It won't connect to the Internet? Is it a plugin? Is it plugged in? Did your 5 year old cousin spill soda on it? We can forgive our not-so-technical friends and family for leaving out context or being unable to articulate what is actually wrong; but surely a programmer can be expected to be able to explain why something needs to be fixed.

      //TODO: Conditionally recycle near death particles if over system limit.

      My research group will hate you, because this is going to be inserted somewhere in my code ;)

      --
      Palm trees and 8
  20. Don't mind me by Sez+Zero · · Score: 5, Funny

    I'm just here for the Comments on Comments on Code Comments.

    1. Re:Don't mind me by Anonymous Coward · · Score: 0

      I appreciate your Comments on Comments on Comments on Code Comments.

    2. Re:Don't mind me by Anonymous Coward · · Score: 1

      Yo dawg, I heard you liked comments on comments on code comments so I put a comment on comments on comments on code comments on your comment on comments on comments on code comments so you can comment on comments on comments on comments on code comments when you read the comments on comments on comments on code comments.

    3. Re:Don't mind me by Anonymous Coward · · Score: 0

      // NO COMMENT

    4. Re:Don't mind me by Anonymous Coward · · Score: 0

      This is me adding a Comment to your Comment on Comments on Comments on Code Comments

    5. Re:Don't mind me by Anonymous Coward · · Score: 0

      Sounds like excessively geeky porn to me.

      Now time for some Comments on Comments action.

    6. Re:Don't mind me by Anonymous Coward · · Score: 0

      came for this comment, leaving happy

  21. Collapse the code, not the comments by Tim+Ward · · Score: 2

    Then you can read what the code is supposed to do and understand how it is supposed to work.

    Next, you uncollapse the comments, see what the code actually does, and fix it.

    1. Re:Collapse the code, not the comments by Tim+Ward · · Score: 1

      Uncollapse the *code*, I meant, of course.

    2. Re:Collapse the code, not the comments by nschubach · · Score: 1

      And if the comment is wrong?

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
  22. Wishlist by gaelfx · · Score: 1

    Ok, it's not a list per se, but what I would like to see is an editor that automagically makes the comments on any given lines a tooltip when you mouse over that line. To me, it seems the most intuitive and unobtrusive way to deal with comments, but maybe I'm wrong.

    1. Re:Wishlist by VortexCortex · · Score: 1

      I would like to see is an editor that automagically makes the comments on any given lines a tooltip when you mouse over that line.

      I make editors, but I'm not sure what your feature suggestion is. Do you mean something like this?

      Or perhaps your wish has already been granted via collapsible code & comments? If not, please clarify.

    2. Re:Wishlist by gaelfx · · Score: 1

      That first one is pretty much what I was talking about! Available for Linux?

  23. Comments are usually as good as the code by ccguy · · Score: 2

    In my experience, comments are usually as clever as the writer, and as good as his code. When it's my code and my comments by the way the quality of the comments seems to diminishes as the code ages, even with the file timestamp not changing.

    Anyway I remember discussing comments vs self-explaining code with a coworker. Eventually we ended discussing magic numbers (usually they warrant SOME explanation), he just told me he used #defines which made thing a lot more clearer. After the coffee, I checked some of his code:

    // Validación de cuenta bancaria
    #define ONCE 11
    #define DOCE 12

    (In Spain bank accounts have a simple check embedded so you can easily verify is a bank account number is incorrect, and the algorithm requires to validate the results of the calculation with the values in positions 11 and 12).

    1. Re:Comments are usually as good as the code by Anonymous Coward · · Score: 0

      For anyone who doesn't speak any Spanish, once and doce are Spanish for eleven and twelve, respectively.

  24. Ignoring the comments is the wise thing to do. by 140Mandak262Jamuna · · Score: 2
    Djikstra said, "Always debug the code, not the comments". No one updates the comments. Including me. The number of hours I have wasted in debugging code because I trusted the comment written in the function or the algorithm is countless.

    When I was in grad school my thesis guru believed in a tool called fweave and ftangle. You write code in a c like syntax, along with comments that are regular TeX or LaTeX files. Then send the code through fweave and you get a regular TeX formatted document that can be viewed in ghostscript or printed postscript. Send the code through ftangle, you get a valid FORTRAN code that can be compiled and run.

    It worked for him because he keeps getting a stream of grad students and the code project has to be perfectly documented for the next student to continue the work. But in companies where technical specialists can occupy a position for many many years along with constant pressure to add features, the first thing that get dropped is code documentation.

    For example I have been shipping my product for 16 years now. So many of the functions I write are fleeting and have low half-life. They often start out as a debug function to help me understand some issue, which might not even get checked in. But a few get checked in, first invoked in debug builds alone, then in release builds under env flags, then slowly they morph into sanity check function or an audit method, then a verification procedure, then eventually a special case detector for some feature. When it was first written it does not appear to be worth commenting well. By the time it is part of the feature, it is considered too late to spend resources to comment it.

    --
    sed -e 's/Chuck Norris/Rajnikant/g' joke > fact
    1. Re:Ignoring the comments is the wise thing to do. by Anonymous Coward · · Score: 0

      No one updates the comments. Including me. The number of hours I have wasted in debugging code because I trusted the comment written in the function or the algorithm is countless.

      Maybe if you'd kept your comments up to date then you wouldn't have to worry about your comments not being up to date? Or in other words, don't do a shitty job and then you won't have to worry about whether or not you did a shitty job.

    2. Re:Ignoring the comments is the wise thing to do. by Anonymous Coward · · Score: 0

      > The number of hours I have wasted in debugging code because I trusted the comment written in the function or the algorithm is countless.

      Yeah. There's one thing worse than having no comments in the code: comments that lie.

    3. Re:Ignoring the comments is the wise thing to do. by heson · · Score: 1

      Unit tests are good comments (and they are checked to be up to date with the implemenetation every compile)
      Which pattern/algo is used is good comment
      Implementation decisions are good comments (I.e "foo algo is better for this dataset than bar and baz algos")
      For all else, literal programming is good comment, all other comments are to be regarded as disinformation unless proven otherwise.

    4. Re:Ignoring the comments is the wise thing to do. by serviscope_minor · · Score: 1

      It worked for him because he keeps getting a stream of grad students and the code project has to be perfectly documented for the next student to continue the work. But in companies where technical specialists can occupy a position for many many years along with constant pressure to add features, the first thing that get dropped is code documentation.

      That seems to be a great argument for it. You have complex code and high turnover and the resulting code is usable by the next guy because of the excellent comments.

      --
      SJW n. One who posts facts.
    5. Re:Ignoring the comments is the wise thing to do. by VortexCortex · · Score: 1

      Djikstra said, "Always debug the code, not the comments".

      Meh, that's just a subclass of GIGO: "Garbage In, Garbage Out". If you can't rely on the function's comments then the next programmer who comes along to port the code to another language or platform may get things wrong. I write unit tests based on the comments, not the code; Otherwise how can I be sure the function is working as the programmer intended it to work? How about: No comments are better than bad comments.

      I always update my code's comments; They are part of the code to me. When I change the code in a block, function or class my editor flags the related comments (and thus documentation) with a /// @REVIEW meta tag. The job isn't done until the documentation has been reviewed (which is a subclass of, "No job is finished until the paper work is done").

      I get that deadlines cause problems, they always do. If documentation isn't in the budget then you're doing it wrong...
      "I love deadlines. I like the whooshing sound they make as they fly by."
      - Douglass Adams

    6. Re:Ignoring the comments is the wise thing to do. by Anonymous Coward · · Score: 0

      Djikstra said,

      Dijkstra, not Djikstra. This seems to happen a lot, English speakers apparently find ji easier to handle than ij. You will have trouble pronouncing ij, but Dike-stra is close enough. Dijk == dike.

      No one updates the comments. Including me. The number of hours I have wasted in debugging code because I trusted the comment written in the function or the algorithm is countless.

      I often found outdated comments helpful, they still gave me information about the intention of a function, even if the details were wrong, which I usually spot soon enough. I've never been very good at extracting a big picture from an abundance of details, I seem to have a top-down kind of mind, so any indication of what this big picture might be is helpful, even if the description is outdated. And while I forget to update comments myself often enough, I do correct mistakes when I see them.

  25. My comments... by dosius · · Score: 1

    I have a tendency to be terse with comments, but say enough to make it clear, if I don't feel the code does. Sometimes though, I add in a joke or pun (like, in AIRC, I have a comment "play the server game of ping-pong").

    -uso.

    --
    What you hear in the ear, preach from the rooftop Matthew 10.27b
  26. No comments == Job security by S_Stout · · Score: 2

    Some people like to ensure that operations would be hindered should they be fired.

    1. Re:No comments == Job security by Anonymous Coward · · Score: 0

      They should of course be fired as soon as found to minimize damage.

  27. Comments should be why not how by Anonymous Coward · · Score: 1

    Code comments should only be used to explain why you are doing something not what you are doing, The what should be self explanatory by good coding/variable naming. A comment should not say " loop through all the variables adding 1 to each" it should be more like "Need to shuffle the nodes down by one in order to make room for a new one at the top". When reading the code I can get all the information provided in comment one from the code, however I may be left guessing or baffled as to why they just did that. Where is comment two lets me know exactly what the author was intending and I can see if the code is doing what they wanted or if there is a better way.

  28. It's Another Way To Tell What They Were Thinking by Greyfox · · Score: 2
    Programming languages are as much about communication with other programmers as they are about communication with the machine. At some point someone else is going to have to do something with your code, no matter how well written it is. Over the course of my career I've run across countless pieces of code where I've wondered "What the hell was this guy thinking?!" A well placed comment might tell me, if they'd bothered to put one in. Sometimes that construct actually has to be awkward due to the previous design of the code, and changing it will cause breakage or a side effect somewhere else. Most of the time they just weren't putting a lot of thought into the design of that section of code (Or more often, their entire application.) In a handful of cases they had just discovered some feature and had become enamored of it (Like pointers to functions, or ? : branching.)

    Subtle clues tell me how much code I'm probably going to have to fix in the maintenance of an application. Comments could tell me if the programmer considered a section of code to be temporary with replacement needed, or if the function I'm looking at is a crucial part of the application. One of the best projects I've ever worked on had the requirements that had driven each function at the front of the function. That made it very easy to focus design and refactoring efforts where they were really needed.

    I recently inherited a ten-year-old heap of perl code, on top of which someone had piled a ruby wrapper. There's a lot of functionality that's duplicated between the modules of both languages, and refactoring it all is going to be a nightmare. The code could be in a transitional state where the design is not where I want it for easily a couple of years. I've liberally sprinkled it with todos and comments where I'm putting new code, so the next poor sucker who gets this thing maybe doesn't have to start completely from scratch.

    --

    I'm trying to teach myself to set people on fire with my mind... Is it hot in here?

  29. I don't write comments. by larry+bagina · · Score: 1

    Because I don't write code. I do neither. But both. Confused? I use literate programming -- your code is you commentary. They can't get out of sync. And, as a bonus, rubber ducky debugging is built in.

    If it's good enough for Donald Erwin Knuth, it's good enough for me.

    --
    Do you even lift?

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

  30. Comment lightly and relevantly by Terry+Pearson · · Score: 2
    I guess that when I code, I just make sure that my comments are necessary.

    For example, Eclipse gives a nice preview of methods and pulls in the javadoc into the tooltip when hovering over the comment. Therefore, I try to keep these up to date.

    On the other hand, comments that just say the method name, or cannot be expected to be maintained, should not be created.

    On the point of good code, yes you can write good code and reduce the need for comments, but there are just times when a comment is necessary. For example, there may be code for something that programmers (or humans in general) are not intuitively familiar with. Industry specific items in science, financials, etc. would qualify. If you ever expect a new person to come on and modify your code, you need to make sure they can jump in quickly. A quick comment as to what an industry specific item is, can go a long way to reducing the learning curve and allowing the contractor/new employee/etc to focus on what they are good at (coding).

  31. Incorrect comments by QuietLagoon · · Score: 1

    I have never worked on a program where I did not find comments that were flat out wrong, causing me to (1) waste time discovering the comments were wrong, and then (2) trying to figure out what the program was really doing. As a result, I have become a fan of minimalist comments and better quality coding.

  32. Seeing the forest for the trees by QilessQi · · Score: 1

    To ensure that important information springs to the foreground, comments should exist primarily to document something which is not obvious from the code itself: requirements justifying the code, rationale for a particular approach, explanation of complex logic, and the occasional TODOs and FIXMEs.

    For example, a method on Person called setName() does not need a comment "This sets the name of the person."

    Additionally, there is no need to pepper "// end if" and "// end while" and "// end method" comments all over the code on every right curly-brace. IDEs that automatically comment are pure evil.

    1. Re:Seeing the forest for the trees by Anonymous Coward · · Score: 0

      [...]

      Additionally, there is no need to pepper "// end if" and "// end while" and "// end method" comments all over the code on every right curly-brace. IDEs that automatically comment are pure evil.

      This is a pet peeve of mine. If the beginning of the compound statement or method is so far away that you need a comment to explain the right brace, it needs refactoring.

  33. Comments are useless, learn to read code by TheSkepticalOptimist · · Score: 1

    The problem with comments is that the code is Dynamic, the comments are Static.

    Someone can write code and write beautiful, fully descriptive comments, which are valid for about one iteration of the project. Then the same or other developers will come along and change code to match new expectation and functional requirements, and NOBODY ever updates the comments after the fact.

    Also, comments can be pretty useless. I tire of seeing comments and summaries on classes which basically paraphrase the name of the method or function call like: /// This method returns true when a connection is established
    void bool IsConnectionEstablished() {...}

    I mean the above summary is a waste of everybody' time and not worth the bytes it consumes in the source code.

    Code should be self evident and any software developer worth their salt should be capable of being able to follow a logic path through the software given it was written with any amount of competence.

    The problem today is there are TOO MANY wannabe software developers that see code development as a way to make a quick easy buck but lack the fundamental skill levels to be a talented software developer. This is why there exists Agile process and software patterns, unit testing and gobs of "value added" frameworks, etc. It's because you can no longer have teams of talented software developers working on a project, you have a bunch of code monkeys that punch in code. Therefore you required external influence to ensure a project comes together efficiently and is maintainable in the long run.

    The problem is when these code monkeys are told they must document their code is when the whole system breaks down. Poorly written comments, wrong information, rapidly changing feature requirements that do not match code commentary.

    I abhor ANY system or process that adds overhead to the software development process. Unit testing fails because if your code changes, you must change your unit tests. CODE IS NEVER STATIC. Google touches 60% of their entire codebase every 6 months because they are constantly optimizing and improving it. I have NEVER seen a system where code is written once and then becomes a static reusable module. The problem is that MOST teams using Unit Testing end up turning off the unit tests after some period of time because they become unsustainable, whatever motivation brought unit testing into the team environment is lost when deadlines are exceeded. Few managers realize that Unit Testing adds 20 - 30% or more overhead to software but plan development as if Unit Testing takes no effort. The software changes, but nobody wants to invest the time to ensure unit testing is updated to match the new requirements of the system.

    Same with code comments. A team might become motivated to add commentary to a project, all developers diligently add comments and summaries, and then when deadlines approach that is all thrown out the window because nobody will ever maintain comments AFTER they are written.

    Don't get me wrong. There are cases when a quick comment prior to a block of code can mean the difference between wasting an hour of intense forensic code analysis. I use comments whenever the code does something slightly unexpected or purpose not easily understood. Its a hint rather then a full blown documentation of the feature, but in general globing up comments into code is one of the most useless waste of times and potentially damaging initiatives a code team could ever embark on.

    I would love a system that can be self-testing and self-documenting. Microsoft is working on a solution called "code contracts" which allows you to define the requirements of a functional block in code, which will then ensure the safe usage of the block with the code entering and exiting the solution. Because code contracts ARE CODE, any changes to the requirement of the code requires changes to the code contracts that are tightly coupled to that functional block. Because you describe the purpose of the

    --
    I haven't thought of anything clever to put here, but then again most of you haven't either.
    1. Re:Comments are useless, learn to read code by Dixie_Flatline · · Score: 1

      If your comments add a 'significant' overhead to your coding, you're doing them wrong.

      If your codes are 'static' while your code is 'dynamic', you're doing them wrong.

      Code isn't finished until the system is clear. If the comment needs to change because the code changed, then change the comment. If the code change is SO convoluted as to change the entire comment, so much more the reason to change the comment. If the code has changed to be more optimal, but performs the same essential function, then the comment doesn't need to change.

      I really don't see the problem.

    2. Re:Comments are useless, learn to read code by Anonymous Coward · · Score: 1

      > I really don't see the problem.

      Comments and code that express the same idea violate the rule 'Do Not Repeat Yourself' in a particularly unpleasant way, where one of the repetitions is useless and therefore practically guaranteed to get out of sync.

    3. Re:Comments are useless, learn to read code by Dixie_Flatline · · Score: 1

      I didn't say they expressed the same thing, merely that code that is dynamic needs comments that are dynamic. Code that changes sufficiently to invalidate the comments means that you rewrite the comments. Code that does not change sufficiently to warrant such a change means you leave the comments alone. Again, there's no issue here.

    4. Re:Comments are useless, learn to read code by Karlt1 · · Score: 1

      " Unit testing fails because if your code changes, you must change your unit tests"

      No, if your code changes, and the unit tests fail, and the requirements that the unit tests were designed to test fail. That means your code changed something inadvertently -- the whole point of unit tests.

      "Because code contracts ARE CODE, any changes to the requirement of the code requires changes to the code contracts that are tightly coupled to that functional block. Because you describe the purpose of the function in code, you can easily create a system to generate DYNAMIC documentation about the code by updating the rules and requirements of the software in real-time."

      You just described unit tests.....

  34. Most comments are useless by prefec2 · · Score: 1

    Many programmers do documenting as a last step, which leads to comments explaining what the code does. However, I do not need a comment explaining waht the code does. That's the code for. I need comments explaining why the code exists. The purpose must be documented. On a higher level I need documentation explaining why the problem X has been solved with solution Y and which other solutions have been considered, but not used.

    When I have a class JvmTypeParameter and there is no documentation about the used vocabulary, I do not know what the purpose of a parameter is for a type. Jvm tells me, it is for Java of the Java virtual machine. I do know what a type is, however I do not know what the developer thought when he used that name. Therefore I do not know what a type is in this context and what he or she thought could be a parameter of a type.

    The answer is, a JvmTypeParameter is a reference to another type or set of types used in Java generics. For example List the String is such a type parameter in the above example. To understand what it is, you need a lot of context knowledge and that is normally missing from code comments and in most cases also from the documentation.

    1. Re:Most comments are useless by Anonymous Coward · · Score: 0

      which leads to comments explaining what the code does.

      ...Which is the wrong way to comment. Comments shouldn't tell you what the code does. They should explain why it works that way.

  35. External worknotes? Not convinced... by rklrkl · · Score: 1

    I'm not convinced about external worknotes at all, because they're probably stored completely separately from the code itself. What's wrong with saying "Further details in the'"Main Menu design' section of README.txt in this directory" in a comment if you don't want to include a large swathe of comments in a source file?

    If worknotes.scripting.com goes down for any period of time or goes bust, then this guy's links to external worknotes aren't going to look too clever. Never mind that the example he did use has just 5 bullet points that could easily have gone into a comment surely?

    I suspect one of the few useful things an editor or IDE could warn you about is if you've gone more than a screenful of code (or perhaps let the warning level be set in terms of lines of code) without a comment, though no doubt some programmers would turn this feature off anyway :-)

    1. Re:External worknotes? Not convinced... by ledow · · Score: 1

      And if they couldn't turn it off, they'd just concatenate all their lines.

      More importantly, I'd infinitely prefer a version that warned if there was a screen full of comment and no code.

      If you need that much comment, it's too important to hope that the guy maintaining the code keeps it up to date and everyone who uses that part of it reads and understands the comment. It should be explained elsewhere and a big red notice "DO NOT TOUCH WITHOUT READING X" should be put on the code itself.

  36. Documentation by ledow · · Score: 1

    Documentation external to the code is pointless and worthless. It gets out of date, glosses over implementation details, doesn't directly reference code (only by function, normally, and functions can be HUGE) and doesn't state much that couldn't be found through introspection.

    Documentation in comments has the opposite problem. It describes ONLY the implementation details, stays (pretty much, if you're good) up-to-date, stays with the function/method/class/objects being described, and states only things that you *CAN'T* see with just a brief look at the code.

    And, in the end, the code is the master of what ACTUALLY happens.

    So it's not really an easily solvable problem by some editor paradigm. External documentation solves different problems to in-code commenting, and are usually even written by different kinds of people, and neither of which tell you what's ACTUALLY going to happen.

    If documentation was just-that-easy to fix, we'd have done it already. But it's more a political, professional, and personal problem than it is anything some magic "system" can fix.

    And, to a trained programmer, hundreds of lines of comments are pretty much treated as whitespace whether they have collapsible trees of source or not. That's why we colour them that way, so they don't get in the way of real work. And also, we need them out of the way and have learned to ignore that colour when we're coding and ignore the code when we're commenting.

    They are two separate entities, and you have to "context-switch" to comment or to code (usual procedure is code until it works, then comment it). And other documentation is entirely separate and a totally different ball-game.

  37. I like "executable comments" by hey · · Score: 1

    Java's @Override is great. I says something that might be a comment in C++. But its checked at compile time too.
    Java's JavaDoc is good to.... its parsed by the IDE so when you latter hover on a function you see its javadoc.
    Adding Java's final or C++'s const on variables is another good "executable" comment.

  38. Pool analogy by Kjella · · Score: 1

    A well commented code base is like a pool full of clean water. Poor/absent/misleading commented code is like piss. The value of having a pool rapidly deteriorates if someone's pissing in it, even if by volume there's far more water than piss. The only way you're going to keep the pool clean is if you have chemicals in the water that immediately lets you know if someone is pissing and can evict them, that is to say code review. But if you already have a pool of piss, writing good comments is like pouring a liter of water into it - it's still a pool of piss. The only thing you can do is empty the pool and start over and try to do better next time. So I'm more it depends on the state of the code - if it has good comments, write good comments. If it is salvageable, salvage it. If it is a lost cause, don't waste any time trying to band-aid it.

    --
    Live today, because you never know what tomorrow brings
  39. Bitrot by flyingfsck · · Score: 2, Insightful

    Comments suffer from incurable bitrot. So when I need to understand code, I never bother reading the comments, since it is usually more confusing than the code.

    --
    Excuse me, but please get off my Pennisetum Clandestinum, eh!
    1. Re:Bitrot by Jeremi · · Score: 2

      Comments suffer from incurable bitrot.

      It's curable -- all it takes is making sure that any time the code is changed, the associated comments are updated to match.

      Of course, making sure that programmers actually do that is easier said than done, but the way to maximize the likelihood of that happening is to make sure the comments are as close to the code as possible -- preferably on the same line, or right above/below it. Comments that are off-screen (or worse, in a different file) when the code is modified are very unlikely to be updated in a timely manner.

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    2. Re:Bitrot by nschubach · · Score: 2

      It also relies on the coder trusting that the comment is accurate. Are you writing a program to do a specific task or writing comments to do that task? I put more faith in the code (because that's what the compiler runs) over the comment. If the comment says one thing and the code does something else, I'm willing to bet the code is more accurate. If I rewrite the code to match the comment, I may have just re-introduced an old bug. Now I have to go back through the file history to figure out if this was changed and/or if the original author was a poor commenter.

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
    3. Re:Bitrot by Jeremi · · Score: 1

      Ideally you'd understand the program's purpose well enough to tell whether the code or the comment is wrong, and/or you'd be able to contact the author of the code (and/or comment) and go over it with them.

      Of course that's the ideal case and not always possible in real life, in which case there is no alternative but to grovel over the code until you understand what it does, and if you then decide to make any changes, you have to test the code (both pre-change and post-change versions) to make sure that the behavior has improved and no bugs were introduced.

      Anything less than that is risky behavior.

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    4. Re:Bitrot by famebait · · Score: 1

      -- all it takes is keeping two lengthy sets of logic rules with highly complex behavior and formulated in different laguages in perfect sync at all times

      There, I fixed it for you.

      --
      sudo ergo sum
  40. Self documenting code definition (mine) by Rastl · · Score: 1

    My definition of self documenting code is code I've documented myself. Yes, there's things that are horribly obvious and don't need documentation. Then there's the other 95% of what's in the file. If nothing else saying the function of the next section of code and dependencies can really help when I have to go into it 6 months after it was written and change something.

    I also use headers to document changes but that's a slightly different topic. At least a general idea of the changes (with defect number) is available for the next person so they can keep track of who did what, when they did it and why. There's some terrible changes that were made but were necessary due to whatever reason was in the defect.

    Descriptive variable names (within reason) and decent whitespace also go a long way to making the code more easily understood.

    If the next person doesn't want to read the comments then that's their decision. I put them in as part of how I code.

  41. TFA sucks by Sloppy · · Score: 3, Funny

    As soon as I saw that the guy wrote "UX" I knew I was probably dealing with an exceptional moron (how that one acronym has turned into such a reliable red flag, I don't know, but look around and try to tell me it isn't true), but I still had no idea just how badly the article would go. It's not even stupid. It's just .. nothing.

    The guy's argument is really that his text editor's preferences are/were set to something he doesn't like.

    I shit you not. His editor's preferences were something he considers to be not-quite-right, and he noticed that it wasn't working well for him, and then somehow that turned into a programming article.

    I can't even follow through on my "UX" prejudice and say "Aha! See? The guy knows nothing!" because he's taking it to the next level, so that from now on when I see "UX" it'll be "Aha, See? The guy says nothing." Although now that I think of it, maybe that's what the "UX" red flag has really always meant, all along. Hmm. Ok, you did give me something to think about.

    --
    As copyright owner of this comment, I authorize everyone to defeat any technological measure which limits access to it.
    1. Re:TFA sucks by Anonymous Coward · · Score: 0

      Thanks.
      I read your comment and almost started laughing out loud in my office.

    2. Re:TFA sucks by O-Deka-K · · Score: 1

      Modded funny, but you're absolutely right. Maybe it should be titled:

      "Coder" Doesn't Know How to Change Preferences

      Emphasis on "preferences". Yellow comments on a white background? Really? This is MORE readable?

  42. I Worked On Code Where Every Comment Was Garbage by Anonymous Coward · · Score: 0

    I worked at a (backward) company that didn't understand version control. Their solution was to litter the source code with meta-comments for version control - Thousands of them in just one file. They stayed there and accumulated forever.

    Any real comments were in Japanese, and the file format was some strange character set that many editors couldn't work with.

    There was so much bumph on the screen, you'd be lucky to see a single executable line of code at any one time. At every single point in the decision tree, these people had picked the worst possible path.

    Don't imagine the idiocy stopped there either.

  43. All comments are lies. by famebait · · Score: 4, Interesting

    That sounds harsh, and of course it doesn't fit 100% of the time, but if you look closely enough it is true a frightening part of it.

    The only thing you can trust is the code.

    When I write comments it is usually to say "this code might look like an opportunity for this or that refactoring/optimisation. Don't do it becauase..."
    Yes, ideally the code should express this directly, and commetns are an admission of defeat, but sometimes we are defeated.

    --
    sudo ergo sum
    1. Re:All comments are lies. by Anonymous Coward · · Score: 0

      This. The comments LIE! The Truth is in the code.

    2. Re:All comments are lies. by rastos1 · · Score: 3, Funny

      When I write comments it is usually to say "this code might look like an opportunity for this or that refactoring/optimisation. Don't do it becauase..."

      You mean something like this:

      //
      // Dear maintainer:
      //
      // Once you are done trying to 'optimize' this routine,
      // and have realized what a terrible mistake that was,
      // please increment the following counter as a warning
      // to the next guy:
      //
      // total_hours_wasted_here = 42
      //

      ?

    3. Re:All comments are lies. by famebait · · Score: 1

      Funny.
      But on the serious side, more like

      // This comparator is performance critical and intentionally left messy after empirical optimisation. // Do NOT change it without TESTING that sort performance does not suffer for 500K+ rows.

      or

      // Since extrudeStrands() has side effects we don't control, we can't use the Gnocci pattern here.

      --
      sudo ergo sum
  44. Seeing comments versus code by pturley · · Score: 1

    I write a lot of comments because it feels natural to me. For me, the *most* important obstacle to working with another's code (or my code that I haven't seen for a long time) is understanding the meaning behind it. With that priority, I sometimes write three times more lines of comments than lines of code.

    It surprised me when I ran into someone who thought this was "too many comments." I came to understand that, for this person, the priority was to see as much code on the screen as possible. For him, my comments were "diluting" the code and making it harder to understand. I think I saw this reflected in the summary description when it mentioned "the clarity of comment-free code."

    This was an important moment for me, in that I realized neither he nor I were "wrong," we just had different things that were important to us because we had different ways of understanding code.

  45. Literate Programming (was Re:I don't write com...) by WillAdams · · Score: 1

    ::applause::

    Some useful links for those who aren't familiar w/ it:

    http://www.literateprogramming.com/

    http://en.literateprograms.org/LiteratePrograms:Welcome

    and best of all, Crowther's Colossal Cave Adventure as a literate programming novel translated by Donald Ervin Knuth:

    http://www.literateprogramming.com/adventure.pdf

    I've found literate programming to be invaluable for coding up infrequently touched systems which need updates from time-to-time.

    William

    --
    Sphinx of black quartz, judge my vow.
  46. For those of you that claim comments are useless by Anonymous Coward · · Score: 0

    Try programming in assembly language for a year or so. Then see if you still think comments are useless.

  47. Javadoc - non-opensource by heatseeker_around · · Score: 1

    This is a valid example if you own or have access to the source code. But, in Java for example, in the case you just use an external non-opensource library, how the heck a Javadoc is useful if there are no comments at all on some important complex methods just based on the name and the parameters ? At some point, wouldn't it slow down the coding ?

  48. The problem with comments... by Anonymous Coward · · Score: 0

    The problem with comments is that they create a false sense of understanding.

    For example: /**
      * Adds two numbers together.
      */
    function addNumbers(var num1, var num2) {
            return (num1 + num2) * 2; // bugfix#8859: we need to multiply all additions by 2 for some weird reason
    }

    And so the API docs will read:

    function addNumbers(num1, num2): Adds two numbers together.

    The actual domain knowledge of what this function does is encoded in such a way as the inner meaning is lost. Some documentation tools "fix" this by including the source code so that the competent reader can spot the glaring problem here. But most BAs don't want to read code (or don't know how) and so the communication of what the function REALLY does is lost.

    1) Write code so that it is easily understandable
    2) where #1 is not possible, include a brief comment where necessary
    3) Try to refine instances of #2 into instances of #1
    4) ???
    5) profit.

    1. Re:The problem with comments... by skelly33 · · Score: 1

      By your logic, the API doc should instead simply read:

      function addNumbers(num1, num2)

      ... which has the same problem - the function name itself bears no reflection on what the code actually does. What you have described is not a problem limited to comments; it's just, plain sloppy work.

  49. As a developer.. by Anonymous Coward · · Score: 0

    "impossible tradeoff between comments and the clarity of comment-free code"

    There is no tradeof between uncommented code and commented code. Uncommented code does not add clarity.
    I like my code commented if it isn't obvous what the code is doing.

    Also, comments should help the developer, comments should not explain what I can read from the code.
    Try digging around in 1M lines of code, and you will understand when and where comments is required.
    They are required where the chain of thoughs itsn't clearly expressed by the code itself.

  50. Comments are important by Anonymous Coward · · Score: 0

    Comments aren't for you, they are for others who have to figure out what you've done. If their style and logic is different (which is almost always the case) then it will take a lot longer to figure things out without comments. This is why comments are important. It speeds up the learning curve.

  51. Nonsense by Errol+backfiring · · Score: 1

    The problem with comments is that they don't compile. The language does not complain if a comment is horribly wrong or horribly out of date. That is the problem of comments. Code folding is another problem. If you feel compelled to hide your own code, there is something horribly wrong with your coding style. And if you feel compelled to hide somebody else's code, it's broken. Fix it.

    --
    Nae king! Nae laird! Nae yurrupiean pressedent! We willna be fooled again!
  52. Example... by CFBMoo1 · · Score: 1

    FUNCTION fx_get_bar_from_foo
    (
        p_foo IN MYTABLE.MY_FIELD%TYPE
    ) RETURN MYTABLE.MY_FIELD2%TYPE
    /**
    * This sample function is only an example with comments.
    * It may be right or it may be wrong but the comments in here
    * allow me to come back years later and understand what I did.
    * Yes it's a bastardization of Java and PL/SQL. Plus people
    * at work love my code so far so I must be doing something right.
    *
    * @PARAM p_foo IN MYTABLE.MY_FIELD%TYPE my FOO field.
    *
    * @RETURN MYTABLE.MY_FIELD2%TYPE my BAR result.
    */

        -- Variables.
        v_return MYTABLE.MY_FIELD2%TYPE = NULL;

        -- Cursors.
        ...

    BEGIN
        -- Check the parameter passed in.
        IF NOT p_foo IS NULL THEN
          -- Must be good, process it.
          SELECT
        MY_FIELD2
          INTO
        v_return
          FROM
        FOOBARS
          WHERE
        MY_FIELD = p_foo;

          -- Check it against the magic cursor.
          ...

          -- Log the request.
          ...
        END IF;

        -- Return it.
        RETURN v_return;
    EXCEPTION
        WHEN OTHERS THEN
          -- This isn't good, log and return nothing.
          ...
          RETURN NULL;
    END fx_get_bar_from_foo;

    -- Use a good editor, either an IDE like eclipse or something like Notepad++, Kate, or Gedit.
    -- Easter Egg Comment: The yoke is on you!

    --
    ~~ Behold the flying cow with a rail gun! ~~
    1. Re:Example... by geekoid · · Score: 1

      Worst. Comments. Ever.

      What is it suppose to DO? What's the goal?
      great you looking through a cursor, swell. Why? why do you want o get bar from foo?

      Your code is useless if bar or foo changes,or if people are looking at reuse.
      and THIS is unforgivable:

      IF NOT p_foo IS NULL THEN
                  -- Must be good, process it.

      really? the only bad one is null? really?
      That type of coding is why bugs suddenly appear and disappear.
      So god damn bad.

      and exaggeration to make a point:
      http://xkcd.com/327/

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
  53. Re:// COMMENTS ARE FOR PUSSIES ! by Anonymous Coward · · Score: 0

    Amen, brother.

  54. A laughably false claim by Anonymous Coward · · Score: 0

    Without this ability there's an impossible tradeoff between comments and the clarity of comment-free code.

    Are you fucking kidding me?

    He can't figure out how to do it, so he falsely claims that it's "impossible"?

  55. strategy in comments, tactics in code by Speare · · Score: 1

    I wrote the following entry on perlmonks.org several years ago. http://perlmonks.org/?node_id=473080 It's nothing specific to the language, so I'll just copy verbatim here.

    One, I have a rule I teach to any programmer under my supervision: strategy in comments, tactics in code. Tactics are what you do to get something done. Strategy explains what you want done. In warfare, an officer focuses on strategy: "secure that hill!" "pick the best two devices!" "find the local minimum!" Don't mention the tools you use to get that job done, soldier, unless you're being fiendishly clever. Comments should be in natural human language, while the code should just accomplish those tasks.

    Two, I have a technique I teach to any new programmer, whether they're under my supervision or not: write the comments first. Programming courses always talk about writing pseudocode: why write it on scratch paper, just to throw it away?

    sub process_ring_packet
    {
    -# if we have a prior server registered,
    --# if this packet was received from the prior,
    ---# if this server created this packet originally,
    ----# kill the packet, it's completed the trip.
    -# scan the packet for all object references.
    -# dispatch packet to object mentioned which we control.
    -# if any object references remain unhandled,
    --# if we have a next server registered,
    ---# send the packet to the next server.
    }

    Once the pseudocode is written in human terms, then fill in your actual code in whatever computer language is being employed. Note that I didn't say HOW to do each of the tasks in the comments. I just wrote what needed to get done. Lastly, as others have indicated, the actual code should not be too clever for your teammates to understand at a glance. Use clear concise words for variable names, without abbreviating them unnecessarily. Use the idioms they're familiar with. Use the language they're familiar with. You shouldn't need any # swap $x and $y comments to explain basic tasks or idioms. If you really find a clever but unusual trick, or you need to hack out something that's not obvious, then you can mention it.

    I have taught my editors to highlight tags like #REVIEW: #TODO: #BUGBUG: #HACK: so I can see areas that need more attention. Review things which may or may not be right or done in the best way. List things that are definitely undone but needed. Mark areas where known bugs are located, even if the fix isn't in there yet; give bug tracking numbers if appropriate. Mark code which is overly clever to get around dumb library limitations or which save a lot of processing in obscure ways.

    (Of course, the slash ecode tag and lameness filter fought my attempts to include the pseudocode example, where indentation is useful.)

    --
    [ .sig file not found ]
  56. We're doing this backwards by DulcetTone · · Score: 1

    We should have environments that compile the comments and ignore the code, because that is where the bugs are.

    Who ever read a comment that read anything like the following?

    // iterate through the list of records, but be off-by-one at the end

    --
    tone
  57. Comments? by Anonymous Coward · · Score: 0

    I thought comments were for people who can't code, and I don't want them in my code anyway so...

  58. Language parsing: it's a feature by ntropia · · Score: 0

    From my personal experience, I don't think it's a bad thing that the "editors display comments in such a way as" your brain is not bothered by them while parsing the code.
    Comments are written in common language most of the time (pseudo-code in few cases) and it takes some effort to interpret them while you're trying to follow the data flow in the code. Graying them out or even collapsing them is a feature.
    On the other hand, you when you look for them, I think most of the editors don't make it hard for you to access them.

  59. Why not what by coolmadsi · · Score: 1

    With comments, I prefer that they explain why the code is doing something, not what it does (which should be evident from the code)

    1. Re:Why not what by geekoid · · Score: 1

      ".. not what it does (which should be evident from the code)"
      how about to that Jr. Coder that just got out of college and had you old code dropped on him to fix a bug right now?

      I have read a lot of code that wasn't clear what it was doing because the developer was either being 'cute' with the code, or just new some pieces of the code that where pretty esoteric. Since that did it often, it doesn't occur to them someone else wont know about it.

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
  60. Absolutism... by jythie · · Score: 1

    The thing I find frustrating about this debate and ones like it in CS is just how absolute people get in their statements... "I do things X way because it is right, if I have power over someone in hiring and they do not do X then I will not hire them or let them go!". This is pretty scary since what it means, at least in part, is people are not being hired or retained based on if they can do the job, but on the roll of the dice that they just happen to match up with the particular philosphy of the person above them... and expletive help people who are flexible and can adjust to local standards... they don't even get past the interview stage since 'well, what is your convention' is often the 'wrong' answer when you are asked how to do something.

    I can recall years ago having to fill out a programming test for an interview that involved how you would make a 'card' and 'deck' class. I pointed out there are something like half a dozen ways to implement this, all of which are valid but are aesthetically differ t based off the local culture. This was considered the 'wrong' answer because the interviewer had a very clear idea of what the right way to make a 'card' class was...

    1. Re:Absolutism... by geekoid · · Score: 1

      And that's why I refuse to take developer tests.

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
  61. My views by Mr.+McGibby · · Score: 3, Interesting

    From my blog:

    http://madsoftware.blogspot.com/2007/06/my-confession.html

    I have a confession to make. Forgive me. Wait, don't forgive me. I'm completely unapologetic. I am a programmer, and I don't write comments. I just needed to get that off my chest.

    I don't believe in comments.

    I have been writing a lot of fairly complex code lately. And all the while, the voices of dead Computer Science professors have been speaking to me. They repeat the mantra of good code commenting. I feel guilt, like when I go to church. Or when I don't make my bed in the morning. Of course, not one of them is able to give me any good suggestion of what a good set of comments is. They just tell me what isn't a good comment. So does that mean that anything else is a good comment? Like lots of swear words in the code. That's probably more useful than real comments, because they make me laugh and keep me from falling asleep at the keyboard.

    Good comments, I'm told, are not just a rehash of what is already in the code. Well, if it isn't already in the code, then it isn't much use to the program is it? I don't believe in comments. I think they are mostly a waste of time. Maybe not for you, but for me they just make my life difficult. I have to make a context switch to English in order to write them. That takes time and just serves to confuse me.

    Whenever I write English, I take the audience of my writing into account. Who is the audience for my comments? Some moron with a basic C++ book on his desk? Or the great man himself, Bjarne Stroustrup? Bjarne is pretty smart and will probably be able to figure out my code just fine without me, or my comments. Because he speaks C++. I speak C++ too, so that's how I like to communicate with computers and other people who speak the same language.

    So I don't write comments. I'm one of those people who likes to use good variable names, good function names, and good file names. When I look at others' comments, I don't usually trust them, because they often don't make any sense. Or they are just plain wrong. That's just awesome. Like the time I first starting programming and I spent two days wondering why the second member of a pair of ints (pair) was always zero, even though the comments said it should contain some valuable piece of information. Actually, it was the first member, not the second one, which I finally figured out by actually looking at the damn code. Wonder of wonders, the code actually told me what the code did. Amazing.

    I think that instead of comments we should put quotes of great authors at the top of all our code. That way, when people read our code, they will think that our code is profound, because we quote the greats of our time like, Dostoevsky, Helen Keller, or Dave Barry. And the best thing would be to just randomly pick those quotes so that when people try to make some connection between the code and the quote, they'll spend lots of time trying to figure out. Then they'll feel stupid, but won't want to admit it and we can fun of them when they can't explain the connection. And we won't have had to be smart at all, because all those people that we referred to are smart.

    Have I even written comments? Of course, I slap all my comments in the headers, when I don't feel like writing documentation. Or when the function name is getting too long. Or when some fellow programmer makes me feel guilty for not following the religion of comments. What is the point of writing commments if the function name tells the whole story? Take vector for example, the size() function returns, guess what, the size of the vector. I know what you're thinking, that is completely non-intuitive. It's got to be commented. Look, if the function name can't tell you what the function does, then maybe you should change the function name. And if your function name gets too long, then maybe your function is doing too much.

    Good, maintainable programs are easy to understand not because they hav

    --
    Mad Software: Rantings on Developing So
    1. Re:My views by Animats · · Score: 3, Funny

      Transfer this guy to maintenance programing for a year.

    2. Re:My views by James+McGuigan · · Score: 1

      For the fashion of Minas Tirith was such that it was built on seven levels,
      each delved into a hill, and about each was set a wall, and in each wall
      was a gate.
                      -- J.R.R. Tolkien, "The Return of the King"

              [Quoted in "VMS Internals and Data Structures", V4.4, when
                referring to system overview.]

    3. Re:My views by Anonymous Coward · · Score: 0

      You, sir, are an asshole and if you should ever have the misfortune of coming up for an interview with me you'd better be prepared to be laughed off the premises after saying something so ridiculous as that.

      Yes, you're entitled to your opinions and I support your right to say stupid shit like that... but you most definitely won't be working for me doing it, and you won't be working for anyone who isn't also an asshole too frankly.

    4. Re:My views by Anonymous Coward · · Score: 1

      Good, maintainable programs are easy to understand not because they have lots of comments explaining their complex structure, but because they are straightforward, not complex. Complex is a synonym for spaghetti.

      Epic.. fucking bullshit. Unless your code just does trivial shit. Got a complex algorithm or numerical algorithm to implement, you need freaking comments. At the very least an overview of what the algorithm is (and ideally why it works), what it does and hopefully some hints at what some of the functions do to implement the algorithm. It also gets epic important when one gets into optimizations too.

      I tell you what, to give a taste of it all, open up LinPack (in Fortran) strip the comments, and see if you have any idea what is going on. Try it I dare you.

    5. Re:My views by markjhood2003 · · Score: 1

      I don't know if you're serious or just trolling, but if the former, I sure hope I never have to revise the code you wrote, and I would pity the developer who got stuck with that job. The only way I can understand your attitude is that perhaps you don't work with other people, or you never expect your code to have any life after you're done writing the first version.

      As many people have pointed out, comments shouldn't be used to explain what the code is doing, unless it's exceptionally obscure; they should be used to provide information that doesn't exist in the code itself.

    6. Re:My views by Anonymous Coward · · Score: 0

      Stick to food and religion, stay away from code. Makes the world a slightly happier place for other coders.

    7. Re:My views by geekoid · · Score: 1

      "Well, if it isn't already in the code, then it isn't much use to the program is it? "
      it isn't about the program. You word that in a way that make me question you knowledge of how a compiler works.

      " I'm one of those people who likes to use good variable names, good function names, and good file names. "
      and? that in know way indicates the goal of a piece of code. Not at all. and Good is subjective, but the the sake of this argument I'll assume they are consistent.

      The alternative to bad comments isn't no comment, it's better comments.
      Again,l comments are about the goal. You can read the code and see what it's doing, but is it suppose to be doing that?

      ", I slap all my comments in the headers, when I don't feel like writing documentation."
      wow..you are pretty horrible and any long term benefit at your job.

      "What is the point of writing commments if the function name tells the whole story? "
      because it almost never does? sure, you you are writing 5 lines of code, then yeah a good name is fine... unless that code is called by 100 s of different calls
      Say there is a bug. If the code is fixed one way, it breaks one thing, if its another it may break something else. which is right? what is the code expecting, maybe the bug isn't there it's the calling code trying to pass the wrong variable. What if both these examples have been the code for years, but never came up until recently? how do you know what's suppose to be without having to run through the whole program?* Those question are just made up, there based on situation I have ran into.

      "but because they are straightforward, not complex. Complex is a synonym for spaghetti. "
      No, comples is a reflection of many really world reality trying to be coded for.

      No single piece of code should be complex, but the code working together as a whole is incredibly complex.
      R=try writing code to make business decisions on large financial business's.

      You're whole post seems ot come from some simpleton program with no experience in the real world with large systems. Like the only code you ever wrote is self contained.

      " Code comments may feel right, but they just don't prove their value outside of giving people a good feeling."
      Good comment written for properly engineered code are invaluable.

      ". In religion, there are things that you believe just because they seem right. "
      and keep it there. In engineering there are things that ARE right. If you can't engineer, you, and everyone else like you, should just get the fuck out of the industry. You are the reason the software industry is still a pile of buggy crap that people can't change without spending millions of dollars.

      *I routinely work on programs with over a million LOC.

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
    8. Re:My views by geekoid · · Score: 2

      no thanks,. he will just put in a bunch of code he believes is obvious without taking into consideration any outside system the piece of code might be using.
      Transfer him to McDonald's trainee.

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
    9. Re:My views by euroq · · Score: 1

      You are so fucked up in so many ways. You believe in religion because it "seems" right without evidence? You chose Bjarne Stroustrup as an exemplar of intelligent programmers, even though he wrote C++ which is a fucked up language?

      Good comments, I'm told, are not just a rehash of what is already in the code. Well, if it isn't already in the code, then it isn't much use to the program is it? I don't believe in comments.

      You are a fucking moron. RTFM. You are saying you don't like worthless comments. Duh, you dumbass. Good comments are not what is already in the code. Good comments explain why, bad comments explain how. The how part is already in the code and therefore worthless.

      --
      Just because the U.S. is a republic does not mean it is not a democracy. Democracy/republic are not mutually exclusive.
    10. Re:My views by angel'o'sphere · · Score: 1

      I guess for every human it is pretty difficult to stop and hesitate during one of his thoughts and realize: o! this is not obvious!

      Usually a human as a trail of thoughts and comes to an end. At the end or together with that end, the code is (already) written.

      If there is no "wake up" event, causing that human to get several steps back and "reviewing" his own thoughts and solutions, he will never realize that his trail of thoughts above and his code is non obvious.

      And even if he does review his thoughts and code there is no guarantee that he will realize it. Much more likely he will just follow his original trail of thoughts again.

      The only way I know to break out of this trap is to read your own code often enough and simplify it with refactorings. In the end you will be able to write more simple, more obvious code. And the way you approach stuff and the way you think will change. However: you still easily fall into the same thought pattern as mentioned above.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    11. Re:My views by flargleblarg · · Score: 1

      Let's see a sample of your code, there, cowboy.

    12. Re:My views by flargleblarg · · Score: 1

      Or subject other people to maintaining his code for a year and see how many questions arise.

    13. Re:My views by billybob2001 · · Score: 1

      Take vector for example, the size() function returns, guess what, the size of the vector.

      So I should resort to guesswork and not even read the code, let alone hope for comments?

      What if it's not actually vector that I want to use, but something that appears to be very like it, so I assume you wrote it to behave the same way, but for very good reasons, you wrote some things differently.

      Suppose I want to use noCommentsBecauseYouShouldJustKnowFromTheCodeVector and call its size() function?

      Tried it, it said 16 every time no matter what was in the vector - how do I know whether it's meant to return the element count or the size of the "vector" pointer in bytes? (Or some other calculation with some magnitude, such as capacity or memory usage?)

      Also, what happens if the vector is null/uninitialized? Is that the same as when it's empty? For whatever language I use?

      How big can its value be? (When it's valid / ever)

      Can it be negative?

      Are all values unambiguous?

      Is it thread-safe?

      Is there something else I may have called which will already contain the size value, so I can re-use it to save calling size() now?

      Why am I using this vector anyway? Isn't there something better? (And if not, why not? Because there could be a really good reason, which I might not guess.)

  62. Comments have the following purposes. by aristotle-dude · · Score: 1

    1. To document an API with methods and expected outcomes.

    2. To document TODOs.

    3. To document why a method is public (ie. for unit tests).

    4. To document the reason for workaround code when working with an external third party web service or other type of api that sometimes returns inconsistent results where the information is sometimes available through other means in the system.

    --
    Jesus was a compassionate social conservative who called individuals to sin no more.
  63. Comments are the cognitive layer by gestalt_n_pepper · · Score: 1

    Necessary, but not too detailed. They should briefly summarize what you did, and perhaps how (again briefly) but MOST importantly "WHY you did what you did.

    --
    Please do not read this sig. Thank you.
  64. How vs Why by denbesten · · Score: 1

    Comments that describe why you are doing something or that explain strategy are exceptionally useful. Please include them. When I need to look at your code in two years, they will make me very happy.

    Comments that describe how the language works (e.g. "//loop through the arguments") or what something is (e.g. "int i; // loop counter") have the possibility of being eliminated through careful selection of names, code organization, etc. Doing this will also make me very happy.

    Also, please live within the language definition. Substituting "argv" with "CommandLineArgumentVector" when programming in C makes your code less clear because it no longer matches what is taught in every C book. Same goes for brace placement. If you want to call yourself a "C" programmer, your code will look like it came out of K&R.

    I'll climb down from my soapbox now.

  65. comments - just do it by Anonymous Coward · · Score: 0

    Just put them in a collapsable region (#region ... in Visual Studio), then expand them to read or collapse them to get them out of the way and, if you have coding to do, which you do, get back to work!

  66. and also by Anonymous Coward · · Score: 0

    I've found that, usually, the one that is most affected by my own careless lack of commenting is my future self... the point is, commenting code well can help you directly, at a later date, when you go to take the lid off again and start wondering, "what the hell was I thinking here..."

    I've found that comments never get in the way, and I always appreciate them when they're there. Just a short one is a whole lot better than nothing, and almost as good as a long one... please just give me a CLUE what was happening here!

  67. No, ignoring the comments is sloppy. by TuringTest · · Score: 1

    Djikstra said, "Always debug the code, not the comments". No one updates the comments. Including me.

    A guy above said that their team treats incorrect comments as a bug, and they're right in that approach. The whole point of high-level languages is to communicate with the programmer as well as with the machine; if the source code contains inconsistent instructions for the human and the computer, the program's current internal logic is flawed. Even if the binary executes without errors, changed the code won't be smooth because of those contradictions.

    While the school of 'weave' and 'tangle' from literate programming proved to be too heavyweight to be practical, the future of comments is not to ignore them, but to better integrate with the IDE. Documentation generators like Javadoc or Doxygen were a big hit because they simplified building rich sets of deep, easy-to-navigate comments. Also coding features like design-by-contract and unit testing can be thought as forms of executable comments - they don't contribute to the program business logic, but they tell the programmers about its inner stable structure.

    Programmers ignore comments not because it's the right thing to do, but because it's hard to do well. As tools for engineering comments along with code get better, we'll find programmers using them more and more during the early programming stages instead of an afterthought.

    --
    Singularity: a belief in the "God" idea with the "demiurge" relation inverted.
  68. Re:For those of you that claim comments are useles by GuB-42 · · Score: 1

    It is very difficult to write "self-documenting" code in assembler. Most variables are not even named (registers).
    Also, people usually do assembler for a reason, either it is for heavy optimization or direct hardware access. In both case there is usually a lot of things behind the code that is not visible. For example situations where there is a good reason for doing b+a instead of a+b are much more common in assembler than in high level languages.

  69. Plain Language Programming by Kataire · · Score: 1

    The more comments you have in code, the higher risk you have of time sucks and bugs (past, present, and future). Instead, use naming and syntax to make your code as human readable and comprehensible as possible. Bytes are cheap, there's rarely need for clever abbreviations; instead of getting clever with them, get clever with expressing your code closer to plain language. Think about the names of your nouns and verbs (and even adjectives and adverbs), and make sure they make sense to anyone who understands your problem domain.

    In my humble opinion, broken code comments are almost as dangerous as broken logic, and should be treated as a bug if it's wrong. It's wrong if it's inappropriate, outdated, misleading, takes more than a line or so, or superficially obvious. If it needs more than a line or so, it should be documented, and the line in your code should brefly identify the problem and documentation location. I'd recommend that it refer to sections within a technical design document.

  70. No Technical Person Likes Writing Documentation by 4iedBandit · · Score: 1

    No technical person likes to spend time writing documentation. In my career this is a universal truth. I document my code and I write external process documents as well. I hate it, but I do it. Why? Because six months down the road when I've moved on and focused on something else a requirement changes in the old code. I have to go back and make changes quickly and be confident that my changes don't screw up anything else. I partially rely on the documentation I wrote to explain what the inputs are, what the output should be and why I did it that way. The other half of that equation is unit testing. If I document and I have a test to verify my code, changes on down the road are much easier to do with confidence.

    I find people who say that code should document itself are full of it. I write programs because I need to manipulate inputs in a non-obvious way. I document it because it is non-obvious and I don't want to have to waste time figuring out why I did something a certain way 6 months ago.

    You know what really pisses me off? People who believe code should be self documenting and therefore *REMOVE* all comments. I worked with one guy who actually setup scripts to remove comments from all source in the repository. He thought all of his code was self documenting too. He was wrong. Sorry, but I'm not a super genius who can immediately understand all the obfuscated functions and variables someone else thinks is obvious. Deciphering un or poorly documented code is a huge time sink.

    --
    "The avalanch has already started, it is too late for the pebbles to vote." -Kosh
  71. Favorite Comment: NOTE: This breaks 9/1/2014 by Anonymous Coward · · Score: 0

    I've looked at a bunch of code written by others in my years. Came across some complex code that said, "NOTE: This breaks 9/1/2014" with no further explanation. I have no doubt that it isn't correct.

    After seening that comment, I started having fun with my comments in that product too. I added, "NOTE: Breaks in 2040, but I'll be dead by then." It was a bonehead 2 character year handler. After 2040, all 2 digit YY dates become 1940, 1941, ....

    I'll be dead by then, I'm pretty sure.

    Comments shouldn't be necessary except at the top of a file that explains the general purpose for the file/class. The code should speak for itself whenever possible. Descriptive functions/methods, classes and variables should be enough. Sometimes that fails for really complex needs so comments are required. I'm a believer that comments should explain entire functions - not a single line.

    Functions should be shorter than 1 screen can display. Long functions are hard for our brains to keep track. Think about it - how many times have you needed to merge multiple functions into a single method - never. OTOH, you always need to split up functions into multiples - happens all the time. Somewhere around 10-20 line of code seem ideal for a function/method.

  72. I prefer TODO/FIXME by Anonymous Coward · · Score: 0

    When writing the code, I know a spot is dodgy, and I can mark it as such.

    It is a likely place to cause bugs. Why not fix it while writing? Usually there's no time to fix it.

    So is it better to leave those out? Some corporate coding standards mandate no FIXME, TODO or XXX in the code. Thus people just remove them. Is the code better? No. Why? It takes a longer time to home in on the problem spots, as they are no longer clearly marked "HERE BE DRAGONS".

    Put the comments there, and use your editor to hide them. Any sane editor can do that with a bit of scripting/tweaking.

  73. RE Grownups writing programs by clovis · · Score: 1

    Periodically this gets brought out, looks like it's time again:

    http://www.fastcompany.com/28121/they-write-right-stuff

  74. Fuck Comments by Anonymous Coward · · Score: 0

    Fuck them all.

    I'd rather not have code comments at all. I am working on your usual written-by-pieces-of-shit legacy code, and I have to deal with the following.

    -Comments that only say who did what when. Jdoe, 2/7/2003. Yeah, that's useful, dude.
    -Comments that add no useful information, wasting tons of space. public void setTableDAO(TableDAO tableDAO) { //sets the TableDAO
    -Commented code! everywhere! Just adding to the bulk of the retarded thousand lines long methods.

    And of course there's never any comment for the mysterious sections that may actually be useful. These assholes were mandated to comment their code, and they followed it to the letter of the law.

    I spend a lot of time deleting these comments. No comments make for much more readable code.

  75. What? by Anonymous Coward · · Score: 0

    What the fuck is going on on /. lately? This is one of many CS or programming related articles that have shown up in the past few weeks, and it's really ticking me off. I come here to read about Julian Assange, Apple lawsuits, and politics, not tedious minutia relevant to my job and life. Don't forget your roots, because I will ragequit if you guys turn this into a tech news website. Officially on notice.

  76. Time and place for comments by cyberfunkr · · Score: 1

    In my code I have developed a certain style/guideline about comments
    1) Always comment in detail the utility functions. They are the most likely to have obscure code, hacks, tricks, or otherwise confusing to read on first view.
    2) Database functions should self document, both by the name of the function and a quick glance at the query. A function named Members_Load_All_By_Time( minutes, array ) kinda says it all.
    3) Display functions get commented to break up sections; here is where navigation starts/end, here is where notes get displayed, etc.
    4) Long If/Then/ElseIf/Else get one for each condition about why test for that specific condition.
    5) If pulling in a feed, or otherwise getting a complex array/structure, have a comment block of what the input looks like. This could be an example of the XML, members to an array, or other non-standard information. Something to show what I'm working with.
    6) If using a technique found on a forum or blog, include a comment to the URL/post, date it was published, name of author, and other info to get back to the posting. Not only to CYA in case of licensing issues, but check back occasionally to see if the author or a commenter has made an improvement. Or for me to submit an improvement I discovered.

    As a side note, sometimes even better than comments is just good coding style. If the language allows it, use whitespace to your advantage; line things up, indent to show beginning and end of loops, and add blank lines to give visual breaks and convergence points.

  77. Most coders get comment wrong anyway. by Anonymous Coward · · Score: 0

    Comments are there to tell you WHY they did something the way they did, not to tell you WHAT they did.

  78. Yes, good comments are good, but by cc1984_ · · Score: 1

    In my opinion, a two pronged approach of good commenting in the code and extensive testing make for a much more attractive package.

    Is there some code that looks odd but accounts for edge case x? Write a simple comment saying as much, but write a test with the edge case in it. That way if someone hoses it, a test will fail.

    You even have things like cucumber (http://cukes.info/) for ruby which creates documentation with the tests.

    1. Re:Yes, good comments are good, but by DuckDodgers · · Score: 1

      In some cases logging is unnecessary or you have no useful place to put the log files, but in addition to comments and unit tests I have tons of log statements. e.g.:

      log.debug("Entering function ___ which is supposed to sort the list of patients based on their most recent test results arrival.");

      It won't show up in the log file when the code is run normally, but it's a form of comment all by itself, and it makes finding errors much easier - just turn your logging level up from warn to debug, and it will walk you through each step.

  79. Magic Method by Anonymous Coward · · Score: 0

    I like people who write "This is where the magic happens." Sprinkle some bitxie dust on a simple algorithm and poof...MAGIC?

  80. He works by himself. by Anonymous Coward · · Score: 0

    Dave Winer has essentially worked solo on his code for the past 10 years. Why should I pay attention to what he says about comments? He doesn't collaborate.

  81. Uncommentable algorithms by sgunhouse · · Score: 1

    As a mathematician who sometimes programs, much of my code is indecipherable to non-mathematicians and any degree of commenting won't change it. If you don't understand why there's an exponential function in that code for assigning probabilities to an event in the simulation, dumping an entire textbook into the comments won't explain it to you. Can I assume at least a certain level of knowledge so I don't have to write a textbook? Well, at the time, no - I knew the expertise of the person I was coding for, he simply couldn't grasp that. (He had told me so himself, too.)

    If I'd been writing for people who have my non-programming knowledge, I wouldn't need to comment on that particular algorithm at all, it's pretty basic in the field. Should there be some comment left for people who don't know that discipline? Okay, sure - but honestly it won't explain it to them.

  82. Why not what (again) by wonder · · Score: 1

    As has been said a few times, the principle reason for a comment is to explain why the code needs to be the way it is, not what it is doing. By this definition, a few things happen.
    You get fewer comments in the code, because most code doesn't need explanation. Yeah yeah there are those pesky API calls that have to get called in nonsensical order and the fact that you're rounding down and not up because your ad campaign doesn't do partial credit to save money, or whatever other nefarious, legacy, or even sometimes malicious reasons there may be. Even legitimate code can be malicious.

    But lets be real. This only works if people write sensible code to begin with. Code can be self-documenting. Those nay-sayers who complain that it cannot be simply don't know how to do it, or haven't yet seen a suitable example.

    You don't need to write code that has 6 equations on one line. You don't need to write 200-line methods. You don't need to use variable names that obfuscate meaning, or worse, those that have no meaning at all. (int a,b,c,d = 0). You don't need to, but many of us as professional developers do. Why in the world do we do that?

    I can spout all sorts of slander about being lazy and being macho, ignorance and horribly misguided job security, but i won't because it doesn't help. I don't care why we do it, i care why we should seek to write code that we can come back to a year later and just read.

    Languages are pretty high level these days. The code they support can very nearly read like sentences. Why not?

    I learned how to produce useful self-documenting code by doing TDD. TDD told me to write tests that describe the behaviour i wanted to achieve (not the implementation i was trying to test). I parlayed this into my code as well. Now i might have a class called calculator, with methods such as Divide, Mulitply etc. and tests which say Divide_Prevents_An_Exception_For_A_Denominator_Of_Zero() and Divide_Reports_Divide_By_Zero_Error() and other such things.

    Why would i have to comment that? Does the compiler care how long my method names are? Is anyone reading those tests or methods going to need help to understand what is going on? Not likely.

    Whether you believe you can truly write self-documenting code or not isn't relevant. I can't evangelize the benefits to non-believers. But how about just trying to achieve it? Even if you don't really succeed, you'll probably find your code a lot easier to understand even if you insist on putting comments in your code.

    I'll bet you'll fall in line with everyone else eventually and find that comments aren't necessary, unless something unnatural is afoot. Then and only then, will you ever find a comment in my code.

    1. Re:Why not what (again) by geekoid · · Score: 1

      sometime you need to state what it's doing.
      And you always need to state what it's expected to do. That's the only way the next person that comes along and get an idea of how to fix it, or converted it into a new language,.

      Look, just follow engineering specification. They exist for a reason.

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
  83. blah blah blah by Anonymous Coward · · Score: 0

    nothing to see here..move along people. Just more nerd developers fapping at their egos

  84. Types of comments by justfred · · Score: 1

    One issue I rarely see discussed are the different types of comments. Most languages and editors don't seem to differentiate between these common types of comments.

    -Standard, inline comments //check for out-of-bounds /* send the user an email
    * to let them know they've
    * done something wrong
    */
    int fritz = 0; //0 indicates no fritz at all

    -Autodoc (or autodoc-style) comments, usually in class/function headers - whether or not autodoc is actually used /**
    Given foo and bar object, produce woofObject by transmogrification
    input foo int
    input bar barObject
    output woof woofObject
    **/
    function transmogrifyFooBarToWoof...

    -Comment-out - code that is disabled by commenting /* here is some code we don't use anymore, but is here for reference
                        if (whatever) do something;
    */

    -Todo comments (I tend to style these with #! or #? in php or //#? in other languages)
    #!if the result is negative this will fail
    #?should we be bounds-checking

    Another annoyance with my editor (Eclipse, in my case, but most others I've tried also have this issue) is that I like to left-align my comment-out and todo comments for visibility - a habit that comes from COBOL, I guess.

  85. Examples? Thank you. by shiftless · · Score: 1

    I've only ever worked with one software engineer who, in my opinion, documented enough; I strive to match his standards in my own code but I know I don't always succeed.

    Could you provide examples of what you mean, for the rest of us to learn from? Thank you in advance.

  86. He meant by shiftless · · Score: 1

    I don't think revision control has anything to do with it. It's a matter of taking the time to change the comments near a block of code when you change that block of code. Revision control neither helps nor hinders in this process.

    He meant revision control like the proper business process of developing software and the procedures used to properly make revisions, and the adherence to or lack thereof; not the actual software used to implement it (CVS, etc.)

    1. Re:He meant by siride · · Score: 1

      Gotcha. That makes sense, but it wasn't clear in the context, since the term "revision control" usually refers to the software and its data model.

  87. Problem has already been solved by Anonymous Coward · · Score: 0

    Knuth's CWEB has been around since the 1990's and it is everything one should want in tools for creating and maintaining proper code documentation. Rather than having comments take a backseat, become out of date or inaccurately reflect the implementation. The literary portion of software documentation is up front and coding is implemented to match the documentation. I will admit that what it does is a psychological trick, but it does seem to require less discipline to use and maintain a CWEB project than using code comments.

    In the programming industry, I feel like there is very little "news" that is new and innovative. A lot of it seems like poor rehashes of earlier technologies. Be it CWEB, mainframe virtualization, LISP, Garbage Collection, etc. Most of this stuff seems to have been available decades ago.

  88. Yeah that by shiftless · · Score: 1

    ^... which is utter stupidity. Only a wage slave would get the bright idea that loading themselves down with more and harder work is the way to profit. Never once does it enter into these clueless "programmers'" heads the idea of doing things correctly thus saving time and allow oneself to tackle bigger and harder problems, instead of always wading around in the muck picking up garbage. Fucking idiots. It's basically a reflection of our society as a whole, really. No big deal, it leaves the bigger, more challenging, and more interesting problems wide open for you and I to solve.

  89. Comments as pseudocode by handy_vandal · · Score: 1

    I have sometimes found this method ("Write comments, convert to code") useful.

    Might be especially useful when discussing project requirements with non-technical clients. Obviously coders can't talk code with non-coders; therefore coders must use human languages when talking with non-coders.

    --
    -kgj
  90. Missing the point by Anonymous Coward · · Score: 0

    These comments about the visual relevance of comments is totally missing the point. The real issue with comments is that they lie. I've never seen a project use comments that doesn't go the same way: developer is all excited at first and committed to maintaining good comments in their code so they comment everything. Then it's time to debug and they start changing the code, but forget to change the comments. Two years later, new guy comes in and needs to make some changes to the project, tries to read the comments to understand how the code works, and at best winds up confused because the comments don't seem to agree with the code, and at worst ends up trusting the comments without checking the code and breaks stuff based on an incorrect understanding of how it works.

  91. Create a new process style... by Anonymous Coward · · Score: 0

    Just create yourself a new religion call Comment Driven Coding. ;')
    But now that I think of it, comments could be avoid if you have well define unit test.
    Anyway, I vote for little good comments instead of too much to be change when refactoring.

  92. Patent nonsense by Anonymous Coward · · Score: 0

    The "clarity of comment-free code" is pure, unadulterated bullshit.

    If your code does not have comments (short of glaring syntax errors and obvious infinite loops) it cannot be debugged because there is nothing in human language describing what the code is actually supposed to be doing.

  93. Irelevant by HarryatRock · · Score: 1

    No amount of comments can replace full and proper design and implementation documentation. In fact the best comments are links to these documents. And don't go on about waste of time producing such documents, in over fourty years in the business I've seen plenty of evidence to support my view. Modern IDEs make it easy to update design and implementation notes and keep linked versions of these and the code in step, and multiple screens make it easy to have all relevant information in view at the same time.
    Now get off my lawn and take your badly designed, badly written, and probably irrelevantly commented code away from my system.

    --
    nec sorte nec fato
  94. talk to your code by Simonetta · · Score: 1

    The best comments are done with a speech-to-text converter.
        Put a picture of some pretty movie star next to your screen (that shows your code). Pretend that she is just !fascinated! by you and your code. Turn on the speech-to-text so that everything that you say gets dumped into a text file. Pretend that you are talking to here and describe your code in all the detail that you can imagine. Describe everything. When finished, close the text file and include it with your source code. Way better documentation than any other method and faster also.
        THis is weird, but it really works if your speech-to-text is working. Not 100% is OK, but at least 90%.

    1. Re:talk to your code by geekoid · · Score: 1

      "Yeah baby, this code where I do a memory copy. yeah, it's the best. I got a bitty for that.. a bitty is an award to outstanding code.. writing code like this is what allows me to afford the Corvette out side. Lets go for a drive. I know a great place up on the hill with good with and a magnificent view."

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
  95. Funny at times by SuperTechnoNerd · · Score: 1

    A while back I was looking through some source code for a linux device driver, one part said
    "This is an ugly hack. I must have been on crack. Need to fix this soon"

  96. Simple rule I try to follow by vgerclover · · Score: 1
    • Docstrings: what the code does.
    • Code: how it is being done.
    • Comments: why it is being done in the way it is coded.
  97. Ugh, THIS stupid-ass debate again?!? by Anonymous Coward · · Score: 0

    If you're a good programmer, you comment, you comment well and you comment quite a bit. Period, end of frigging story. Anything else and you're shit developer, plain and simple.

    Comments tell the story of the code. If you're one of those "the code explains itself" people, YOU ARE WRONG. The code tells you what the code does, and absolutely should be written as simply as possible to facilitate that, but it does NOT tell you what it's SUPPOSED to do, not WHY it's supposed to do it or HOW it arrived at its current form. Only comments can do that, and THIS is the stuff that professional developers know are most important.

    Good commenting is identifiable by being able to pull all the CODE out and read the comments and be able to get the overall flow of the code, the overall picture of what's going on, without getting into implementation details. Yes, having to update comments along with code is a drag, but (a) good comments tend not to have to be changed just because the code changes, and (b) it's the price you pay for maintainability, which in a professional environment trumps all else.

    Whether the comments are colored, collapsed, in a crazy font, spin and glow when hovered over, that sort of stuff is tangential. Writing them in the first place is what matters.

    Let's stop debating comments already, ok? They're necessary, they aren't optional, and GOOD developers already know this. You shit developers can either get with the program or man the fryers at Wendy's because you shouldn't be working in this field if you don't get it.

  98. Keep worknotes with the code by DragonWriter · · Score: 1

    Yeah and what happens when the 'worknotes' server is taken offline or moves?

    This is one reason why "worknotes", to the extent that they are needed, should be maintained with the source code (i.e., in the same repository) even though the notes are separate files from the source code.

    It should be impossible for the worknotes referenced in the source code to become unavailable while the source code itself is available.
     

  99. Comments versus Reality by userw014 · · Score: 1

    In my experience with legacy code, most comments (if present) only bore a rather tenuous relationship to the code or the purpose of the code.

    I've taken to treating comments as entertaining reading by the author(s) of the legacy code. Sometimes they foreshadow what's about to happen, sometimes they spoil the ending, sometimes they deceive, and sometimes they outright lie.

    Code without comments IS a bit frustrating - but also freeing too. Without the comments adding chaos to the body of work, you can figure out what's going on without distraction.

    1. Re:Comments versus Reality by geekoid · · Score: 1

      " you can figure out what's going on without distraction."
      but you can't figure out what it's SUPPOSED to be doing.

      So comment. Update comments. Do proper engineering.

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
    2. Re:Comments versus Reality by userw014 · · Score: 1

      I do. But I treat the comments in the code before me as potentially treacherous.

  100. Unit Testing by DragonWriter · · Score: 1

    Unit testing fails because if your code changes, you must change your unit tests.

    Wrong.

    If your the requirements for code change (or it is discovered that your previous unit tests didn't cover all of them completely and correctly), you must change the tests that exist to determine whether the code meets those requirements.

    If your unit tests fail, you must change the code.

    But you don't need to change the unit tests because you changed the code. That's backwards.

    Few managers realize that Unit Testing adds 20 - 30% or more overhead to software but plan development as if Unit Testing takes no effort.

    I've yet to see any place that does anything like unit testing at all -- whether in the bad test-last way or the good test-first way -- where the fact that writing unit tests takes time is not considered in planning and estimating. The good test-first places tend to be low-ceremony environments where the dev team does estimates which include unit testing as part of the overall development-time estimate, and the bad test-last places tend to by high-ceremony bureaucratic environments with top-down planning by management that explicitly breaks out unit testing. So, IME, this is generally false.

  101. Colors man, I see the colors. by Anonymous Coward · · Score: 0

    Let .. me get this straight... the linked article is essentially complaining about editor settings. most source code editors let you select the font, color, etc for each thing construct it recognizes... if the comments are not visible enough to you, edit one's editor settings...

    perhaps it's a complaint on the default setting of an editor.

  102. Comments matter by Fishbulb · · Score: 1

    Good comments help capture what you're thinking; what you're trying to do with your code. That's far more important than the implementation. It's the 'why' not the 'how'. Anything that facilitates capturing the why is a good thing.

    Case in point: regaining the knowledge of the Apollo program. they still have most of the designs of components, including multiple design revisions, but they never captured the reasoning behind the design changes. You can see that bolt moved a half-inch to the right, but you've lost why that move was important.

  103. REM *** Comments are your friend *** by Anonymous Coward · · Score: 0

    I started programming at age 12. That was back in 1980. I've been coding professionally for close to 20 years. I am a comment zealot. I'll tell you why too... I still maintain code that I originally wrote as far back as 1995. A whole lot of weird is introduced into a code base with that kind of lifespan. In a non-perfect world, deadlines, vocal clients, incompatible data organization, all kinds of things happen causing code to evolve in unexpected (and incomprehensible) ways. It's not optimal, and it makes me cringe when I see nice well thought out architecture get crufted up by some ugly kludge so we can ship on time, but it happens. So if you don't document what the heck is going on, right then, right there... Good luck 10 years down the road trying to figure out why you did some extraordinarily non-obvious thing... Comments augment code, good comments explain the "why" you did something screwy.

  104. false economy by Chirs · · Score: 1

    If you don't have comments you need to spend time reverse-engineering the code.

    I suggest that it takes less time to update the comments than to try to understand code with no comments.

  105. code can't tell you *why* by Chirs · · Score: 1

    The most useful purpose of comments is to explain why something is being done, or being done in a certain way. In some cases (assembly coding, for instance) it can also be useful to have a comment explaining the overall algorithm.

    Comments should also highlight any particular gotchas, possible areas of improvement, known shortcomings, etc.

    1. Re:code can't tell you *why* by Anonymous Coward · · Score: 0

      So what happened to the rest of your project documentation - design docs, requirements, reviews, etc? Gone with the wind? Sheesh.

  106. Visual Studio by geekoid · · Score: 1

    handle comments perfectly. You can hide them, change the color, run reports on them, use a template.

    And yes, comment your code.
    Data, initials a description of what you expect it to do.
    Update with changes, because regardless of your ego, you are capable of putting a small change that doesn't show up for a week..or more.

    --
    The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
  107. Have a "comment trigger" by smagruder · · Score: 1

    In my experience/perspective, it seems to work best to, at a minimum, try one's hardest to write code that is as efficiently encapsulated as possible and self-descriptive using well-named functions, parameters, classes, methods and variables, along with clean formatting of processing structures.

    And then have a "trigger" as to whether a comment is necessary. Such as:
    1) Are you doing something so arcane that another programmer wouldn't easily figure it out? Arcane things like unusual business logic that a reader of the code might not be expecting. Of course, one way to solve arcane code is to find a way to further simplify the code, perhaps breaking it up and/or using functions.
    2) Is there a limited use for what you've written? Is it necessarily partially hard-coded for now?
    3) Is the code section really long so that commenting can better guide the reader around the monstrosity? (or you can break it down and/or use functions to clarify)
    4) Does the code do something really special that you want to point out? Does it have a potential for re-use?
    5) Have you had to write an anomaly workaround or something kludgy that for some reason needs to await further review and rewrite but also needs to go into production ahead of that time?
    6) If a common function library, are the purpose, parameters and return value fully explained? Similar applies to common classes.

    There may be other triggers I can't recall off-hand.

    Even though IDEs can hide comments, they, like code, still have to be maintained. So efficiency of comments is important, although usually not nearly as important as efficiency of code.

    --
    Steve Magruder, Metro Foodist
  108. Too much comments by someones · · Score: 1

    I have developed/maintained software for some bigger companies like our National Trains' Company.
    I came across code that was done by some guy comming from the java eco system.
    It seems to me, like he was an amateur OR that java folks do lots of useless commenting.
    Not that there were more commenting lines than code lines, but the comment itself was that trivial that it just obstructed reading the code.

    Consider something like this (actually i cannot post the real function, but its pretty much the same triviality): /*
    * if num1 or num2 are both greater than 0 add num1 to num2 and return the result.
    * in all other cases return -1
    */
    int addNumIfPositive(num1, num2) { /* if num1 or num2 is smaller than 0 return -1 */
    if(num1 0 || num2 0 ) return -1; /* add num1 to num2 and return */
    return (num1 + num2);
    }

    Why would one need any comments at all?
    Code comments should be helpful for people that maintain or extend existing functionality and not for people who cannot read code.
    Comments should be used on code sections that are not clear from reading the code. eg some series of function calls, or exception handling, but PLEASE dont use them on trivialities or for people that cant read code!

    1. Re:Too much comments by someones · · Score: 1

      meh, html kill'd the formatting

  109. Comments by Anonymous Coward · · Score: 0

    I think if you have time to comment on comments, you obviously do not have enough work to do. However, commenting on comment comments is acceptable provided the comment on comment comments is thorough and engaging.

  110. I'll provide a reference for a janitorial position by Zero__Kelvin · · Score: 1

    "You did not post a compile able "*.c" file but a "*.h" file."

    As I said, the file I got the code from is e100.c See lines 494 through 571. Also, there is no real difference between a .h and a .c file for the purposes of our discussion since both are comprised of two fundamental atoms, to wit comments and code. The purpose of a header file is to include certain elements of a program's source code that will be reused by multiple files so that they can share interfaces and data structures. When no such sharing is desired they don't belong in a header file. In this case the struct has file scope, and putting it in the .c file ensures that nobody else can or will manipulate elements of the struct. This is done in order to properly implement abstraction.

    As you can see, what you don't know about what you are doing could literally fill a book.

    "I suggest you consult your favorite dictionary what a 'janitor' is :D"

    I know exactly what it is, but you seem to be the one who cannot understand simple English. My statement is that the best thing one can say about your knowledge of software engineering is that you would probably do well emptying trash, mopping floors, and cleaning toilets.

    --
    Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
  111. Re:I'll provide a reference for a janitorial posit by angel'o'sphere · · Score: 1

    Lol,

    an empty file also is a valid c-file. And contains no code.

    Yepp, I did not read up the old posts so I missed the fact you got your example from a .c file and not an .h file.

    Nevertheless most .h files compile to nothing if you compile them.

    So the point about knowing nothing is kinda ridiculous ...

    Meanwhile I lost track what the point of the argument was ...

    You want to comment everything except the stuff that needs comments? (what exactly does that "cb" field mean in your code?)

    I like to comment as few as possible ...

    That makes me a janitor?

    Sorry, in my country janitors don't clean toilets, mopp floors or empty trash ...

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  112. Re:I'll provide a reference for a janitorial posit by Zero__Kelvin · · Score: 1

    "an empty file also is a valid c-file. And contains no code."

    Was there a point to be made, other than that you don't know better than to start a sentence with a conjunction?

    "You want to comment everything except the stuff that needs comments? (what exactly does that "cb" field mean in your code?)"

    It is not my code, first of all. It has been vetted by numerous Linux kernel programmers. That being said, it is a Command Block. This is something that you would know if you were writing an Intel Ethernet driver. It is completely obvious. It is not the kind of thing you would put in a comment any more than you would add /* i is an index in the for loop */.

    "Sorry, in my country janitors don't clean toilets, mopp floors or empty trash ..."

    Well there is room for innovation and improvement then! ;-)

    --
    Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
  113. Re:I'll provide a reference for a janitorial posit by angel'o'sphere · · Score: 1

    It is not my code, first of all. It has been vetted by numerous Linux kernel programmers. That being said, it is a Command Block. This is something that you would know if you were writing an Intel Ethernet driver.

    If my boss assigned me tomorrow to work on an ethernet driver: I would not know that.

    Rest for the other fields in that structur.

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  114. Re:I'll provide a reference for a janitorial posit by Zero__Kelvin · · Score: 1

    "If my boss assigned me tomorrow to work on an ethernet driver: I would not know that."

    On the exceedingly long list of things that you dont' know, that you would need to know in order to successfully modify the e100 Ethernet driver, that is the least of your worries. For example, you don't know that you shouldn't be starting by changing the code, and that by the time you knew enough about Intel Ethernet cards to actually start changing code it would be patently obvious.

    "Rest for the other fields in that structur."

    The hilarious thing as that you started out claiming no commenting was necessary, and you are finishing up by complaining that things that need no comment are not commented. You really are a hilarious guy. Thanks for the laugh.

    --
    Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
  115. Re:I'll provide a reference for a janitorial posit by angel'o'sphere · · Score: 1

    I did not say "no comments are necessary". You put that into my mouth.

    I always said, and repeated it: classes need a comment (for the class itself and for all their fields). A huge C-struct is nothing different.
    I also said: all "public" methods of that class need to be commented (what is the method doing) and their parameters.
    A c function that is supposed to be called (in other words is public) is similar to a "method".

    Beyond that your code should be so clear that no further comments are needed. The rare exception you pointed out is something like allignment, I assume there are more.

    In your case, nearly every field of that structure is a miracle. (Yes, I can conclude a little bit from it).

    For example, you don't know that you shouldn't be starting by (1) changing the code, and that by the (2) time you knew enough about Intel Ethernet cards to actually start changing code it would be patently (3) obvious.
    1) if I see the error, I make a breakpoint there, and yes I fix it.
    2) I don't need to know EVERYTHING about e100 cards ... I only need to understand what is going wrong
    3) does not matter, and I doubt it. I fixed enough bugs in commercial systems where it was important to finds and correct the bug in hours or less

    A line like max = a b ? a : b; is obviously wrong, as "max" indicates I want the maximum. A line like m = a b ? a : b; looks right at the first glance ... you only realize later that malloc(m) allocates not enough memory.

    Sorry, the time where c variables should have arcane obscure names are over since the compilers accept identifiers that are longer than 8 bytes.

    To phrase it with some famous words: you may disagree but you would be wrong.

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  116. Re:I'll provide a reference for a janitorial posit by Zero__Kelvin · · Score: 1

    "3) does not matter, and I doubt it. I fixed enough bugs in commercial systems where it was important to finds and correct the bug in hours or less"

    ROTFLMAO. Thanks for that one. The fact that you think you can properly fix a bug in a commercial product in less than an hour makes clear exactly how firmly you fall into the clueless category. That is precious!

    "A line like max = a b ? a : b; is obviously wrong, as "max" indicates I want the maximum. A line like m = a b ? a : b; looks right at the first glance ... you only realize later that malloc(m) allocates not enough memory."

    No. A line like max = a b ? a : b; makes it clear that you can't write a single line of C code that would actually compile.

    So I've spent enough time going back and forth with you while you prove your incompetence over and over again. It is time for you to go on being happily clueless and wreaking havoc wherever you type, completely unaware of what a complete hack you are. Have a nice life.

    --
    Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
  117. Re:I'll provide a reference for a janitorial posit by angel'o'sphere · · Score: 1

    Lol,

    the only one who is clueless is you, otherwise you had guessed that the "less sign" was eaten by the slashdot html filter.

    If you consider me incompetent then come to my place and write a bit of code ;D If you would wrote code like the one you had posted you will be gone in no time.

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  118. Re:I'll provide a reference for a janitorial posit by Zero__Kelvin · · Score: 1

    "the only one who is clueless is you, otherwise you had guessed that the "less sign" was eaten by the slashdot html filter."

    Again, you prove my point. You are unable to review your post before hitting submit, and unable to use an example that will render properly to make your point. This is a clear indication that you are > (i.e. more than) incompetent.

    "If you consider me incompetent then come to my place and write a bit of code ;D If you would wrote code like the one you had posted you will be gone in no time."

    You work at a place that hires incompetents, so there is no chance I would even take the job.

    --
    Guns don't kill people; Physics kills people! - John Lithgow as Dick Solomon on Third Rock From The Sun
  119. Re:I'll provide a reference for a janitorial posit by angel'o'sphere · · Score: 1

    Well, as often as you use clueless ans incompetent it is obvious those attributes apply to you :) be happy with your constant insults ...

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.