Slashdot Mirror


If the Comments Are Ugly, the Code Is Ugly

itwbennett writes "What do your comments say about your code? Do grammatical errors in comments point to even bigger errors in code? That's what Esther Schindler contends in a recent blog post. 'Programming, whether you're doing it as an open source enthusiast or because you're workin' for The Man, is an exercise in attention to detail,' says Schindler. 'Someone who writes software must be a nit-picker, or the code won't work ... Long-winded 'explanations' of the code in the application's comments (that is, the ones that read like excuses) indicate that the developer probably didn't understand what he was doing.'"

105 of 660 comments (clear)

  1. The comment may also be complex.. by Oxford_Comma_Lover · · Score: 5, Insightful

    An explanation may be long if it is explaining something complex that the code is doing. A long-winded comment may also be a precise one, rather than a general one: rather than an excuse, this may be an explanation.

    --
    -- IANAL, this isn't legal advice, and definitely isn't legal advice for you. Also, Squee!
    1. Re:The comment may also be complex.. by Rick+the+Red · · Score: 4, Funny

      I once coded a function that varied depending on what quadrant (+x,+y; -x, +y; -x,-y; +x,-y) it was in. I couldn't get it to work right in the second quadrant, but finally got it working by chance and said so in my comments. The code worked, but I didn't understand why and said so. Is that bad coding? It worked!

      --
      If all this should have a reason, we would be the last to know.
    2. Re:The comment may also be complex.. by Anonymous Coward · · Score: 5, Insightful

      It worked!

      Are you sure about that? Did you really have enough of an understanding of the conditions to make that statement?

      Chances are, it worked in the subset of cases you understood, and maybe in the subset of cases that the app needed at the time. In the future, though, all bets are off ...

    3. Re:The comment may also be complex.. by ircmaxell · · Score: 2, Insightful

      The thing that I find a lot of developers don't understand is the difference between "Good" and "Good Enough"...

      In your example, the code you got working for -x, +y may not have been "Good", but if it passes the Unit Tests, then how is it really bad? Could it be optimized? Sure...

      Those that seek perfection are destined to a life of search. Those that seek 'working' are destined to a life of success...

      --
      If a man isn't willing to take some risk for his opinions, either his opinions are no good or he's no good
    4. Re:The comment may also be complex.. by gstoddart · · Score: 4, Insightful

      An explanation may be long if it is explaining something complex that the code is doing. A long-winded comment may also be a precise one, rather than a general one: rather than an excuse, this may be an explanation.

      I have known several people who point out that if it really does require that complicated of an explanation, you might need to re-factor your code and make it less arcane. Of course, not everything can be simplified to the point where it's obvious when you read it, but I've definitely seen a lot of code that could/did benefit from changing it to make it more straight-forward and readable.

      In general though, I agree with the article -- I've known more than a few developers who barely if ever comment code, and claim that it should be obvious from the code. As such, their comments (what there are) tend to be fairly random and not helpful. I once saw a comment that said "die lamer die" with no explanation whatsoever. "Add 1 to count" is also fairly useless.

      Me, I always write the comment for a function/method before I've started writing the body of the method. Because, even if it's just me maintaining the code, I want to know what it was there for in the first place.

      Cheers

      --
      Lost at C:>. Found at C.
    5. Re:The comment may also be complex.. by Marillion · · Score: 3, Interesting

      I've always subscribed to the theory that the code explains WHAT a program should do clearly enough that even a computer understands it.

      Comments should fill in the gaps and answer the questions of WHY and HOW. For example, if I'm using a common pattern or idiom, I like to highlight that. I like to use the Delegation Pattern when doing SAX parsing of XML in Java. Rather that explain what the Delegation Pattern is about, I'll just cite the pattern name, add a link, and explain the nuances of that particular implementation and move on.

      --
      This is a boring sig
    6. Re:The comment may also be complex.. by eln · · Score: 5, Funny

      Precisely. Comments about code that the developer himself doesn't understand, usually because he employed some nasty hack and he's not sure exactly why it worked, are usually short and contain the word "magic" in them.

      For example:

      /* Magic happens here*/
      /* Black magic */
      /* Some particularly dark black magic occurs here */
      /* I'm not sure why this works, but it does */
      /* I went on a vodka bender last night, and this was on my screen when I woke up. I don't know what it is, but it compiles, so let's ship the fucker. We'll call it Vista. */

    7. Re:The comment may also be complex.. by Abcd1234 · · Score: 5, Insightful

      The code worked, but I didn't understand why and said so. Is that bad coding? It worked!

      Yes. It's bad coding. Very very bad coding. And, no offense, but it indicates intellectual laziness on your part.

      Any developer worth their salt would spend the time to understand *why* their code is mysteriously working, rather than just throwing up their hands and moving on, as a) it might be working for your test cases but still be incorrect, and b) anyone coming along later will be hosed, as if you couldn't understand it, there's a good chance they won't be able to, either. And of course, d) any developer worth their salt *wants* to know why their code is working, simply because it's interesting and *part of their job*.

    8. Re:The comment may also be complex.. by Anonymous Coward · · Score: 3, Insightful

      That's true with anything, though. There often comes a point at which further improvements just aren't worth the effort, no matter what product you're working with. With rare exception, where tolerances in engineering are extremely slim, your work only needs to fall within the tolerances of the person you're working for.

      Now, if you're a good coder, and your code is already pretty 'perfect', that's great. Many programs benefit from optimization even if they worked satisfactorily to begin with, too. Don't expect that every program you make has to be perfect, though. Those kinds of expectations are totally unrealistic.

    9. Re:The comment may also be complex.. by Esther+Schindler · · Score: 3, Insightful

      I agree with cream wobbly that it's good prototype code but bad release code. On the other hand it's okay with me that you explained the difficulty in the comments because that fulfills the purpose: You're communicating with the next developer who looks at the code.

      If you managed to get it to work (you think, anyhow), it may still be buggy; and the "Well, I THINK so..." in the comments will be an arrow to "probable source of application meltdown" for someone who comes in to debug.

      There's a difference between writing a good explanation that happens to be long, and a rambling list of excuses. Yours sounds like the former. IMHO.

    10. Re:The comment may also be complex.. by Kell+Bengal · · Score: 5, Insightful

      I agree to a limit. My philosophy is to code the comments, rather than comment the code.

      Comments, for me, serve as a design tool as much as an aid to understanding. You can very quickly understand what my programs are supposed to do by reading the comments; not because my code is hard to understand, but because the comments describe its function as a narrative.

      Of course, if you can't understand what the code does without reading the comments, you're doing something wrong. Once coded, the comments exist to extend and clarify what the code is doing, as well as adding meta data about how things like numerical constants were calculated.

      --
      Scientists point out problems, engineers fix them
      altslashdot.org: The future of slashdot.
    11. Re:The comment may also be complex.. by characterZer0 · · Score: 5, Funny

      Unless your code is running in IE5 or IE6. Then you get it to work by chance, and do not ever touch it again.

      --
      Go green: turn off your refrigerator.
    12. Re:The comment may also be complex.. by Abcd1234 · · Score: 5, Insightful

      In your example, the code you got working for -x, +y may not have been "Good", but if it passes the Unit Tests, then how is it really bad?

      How is it bad?? Christ, the metric for "good" code isn't that it simply "works". It also needs to be readable, comprehensible, and maintainable. If you can't understand how your own code works, it's bloody obvious it fails on at least one of those metrics.

      Besides which, unless you are 100% positive that your unit test covers *all* cases, the fact that your code passes tells you nothing about it's correctness.

      You know, back in my university days, we used to scoff at the morons in the labs who would, quite literally, randomly hack their projects until they worked. I never dreamed that some would consider that a valid development methodology out in the real world. Apparently there *is* a dark side to a high-quality unit test suite... it gives idiots a false sense of security and justifies their idiotic development practices.

    13. Re:The comment may also be complex.. by Abcd1234 · · Score: 4, Insightful

      And while you're spending your time figuring out why something that isn't broken works, he is coding something that you aren't coding at all. Sure, coding until it passes isn't the ideal, but it's a whole lot better than not coding at all (you).

      Bullshit. Software development isn't just about "coding". It's about producing software that's functional and maintainable. "Hacking it until it works" is completely antithetical to those goals.

      Frankly, morons like you are the reason the industry is laughed at by other, more formalized disciplines. Could you imagine what we'd do to a bridge builder who just tacked stuff on until it kinda sorta stood?

    14. Re:The comment may also be complex.. by clone53421 · · Score: 3, Funny

      On the basis of your username, I'm perplexed as to why you somehow failed to properly letter the items of your list. Perhaps "c) ???" should have come in front of "d) Profit!" (well, a rather long and windy version of "profit", but boils down to it basically)?

      Inb4 comments about my failure to count down from 5.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    15. Re:The comment may also be complex.. by YXdr · · Score: 5, Insightful

      ... but if it passes the Unit Tests ...

      That kinda presumes that the unit tests are good, doesn't it? Which means that somewhere, somehow, somebody has to know what problem they are trying to solve.

      Defining 'good enough' is really tough. I've seen perfectionists get bogged down, but even more often, I've seen folks that invoke the 'it's good enough' mantra as a cover for sloppiness and incompetence.

    16. Re:The comment may also be complex.. by Abcd1234 · · Score: 2, Informative

      On the basis of your username, I'm perplexed as to why you somehow failed to properly letter the items of your list. Perhaps "c) ???" should have come in front of "d) Profit!" (well, a rather long and windy version of "profit", but boils down to it basically)?

      ROFL, because I'm a moron, that's why. Honestly, is that so hard to understand?

    17. Re:The comment may also be complex.. by clone53421 · · Score: 2, Interesting

      True. Furthermore, it's arguably proper, when implementing a particularly clever and streamlined hack (i.e. impossible to decipher, when debugging the code), to set it off from the code visually and then follow it with a commented-out block of code which does exactly the same thing, albeit slower or less efficiently, and which will be much easier to understand.

      As a bonus, if the code must later be changed and the original hack would no longer be possible in the new functionality of the code, the procedure has already been written in a more logical and modifiable fashion, so you can start from that rather than having to re-code it entirely on the spot.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    18. Re:The comment may also be complex.. by clone53421 · · Score: 3, Funny

      I went on a vodka bender last night, and this was on my screen when I woke up.

      I've had that happen to me a few times. It's a bit unsettling, I assure you.

      What's even more unsettling is waking up with a full plate of hash browns and eggs next to my bed, and having no recollection of ever making them. It did make for a nice breakfast, though. Perhaps I should do it more often.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    19. Re:The comment may also be complex.. by haystor · · Score: 3, Informative

      You've obviously never actually built a real world building. You'd be damned surprised at how inexact so many things are. Something may measure 12 feet on the plans, you may take a 12 foot board to place and when you get there, you'll still cut it to fit or hammer it into place. Construction, even of your vaunted bridges is filled with hacks carried out at all levels of the build.

      Software development typically isn't engineering. It's usually a business of maximizing productive features versus minimizing cost and time. Rarely is the answer to further investigate working code.

      --
      t
    20. Re:The comment may also be complex.. by mjschultz · · Score: 4, Interesting

      I've gotten into the habit of commenting first, coding second. It is especially useful in complex systems.

      I find that if I write the high level logic in comments of all the functions I'm going to write, it helps me find where I should break out repeated logic and solidifies the design. Once everything has been commented, I can go back and write the code.

      This lets me know what the variables are going to be and can name them appropriately (why name it `i` when I can call is `block_index`). I don't lose the big picture of what needs to get done. It gives me targets to meet and stopping points at the end of the day (a sense of accomplishment and goals for tomorrow is *really* nice). Future coders can read my comments and see what I was thinking (this has actually happened to me). As a bonus, I can worry more about corner cases as I'm writing the code instead of creating corner cases to worry about later.

      I've done it with a Flash memory interface, O/S memory manager, and a kernel module. Each time I've finished, even if it isn't the best code in the world, I know that if the next person reads the comments, they'll know what I was thinking.

      Better code all around.

    21. Re:The comment may also be complex.. by FishOuttaWater · · Score: 2, Insightful

      Ok, so say you want to use code you can't understand in a system. You have two choices: A - unit-test the heck out of it so you know it won't fail, which generally takes longer than understanding it, especially when it fails and you have to fix code you don't understand. B - Just integrate it with the rest of the system, hope it works, and when it doesn't, somebody else spends a considerable amount of time debugging what went wrong, tracks it down to your code, understands it, realizes whoever wrote it doesn't understand it, and relays the experience to your boss. Taking an hour to understand the thing, and perhaps another to simplify it saves lots of time and humiliation in the long run.

    22. Re:The comment may also be complex.. by tgrigsby · · Score: 2, Informative

      As a programming "old coot", I'd say that if you didn't understand why, then yes, by definition that's bad coding. You need to understand the problem before you can fully address the problem. And if the solution is complex, your comment shouldn't say, "Wow! I can't believe this worked. Good luck if you need to change it!" It should instead educate those that come behind you. Comments should be an aid to understand not only the code but the problem domain addressed by the code. It's a means of recording knowledge that the code doesn't make readily apparent.

      --
      *** *** You're just jealous 'cause the voices talk to me... ***
    23. Re:The comment may also be complex.. by Unequivocal · · Score: 4, Insightful

      And while "he" is getting called at three in morning 2 years later to fix a crazy bug that has stopped all business, due to a new use-case being introduced that mysteriously breaks that function, "you" is now coding on a new project, using sound development techniques (including understanding how code works while "you" writes it), making the company new money.

    24. Re:The comment may also be complex.. by Abcd1234 · · Score: 5, Insightful

      Construction, even of your vaunted bridges is filled with hacks carried out at all levels of the build.

      Oh please. Inexactitude is *not* the same thing as not understanding why something works at all. We can build miles-long bridges *specifically* because we understand the underlying physics, and anyone who built a bridge without understanding the physics of why it stood under load would be drummed out of the industry.

      Software development typically isn't engineering. It's usually a business of maximizing productive features versus minimizing cost and time. Rarely is the answer to further investigate working code.

      Sorry, that's crap. Any code complex enough to be difficult to understand is specifically the code that requires extra care and attention to ensure it's correct. If you don't understand why your complex algorithm works, you need to spend more time to understand it, as the odds are extremely good that it's a) not correct, and b) not maintainable.

    25. Re:The comment may also be complex.. by Anonymous Coward · · Score: 4, Funny

      And while you're spending your time figuring out why something that isn't broken works, he is coding something that you aren't coding at all. Sure, coding until it passes isn't the ideal, but it's a whole lot better than not coding at all (you).

      boss? is that you?

    26. Re:The comment may also be complex.. by Unequivocal · · Score: 2, Funny

      We ran across a classic one of these. A application we developed in 1992 stopped working in 1994 for some unknown reason. After a few days of heinous debugging to build a test case, we come across a line of code headed with this comment: /* this will not work - jr */

      We fix that line so it will work, and all have a good laugh later. At the time it was pretty frustrating as I recall. I'm still good friends with JR by the way.

    27. Re:The comment may also be complex.. by Senjutsu · · Score: 4, Insightful

      And while you're spending your time figuring out why something that isn't broken works, he is coding something that you aren't coding at all. Sure, coding until it passes isn't the ideal, but it's a whole lot better than not coding at all (you).

      Coding two routines by coincidence is not more productive than coding one routine properly.

    28. Re:The comment may also be complex.. by TheRaven64 · · Score: 4, Insightful

      And then, when someone comes up with a corner case where his code doesn't work, how much more time is he going to spend finding and then fixing the bug? And how much will his company's reputation suffer while his customers experience the bug?

      --
      I am TheRaven on Soylent News
    29. Re:The comment may also be complex.. by Dragoness+Eclectic · · Score: 5, Insightful

      I've had to maintain code originally written by people with that attitude. To put it politely, I wish they'd switched careers to something besides computer programming; it would have saved everyone a lot of work, cost overruns, budget overruns, and pissed off a lot fewer customers.

      If you don't know what the hell you're doing, you're not going to do it very well. Code that "works by accident" is very fragile and breaks easily and is a triple bitch to maintain, because if you don't know what you wrote, I have to pretty much reverse engineer it from the source code to figure out what you *actually* wrote vs. what you were supposed to write--then I usually end up re-writing it from the original requirements to do what it should have been doing in the first place, because the existing code is such a mess.

      --
      ---dragoness
    30. Re:The comment may also be complex.. by Seraphim1982 · · Score: 5, Insightful

      The reason the 2000 year old Roman bridges survive is because all the shitty ones were destroyed hundreds of years ago.

    31. Re:The comment may also be complex.. by Abcd1234 · · Score: 3, Informative

      Also known as survivorship bias.

    32. Re:The comment may also be complex.. by seizurebattlerobot · · Score: 2, Funny

      Sir, your attitude is a breath a fresh air. Any programmer who doesn't submit a formal and rigorous proof of every algorithm they write to a peer reviewed academic research journal is an incompetent hack who couldn't program his way out of a cardboard box.

      Programmers who pick and choose their development practices based on the specific requirements of the project at hand are ignorant fools who reduce the beautiful and perfect art of programming to a mere act of common labor. It's disgraceful, I tell you!

    33. Re:The comment may also be complex.. by ardle · · Score: 2, Insightful
      If the poster could have got the code working in all cases, rather than (apparently) some special case, do you not think he would have written the best possible code and not added a comment to say otherwise?
      I think you are following a "false" (i.e. unlikely enough to be a bit absurd) argument here.
      And hats off to the coder with humanity enough to make other coders' jobs easier if things should get to the point of having to fix said code: at least we know where to look first.

      First they came for the project managers...

    34. Re:The comment may also be complex.. by sjames · · Score: 2, Insightful

      There's a huge difference between 16 inches on center being more like 15 to 17 in practice and having no idea why the building won't fall down. As long as the engineer KNOWS for a fact that the building will be fine at 18 inches OC, it's not a problem. He can only know that for a fact if he knows how the load distributes and how strong the materials are. He doesn't get to just have it slapped together any old way and then try it differently if it falls.

      The various hacks in building are just compensations for things not being built to perfection. Not understanding the code is like having no standard to measure against.

    35. Re:The comment may also be complex.. by Alanbly · · Score: 3, Funny

      Do not try to understand the "why" of IE6, that's impossible, simply try to realize the truth. There is no "why." Only then will you see that it is not IE6 that conforms but only your code

      --
      -- Adam McCormick
  2. Comments are good by Anonymous Coward · · Score: 5, Insightful

    Comments are good for many reasons:
    1. Showing the next person what you were doing.
    2. When you have to explain what you are doing, it helps you to discover possible errors in your code. Particularly logic errors.
    3. It helps you if you have to come back and look at it in a few years so you will immediately have an explanation of what you were doing.

    Of course for those of us who code perfectly the first time, they aren't really needed. :-)

    1. Re:Comments are good by e70838 · · Score: 5, Insightful

      Comments shall be avoided as much as possible :
      1) the code shall be simple and the name of variables and methods shall be self explanatory in most cases. When this is applied, there remains very few to explain at the code level. The reader of your code is not dumber than you (except when he is your boss).
      2) the more you add comment lines, the less lines of code you can see on your screen. When you start scrolling continously, the speed of code production reduces significantly.
      3) comments introduce a redundancy. What shall be trusted when code and comment differs. Is the code wrong or the comment outdated ?
      4) comments in the code are often used as a substitute for a global software architecture description. In the example of the java api documentation, it is very hard to get a global view of a class with only class comments, we need additional documentation (the tutorials).
      Joke apart, code often contains many comments because it shall comply to quality standards, but strangely, the parts of the code that are difficult to understand are generally not commented. It is a variant of Murphy law that is very useful when auditing code.

    2. Re:Comments are good by clone53421 · · Score: 4, Insightful

      the first thing I do is delete the comments. I don't care what this person *THINKS* the code does, I only care what the code REALLY does.

      *rolls eyes*

      I, on the other hand, think it would be valuable to know if and when the person writing the original code *THINKS* the code does something which, in fact, it does not.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    3. Re:Comments are good by digitig · · Score: 2, Insightful

      Comments are good for many reasons: 1. Showing the next person what you were doing. 2. When you have to explain what you are doing, it helps you to discover possible errors in your code. Particularly logic errors. 3. It helps you if you have to come back and look at it in a few years so you will immediately have an explanation of what you were doing.

      4. Cross-referencing the specification, for reverse traceability.

      Of course for those of us who code perfectly the first time, they aren't really needed. :-)

      Requirements never change, do they?

      --
      Quidnam Latine loqui modo coepi?
    4. Re:Comments are good by Fred+Ferrigno · · Score: 2, Funny

      Of course the person who wrote the code *THINKS* the code does something which, in fact, it does not

      Sure, but it's helpful if they tell you what they think it does, in detail. If you're lucky, you can ask them and they might remember. Or they could just write it down once somewhere convenient. Perhaps it might be stored along with the code.

    5. Re:Comments are good by Rubinstien · · Score: 2, Interesting

      Comments are a form of redundancy, usually only figuratively, but sometimes for real.

      I once was hired to rewrite some old code from the late 60's or early 70's from OCR'd screen dumps. The mainframe system it ran on had been taken off-line, and wasn't being brought back since the company gave early retirement to anyone who knew anything about it. There was a mix of COBOL, FORTRAN, SAS, JCL, etc. I was rewriting in C (mostly just the numerical stuff that had been written in FORTRAN). No one at the company understood what the code actually "did", but they wanted to duplicate the reports that it produced, exactly. I eventually did enough research to completely understand everything except for a single routine. It was all based on table lookups; tables that were generated based on mathematics derived by a researcher in Canada that were "unpublished." I could find several Bell Systems Journal articles that referenced this paper, but could not find the paper or the math anywhere. My sister in law, a research librarian, even located the author for me and I wrote to him, but he never replied. I knew there were problems with the data in the tables, from the obvious OCR errors like ones replaced with L's, zeros with D's, etc. I wanted to regenerate the tables myself (tables were being used for speed) in order to ensure they were accurate. Eventually, I had to bite the bullet and just use what I had. Fortunately, besides referencing the journal articles containing the original math the tables were generated from, the comment contained a complete commented out copy of a prior version of the function. Before it was moved to IBM hardware in the mid-70s, the original code ran on a CYBER something, and the FORTRAN compiler indexed and initialized multi-dimensional arrays in a different order. I wrote a Perl script to flip the entries in these arrays around to the "new" order, and compare table entries, marking any discrepancies. From the list of discrepancies, it was easy to determine what the OCR error patterns were, allowing me to derive the original table. I still felt uncomfortable, and eventually got the customer to get me a hard copy of the original screen dump used for the OCR process. I was able to verify my results from that.

      The ultimate test was ensuring that input from the same data produced output that exactly matched the original output for the same data. This lead to finding and having to work around a bug in AIX's math libraries, but I eventually got there.

      In doing that project, the original author's copious comments were *indispensable*.

  3. Co-workers by Tomun · · Score: 5, Insightful

    Long-winded 'explanations' of the code in the application's comments (that is, the ones that read like excuses), indicate that the developer probably didn't understand what he was doing.'

    Or that he's forced to work with people that don't.

    1. Re:Co-workers by garcia · · Score: 5, Insightful

      Or he's being a good employee and doing the right thing to ensure:

      1. One to three years from now when the code needs to be revisited by him that he can quickly assess the code without thinking about it too much.

      2. Long after he's gone another employee can come across the code and easily understand what was done and why.

      3. Comments, to me, are like writing out all the steps in a math problem. Just because you arrived at the correct answer on the face of things does not mean that you understood what you did. Documentation proves, in many cases, that you did in fact know what the fuck you were doing.

      --

      If you don't like comments, fold them out of the way and be done with it. I just don't see the problem here.

    2. Re:Co-workers by ari_j · · Score: 5, Funny

      I always write long comments that either have no relation to the surrounding code or tell outright lies about it.

    3. Re:Co-workers by Anonymous Coward · · Score: 2, Insightful

      Comments need maintained. If I change your code but don't think to change your long-winded comment then the next person may read your comment and not realize that it is out of date. If you had left a one-liner right where I was making the code change I probably would have seen it and modified it correctly.

    4. Re:Co-workers by Carewolf · · Score: 3, Funny

      I always write long comments that either have no relation to the surrounding code or tell outright lies about it.

      Did you by any chance write ALSA? And did you write your long deceitfull unrelated comments in an APIDOX compatible format which later got published as a sort of documentation?

      Because that.. would explain so much...

    5. Re:Co-workers by Thing+1 · · Score: 2, Interesting

      I find when I'm implementing a complex algorithm, I'll write out a fairly long-winded comment that explains, in prose, what the code is doing, and then in the code itself, I'll include comments for the trickier bits. I do this because I find that a bunch of small comments in a routine is harder to conceptualize, as you have to assemble the global picture yourself

      One of the things I prefer doing, in fact, is to write out a series of "steps" that I intend to do in comment form, one per line (perhaps multi-line), e.g.:

      # 1. Initiate communication with database
      # 2. Does the schema exist? If so, goto 6
      # 3. Configure the schema
      # 4. Upload initial template
      # 5. Configure initial node
      # 6. Add the node we're working with
      # (etc)

      Then, in the code that I'm working on, I copy each of the above comment lines, and then fill in the code in between.

      I find that this gives a great overview, with an easy-to-parse view of how it happens. And, if someone changes one set of comments without another, it's a great clue to the future maintainer to review the source control history because I would never initially write mis-matched comments.

      Or maybe I would, but then, I rarely code maliciously. :)

      --
      I feel fantastic, and I'm still alive.
  4. comments explain what isn't there by Russ+Nelson · · Score: 3, Insightful

    Comments exist NOT to explain the existing code, but to explain all the other code that could have been written, but wasn't. They also point to things like test cases (which if your language doesn't suck, you can put in line), and explanatory standards documented elsewhere.

    --
    Don't piss off The Angry Economist
  5. bad spelling in variables/etc get me by i.r.id10t · · Score: 3, Insightful

    For me, it is bad spelling in variables and such. Or correct but "alternative" spellings - like honor_no_cache vs. honour_no_cache

    Working with fellow students in a group (with one student being from England) brought this out, and in general poor spelling - category vs. catagory, etc.

    Fortunately mostly fixable with find/replace, but still a bear to deal with.

    --
    Don't blame me, I voted for Kodos
    1. Re:bad spelling in variables/etc get me by Mr.+DOS · · Score: 2, Informative

      America isn't the only country in the world. In England and Canada, "honour" is the correct spelling and "honor" is the "alternative" spelling.

            --- Mr. DOS

  6. Seems reasonable by jgtg32a · · Score: 5, Interesting

    Comments do require a bit of effort and time commitment. If you are willing to spend time on the comments your most likely going to spend more time working the code itself.

  7. // teh code is obvius by tedgyz · · Score: 4, Funny

    Comments are for wimps.

    --
    "No matter where you go, there you are." -- Buckaroo Banzai
    1. Re:// teh code is obvius by StripedCow · · Score: 2, Insightful

      Hey, thanks for making that comment!

      --
      If Pandora's box is destined to be opened, *I* want to be the one to open it.
    2. Re:// teh code is obvius by JohnnyLocust · · Score: 2, Funny

      /* Comments are for wimps. */

  8. Long-winded comments can be very useful by JoshuaZ · · Score: 5, Insightful

    I sometimes write code for number theory algorithms. Often short-cuts and little speed ups have long proofs to justify why they work. If I expect the code to be used/read by other people I'll often include these explanations (and so I don't need to bother convincing myself later if I look at the code a year later). There's nothing wrong with long comments. Moreover, given a negative attitude towards long comments, many bad programmers will likely simply respond by not commenting their code at all. That's not good.

    1. Re:Long-winded comments can be very useful by dkleinsc · · Score: 3, Interesting

      Often better than including the full explanation inline is: "Proof that this works can be found ...". Yes, it's one more reference to look up, but some of the algorithms in, say, Knuth, are long and complex proofs that really will interrupt your code reading if included inline.

      A lot of good comments answer one of these questions:
        - Why couldn't this be simplified?
        - What special case is this trying to handle?
        - This looks weird. Why is it right?
        - What expectations are we demanding from elsewhere in the code?

      A situation where I find myself asking any of those questions and no comment is present can be nightmarish.

      --
      I am officially gone from /. Long live http://www.soylentnews.com/
    2. Re:Long-winded comments can be very useful by darthflo · · Score: 2, Insightful

      Linked stuff has an annoying tendency to not be available when you most need it, be it expired domain names, dying servers or even reading the comment in a WiFi-less coffe shop. Cited books tend to only be available in a different edition than referenced.
      But the solution's quite simple: GP, keep on commenting as long as necessary. IDEs and even rather simple editors have allowed coders to collapse comment blocks for several generations now. Long comments are no problem.

  9. Well, duh. by mobby_6kl · · Score: 4, Funny

    That's also why I don't comment my code.

    1. Re:Well, duh. by gstoddart · · Score: 2, Informative

      This is a good practice. Comments very seldom keep up with changes in the code base, so more often than not, they end up being misleading at some point in the future.

      That is not the fault of the practice of commenting code. That is the fault of lazy-assed developers who don't maintain the comments.

      The reason people think they need to cluster bomb their code with comments is generally because they have a degree in CS, and CS classes often require such code.

      That's like saying engineering is rigorous because the profs insisted on it so it has become a habit. It is rigorous for another reason -- in this case, a lot of experience has shown that overall, commented code is easier to maintain. It is exceedingly rare to see code which is only ever maintained by one person over its lifetime; if you've ever tried to fix a Steaming Heap of Innovative Technology which is utterly un-commented you might see why people insist on it.

      I've worked on a lot of different code bases over the years, and most of the originally written by other people. I've seen developers let go because they didn't/wouldn't comment their code (well, that was part of the reason). The manager was a former coder, and expected that if you're working in his code base, you're going to adhere to his rules. Those included commenting code and adhering to standards. Failure to comment meant you were only doing about half of the job.

      Not commenting code, and not keeping the comments up to date as the code changes is a very good indicator that the coder in question isn't doing his job as thoroughly as required. If you write software for a living, it really is a weak excuse to say that comments aren't helpful and tend to be out of date over time -- that's pretty much a circular argument since the reason the comments aren't helpful/accurate is because people haven't maintained them.

      Cheers

      --
      Lost at C:>. Found at C.
    2. Re:Well, duh. by tgrigsby · · Score: 2, Insightful

      >> That's also why I don't comment my code.

      This is a good practice. Comments very seldom keep up with changes in the code base, so more often than not, they end up being misleading at some point in the future.

      That's complete crap. I've heard this argument before, that by not putting in comments you force the next guy to read all the code. That of course assumes that your code is so clean, obvious, and readable that the next guy will be smitten with your mad skillz.

      I would say that it's a reliable indication of extreme ego and lack of skills when a programmer eschews comments entirely.

      Comments serve as an aid to understand not only the code but the problem domain addressed by the code. It's a means of recording knowledge that the code doesn't make readily apparent. Reticence to comment indicates laziness and perhaps even a lack of understanding as to why the code worked in the first place.

      --
      *** *** You're just jealous 'cause the voices talk to me... ***
  10. Sounds right by TheRaven64 · · Score: 2, Funny

    It should be obvious what the code is doing just from reading it. If it isn't, then the code should usually be refactored. Comments are for explaining why the code is doing that. If your grammar is poor in the English then it's probably poor in the code too (unless you are not a native speaker). If you make spelling errors in comments then you probably do in code too. The compiler will catch some of these, but when you accidentally type the name of an instance variable or a global instead of a local, it won't spot it. If you're not checking your comments for this kind of error, you're probably not checking your code for it either.

    Just as with online comments, poor grammar displays a lack of care. Hopefully, more people will be reading your comments than will be writing them. A little effort in writing them can save a lot of effort in reading them. If someone on the Internet thinks that their time is worth so much more than their readers' time then that just makes them an asshat[1]. If a programmer thinks his or her time is so much more valuable than that of people maintaining the code then he or she is a terrible programmer.

    [1] I am fully aware of the universal law that means that, by writing this, my post will have a significantly above average number of typos. Please be nice...

    --
    I am TheRaven on Soylent News
  11. Comment removed by account_deleted · · Score: 2, Insightful

    Comment removed based on user account deletion

  12. Non-native English speakers by AmiMoJo · · Score: 4, Insightful

    English is not most people's first language. Be glad they want to write comments in English at all.

    --
    const int one = 65536; (Silvermoon, Texture.cs)
    SJW, n: "Someone I don't like, and by the way I'm a fuckwit" - AC
  13. Doesn't work by Yvan256 · · Score: 2, Funny

    I always try to comment my code, but then the compiler keeps telling me there's no code to compile.

  14. I'm an expert! by monkeySauce · · Score: 5, Funny

    "Long-winded 'explanations' of the code in the application's comments (that is, the ones that read like excuses), indicate that the developer probably didn't understand what he was doing.'"

    That's right, I'm an expert and I keep my code comments short and sweet. Observe:

    // This function kicks ass.

    function kick_ass()
    {
    ...

    // This following code is like Chuck Norris. It doesn't know how to fail.

    while(true)
    {
    ...

    1. Re:I'm an expert! by clone53421 · · Score: 3, Funny

      You forgot ass_needs_kicked = true and while(ass_needs_kicked).

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
  15. Yes, that's bad coding by Frequency+Domain · · Score: 5, Insightful

    I once coded a function that varied depending on what quadrant (+x,+y; -x, +y; -x,-y; +x,-y) it was in. I couldn't get it to work right in the second quadrant, but finally got it working by chance and said so in my comments. The code worked, but I didn't understand why and said so. Is that bad coding? It worked!

    If you don't understand why it worked, then you don't know how it worked. Consequently, you have no idea under what circumstances it won't work. Unless your unit tests enumerated every possible set of inputs, you don't actually know it worked. Just because code works for some inputs doesn't mean it works.

  16. Comment removed by account_deleted · · Score: 4, Informative

    Comment removed based on user account deletion

  17. I agree, with reservations by JustNiz · · Score: 4, Interesting

    From 30 years of developing software, I've found time and time again that it actually does seem that people who don't know or care about the difference between "their" and "they're" are also too sloppy, unintelligent or just not anal enough to write clean, supportable and robust code.

    However I feel we do need to make more allowance than the article's author did for people who did not learn English as a first language.

    1. Re:I agree, with reservations by NoYob · · Score: 2, Insightful

      From 30 years of developing software, I've found time and time again that it actually does seem that people who don't know or care about the difference between "their" and "they're" are also too sloppy, unintelligent or just not anal enough to write clean, supportable and robust code.

      However I feel we do need to make more allowance than the article's author did for people who did not learn English as a first language.

      I'm impressed - 30 years! Wow!

      In my measly 15 years of experience, I've had to spend many long hours meeting deadlines that some salesman made for us to make the sale. Of course, management backed up the ridiculous deadline because "if the salesman didn't say it could be done, some other company would have and we wouldn't have had the business!' So, said salesman makes his 6 figure commission and us coders are working 80+ hours a week to meet the ridiculous deadline - which happens frequently. Now, when I'm tired, fearing for my job, and trying to design and code on top of all that, the last thing I'm worried about is making sure I don't confuse "they're" with "their" or with "there". I'm worried about being productive, because if I'm not, they'll send the work to a country where they don't even speak English; let alone actually even bother to comment their code.

      Personally, I'd rather have something than nothing; regardless of how poor the spelling is or the grammar. It's a software comment, not a dissertation.

      But that's been my measly newbie experience.

      --
      It's NOT me! It's the meds! I'm on 1000mg of Fukitol.
  18. Existence of Comments by travdaddy · · Score: 3, Funny

    If comments even exist, then the code is ugly. Code should document itself.

    (Any good Perl programmer knows this.)

    --
    Adidas To Bring Back Sneakernet
  19. How much code is written by outsourcing? by dejanc · · Score: 2, Interesting

    I work for a company in Serbia and we write code for an Italian corporation which also outsources their development to Brazil and India. I'm happy if comments are in English at all. Still, we get by just fine, as long as we agree on design patterns to use and writing clear and concise code. Also, whatever happened to: "Comments should describe what the function is doing, not HOW it is doing it"?

  20. Re:Job Security by kschendel · · Score: 2, Interesting

    Yeah, good luck with that. Have a second career ready?

    I once consulted on a large program that had been written in as convoluted a manner as possible, with few or no comments. The guy who wrote it used to brag about "job security". Well, when the company finally allocated a budget to replace the program, they not only fired the guy, but made sure that as many people in that industry as possible knew about it. He was unable to find a new job in programming, and last I heard, he was trying to sell cars somewhere down south.

    You might have job security for a while, but it's gonna catch up with you.

  21. Forced to use Bad API by Baby+Duck · · Score: 2, Insightful

    If I have a long comment explaining "magic", 99 times out of 100 it's because I'm being forced to interface with a bad API which THAT CODER didn't properly understand. Glaring errors in the documentation, unexpected outputs, unexpected hangups ... these are my duty to comment about. Of course I don't understand why the API is malfunctioning ... it's a BLACK BOX. My employer might be too much of a cheapskate to purchase product support to troubleshoot the API. Or the vendor might charge outrageous support fees for their mess ups. I cannot switch to a different API, because I do not have the authority to make that decision. My comments are self-defense when backed up against the wall. It does nothing to gauge my programming ability.

    --

    "Love heals scars love left." -- Henry Rollins

  22. You are not expected to understand this by wandazulu · · Score: 4, Funny

    The granddaddy of WTF comments must come from the original Unix source, written by none other than Dennis Ritchie: /*
              * If the new process paused because it was
              * swapped out, set the stack level to the last call
              * to savu(u_ssav). This means that the return
              * which is executed immediately after the call to aretu
              * actually returns from the last routine which did
              * the savu.
              *
              * You are not expected to understand this.
              */
            if(rp->p_flag&SSWAP) {
                    rp->p_flag =& ~SSWAP;
                    aretu(u.u_ssav);
            }

    So here's an example of a comment that does an excellent (I assume) job of explaining why the code is doing what it's doing, yet the whole thing is so complicated that Ritchie even needed to acknowledge that the comment probably wasn't going to be of much help either with an amusing, and now somewhat famous, statement.

    1. Re:You are not expected to understand this by gstoddart · · Score: 2, Insightful

      So here's an example of a comment that does an excellent (I assume) job of explaining why the code is doing what it's doing, yet the whole thing is so complicated that Ritchie even needed to acknowledge that the comment probably wasn't going to be of much help either with an amusing, and now somewhat famous, statement.

      In fairness to Ritchie, he was programming on bare metal and breaking new ground. OS level code talking directly to hardware can get pretty grotty because of all of the vagaries that can be going on that aren't readily apparent without the device manual and some experience.

      At least he did comment it, and there was enough information in there to at least give context for what he was doing.

      Cheers

      --
      Lost at C:>. Found at C.
    2. Re:You are not expected to understand this by syousef · · Score: 2, Informative

      So here's an example of a comment that does an excellent (I assume) job of explaining why the code is doing what it's doing, yet the whole thing is so complicated that Ritchie even needed to acknowledge that the comment probably wasn't going to be of much help either with an amusing, and now somewhat famous, statement.

      Sorry but that is just a piss poor comment and there is no excuse for glorifying it. If it's that complex, he needs to refer back to a particular section of a particular version of a design document. If there is no design document one needs to be written. There are times when what you're doing is so complex that the only sane option is to refer to more extensive documentation rather than try to explain it inline. That is not an excuse for a supposedly witty cryptic comment.

      --
      These posts express my own personal views, not those of my employer
    3. Re:You are not expected to understand this by syousef · · Score: 2

      I hope I never work with or have to deal with code from whoever thought that was flamebait.

      --
      These posts express my own personal views, not those of my employer
    4. Re:You are not expected to understand this by mallowman · · Score: 2, Informative

      The first C compilers/linkers would only look at the first 8 characters of identifiers to determine equality. That kind of limits the sort of names you could use in a OS sized code-base and still maintain uniqueness. I'd say it was better to keep all identifiers under 8 characters than to risk the possibility of unintended ambiguous names.

  23. Re:10 PRIN "WTF" by smooth+wombat · · Score: 3, Funny

    The only difference is that a lot of bugs are obvuous,

    Yes, yes they are.

    when the code fails to run or runs is an unexpected way, while the bad comments won't stop the code from working, only from being understood.

    It took a bit, but your comment is understood.

    --
    We will bankrupt ourselves in the vain search for absolute security. -- Dwight D. Eisenhower
  24. Or a management failure by Moraelin · · Score: 3, Interesting

    Or it could be just an indication of a management failure.

    A couple of years ago I was brought in to save a project that was hopelessly behind schedule and getting nowhere. Pretty quickly I got the idea that whenever I check something into CVS, it gets re-checked by a really helpful girl there, richly decorated with comments. (Now I do comment classes and methods extensively, as well as places where higher elven magic was used, but I do _not_ write stuff like that now I'm iterating through a node's children. If you need a comment to understand that "for" loop, then there's something deeper wrong with my code.)

    But, anyway, stuff like a line that said "if (currentNode.isRootNode())" had been decorated with the obviously helpful comment "// when the current node is the root node". I'm still at a loss as to what extra info is conveyed by that comment, since just reading the code out loud gets you almost the same sentence and definitely the same meaning.

    And it went like that for every single line. Every single assignment, trivial loop, etc, was dutifully duplicated in that line's comment.

    Turns out, they were asked to comment their code extensively, and judged basically by quantity. So she was just abiding by the rules.

    --
    A polar bear is a cartesian bear after a coordinate transform.
  25. An addition by wandazulu · · Score: 2, Informative

    Dennis Ritchie has a whole page of comments in the Unix source code, and what information they convey.

  26. OT on long comments by FrankSchwab · · Score: 5, Interesting
    Being as this is devolving into a discussion of long comments, rather than a discussion of whether mispellings in comments indicate a lack of attention to detail in coding, I thought I'd throw in something.

    To maintain some sense of topicality: I don't particularly agree with the blog post. As someone with good English skills, I've read a lot of code where the English language skills (and thus spelling and grammar in the comments) of the coder are below mine, but their skills in the computer language at issue are superior to mine. Frankly, there's a far greater relationship between accuracy of the comments (do they actually describe what the code does) and the quality of the code, than there is between spelling, subject-verb agreement, and number of spaces after a period and the quality of the code. This relationship does follow the blog author's contention about coders needing to be nit-pickers.

    Occasionally in my coding, I write a novel in the function header. Generally, this isn't because I don't understand the problem so much as its because I do understand the problem. I've spent hours or days understanding the problem, and the particular necessray function that implements the solution, and I don't relish spending hours or days 6 months in the future remembering what I know today. The interesting thing is that, most of the time, the novel is multiple times larger than the function - 50 lines of comment for a 20 NCLOC function isn't unheard of.

    In my specialty (embedded systems, with especially tight hardware integration), there are functions that need to be written that deal with extraordinarily complex situations. Many times, the bare code tells a misleadingly simple tale - "do this, that, and the other thing", rather than (as Russ Nelson pointed out above)

    but to explain all the other code that could have been written, but wasn't

    . Oftentimes, the novel is there to explain all the ways to trip up in this 20-line function - e.g. unspecified hardware dependencies, subtle system dependencies, unobvious race conditions. Sometimes its there to explain why, no matter how wrong the function appears, it is actually correct.

    --
    And the worms ate into his brain.
  27. Tästä voit hakea sanan kategorian (avain by SombreReptile · · Score: 3, Funny

    I cut text from Finnish language websites and paste it in as comments. I don't know what it says, but it looks really cool.

  28. Author is a Drama Queen by Tablizer · · Score: 2, Insightful

    Everybody has their little "pet signposts" that they use to make wider conclusions. Although there may be small truths to some of them, relying on weak correlations is generally a dangerous way to make conclusions. Good programming involves a wide variety of skills. To focus on a few narrow factors does a disservice to this fact.

    For example, I sometimes put in long comments because the business rules themselves are convoluted. Programming logic cannot make a silk purse out of a sow's ear. Ugly biz rules are ugly biz rules and are not explainable in just a few lines. It's outside of the scope of my duties to clean up the business practices (other than pointing them out sometimes).

    I agree that long comments can serve as a yellow alert to stop and think. But that does not mean that all long comments are inherently a sign of flawed code. The author is being a drama queen via exaggeration. And perhaps it's part piety: I am a careful comment-speller, so you should be also.
         

  29. Comments are for future maintainers by cwills · · Score: 3, Interesting
    The whole purpose of comments is to explain the code so that future maintainers (including the author of the code) can easily understand what is going on. If done right, a maintainer can pick up a module and come up to speed as to what the code does, why it does it, and any thing else that might trip them up. Comments need to capture the developers thoughts from when the code was being designed and written. The reasoning and ideas behind an algorithm that took several months to design cannot be truly captured with a 3 line comment and 25 lines of code.

    I feel that comments can be broken into four types:

    1. Boiler plate front matter. These are the comments that are required by the coding standards of the shop. Usually contains copyright notices, author's name, list of changes, etc.
    2. Specification and reference comments. A list of the external references, such as the formal specification for the code, a bibliography for the algorithms used, etc.
    3. Block comments. These should describe the intent of a larger block of code. The reader should be able to take all the block comments from a program and have a good understanding what the entire program does. Block comments should describe the what and why. Block comments should also describe any gotchas, or special conditions that the maintainer needs to be aware of.
    4. Line comments. Should describe the purpose of a small number of statements. Line comments should not merely echo the action of the code itself, but describe what is happening and how the particular action relates to the rest of the program.

      i += 4; /* Increment i by 4 */ BAD comment

      i += 4; /* Ignore the first 4 fields */ Better

  30. Bill Watterson put it so eloquently by Anonymous Coward · · Score: 2, Funny

    http://74.125.93.132/search?q=cache:6l-STbmY0DkJ:www.gocomics.com/calvinandhobbes/1993/07/28/+site:www.gocomics.com/calvinandhobbes/1993/07/28/&cd=1&hl=en&ct=clnk&gl=us (sorry, Google cached copy because the website is weird)

    CALVIN: "Dad, what's a control freak?"
    DAD: "That's what lazy, slipshod, careless, cut-corner workers call anyone who cares enough to do something right."
    CALVIN: "Am I in the presence of their king? Should I kneel?"
    DAD: "If anything works in this world, it's because one of us took charge."

  31. Commenting, Like programming is an Art by AxDx · · Score: 2, Informative

    Commenting well in a program can be the difference between hours of backtracking, reverse engineering, and other wastes of time. Even if the original programmer is the only one who will ever see them, good comments are just as important as good code. I don't know about you guys, but I find myself having to go back to something I did months and even years ago. Comments make the total difference between a quick add-on/fix or hours of hair pulling frustration. Learn to Code, then learn to comment. That combo is unstoppable

  32. if you are coding in microsoft land by circletimessquare · · Score: 2, Insightful

    you often wind up using certain functions heavily that reveal themselves to have strange quirks

    since these functions are effectively black boxes that your average developer has no legal ability to understand deeper, you have to leave it at that

    blaming the coder for being unable to know why something works in such a situation would be fundamentalist in attitude on your part

    yes, you should understand everything you write in code, but you also need a job to put food in your mouth and a roof over your head. not everyone can be a greybeard learning the deep zen of a true coder in a completely open source environment

    you should therefore show some leniency for the journeyman programmer trying to pay his bills, who has to work with black box functions under deadline out of necessity, not choice

    in such a situation, it is perfectly reasonable to hack at the code until it works, then quietly walk away, unable to know why you made it work. in microsoft land, since the functions you are working with are closed source, you can't blame the programmer for this status quo

    --
    intellectual property law is philosophically incoherent. it is your moral duty to ignore it or sabotage it
    1. Re:if you are coding in microsoft land by Abcd1234 · · Score: 2, Insightful

      you often wind up using certain functions heavily that reveal themselves to have strange quirks

      since these functions are effectively black boxes that your average developer has no legal ability to understand deeper, you have to leave it at that

      Ah, external dependencies are a very different thing, though.

      If I'm coding against an external library, and it behaves unexpectedly, there's little I can do but to document the issue, explain that the code is written to work around a mysterious library bug, and move on, understanding that what I've produced may be brittle going forward.

      But we're not talking about external dependencies, here. The OP simply wrote a piece of code he didn't understand. And that's a problem.

  33. Coding Drunk by twmcneil · · Score: 2, Interesting

    I usually comment much more (and need to) when I'm coding drunk. That also explains the excessive use of the word "Fuck" in my comments. But even drunk, I know the difference between their, there and they're.

    --
    "The ferrets, they're every where I tell you!"
    1. Re:Coding Drunk by sanosuke001 · · Score: 2, Interesting

      A professor I had in college said that the best time to code is when you have a few beers in you and that if we weren't a freshmen class he'd hold our class at the local bar.

      Such a cool teacher... and the Computer Science head now...

      --
      -SaNo
  34. Re:Nonesense by clone53421 · · Score: 3, Funny

    In addition, some of us write comments first and then fill in the code. Often, in fact quite often, the code evolves past what the comments say.

    You. Are. Doing. It. Wrong.

    If the code evolves, fix the comments. Unless you're deliberately trying to confuse the next person who gets the pleasure of maintaining your code...

    --
    Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
  35. Blame Game by mpapet · · Score: 2, Insightful

    Frankly, morons like you are the reason the industry is laughed at by other, more formalized disciplines. Could you imagine what we'd do to a bridge builder who just tacked stuff on until it kinda sorta stood?

    Easy on the self-righteous indignation. I'll stay with your bridge analogy.

    The simple truth is there are few software industry segments written to your 'bridge building' requirement. You want maintainable software. Your boss wants maintainable software. At the C-level meetings, they want faster and cheaper.

    Nowhere in "faster and cheaper" is there room for your mythic "formalized discipline." I'm not sure if you are after the kind of societal reverence a doctor or lawyer gets or what. If that societal respect is you want, get a JD.

    Best case scenario, you are well-known and respected by your peers and the person to whom you report.

    --
    http://www.maxineudall.com/2010/02/should-economists-be-sued-for-malpractice.html
    1. Re:Blame Game by Abcd1234 · · Score: 5, Insightful

      Nowhere in "faster and cheaper" is there room for your mythic "formalized discipline."

      Wait... suddenly understanding your own code is "formalized discipline"? Might I suggest your standards are simply too low? Because, in my mind, understanding your own code is in the category of "basic competency".

  36. Roman Bridges by Dragoness+Eclectic · · Score: 5, Interesting

    Oh please. Inexactitude is *not* the same thing as not understanding why something works at all. We can build miles-long bridges *specifically* because we understand the underlying physics, and anyone who built a bridge without understanding the physics of why it stood under load would be drummed out of the industry.

    I am assuming you refer to the modern physics that we are all so proud of. Let me tell you that in Europe, whenever you get a real serious flooding on a major river, only one kind of bridge survives with no bruises at all: Roman bridges. They are 2000 years old, but they're still up. The crap we're building today won't be up in 2000 years, I can bet on it. Look at the mess with the bay bridge, down twice in 50 years!!!! Ah ah ahah! Kuddos to modern engineering.

    That would be because the Romans had some engineering, but not the equations we have today, so they over-engineered their bridges for safety because they knew they couldn't calculate the exact, optimal configuration for the expected loads and stresses. Over-engineering is a good thing if you don't have to account to the bean-counters. The George Washington Bridge across the Hudson River was also over-engineered because they didn't know the exact tolerances, and it has held up rather well.

    --
    ---dragoness
  37. Re:Real Programmers... by NotBornYesterday · · Score: 4, Funny

    Beauty is only GUI-deep,
    but Ugly goes straight to the code.

    --
    I prefer rogues to imbeciles because they sometimes take a rest.
  38. syntactic and logical perfection can be crap by lophophore · · Score: 4, Insightful

    Perfectly working, syntactically and logically correct code can be utter crap if it is not maintainable.

    Years ago, a very smart man told me that I was not writing code for the compiler, I was writing code for the next poor slob that had to work on it. Let's face it, most source code is going to be subject to rework or maintenance over its life span, so let's do what we can to make that next developer productive. The key to this is reasonable commenting.

    One of the best ways I know of to teach developers to write maintainable code is to have them do support and maintenance for a while. Developers learn quickly which styles work for maintenance, and which ones don't.

    As far as I am concerned, source code needs to look good as well as compile. So I would go one step beyond TFA to say that style, indentation, proper symbol names, use of constants where appropriate, and (yes) proper commenting are all good indicators of quality in source code.

    --
    there are 3 kinds of people:
    * those who can count
    * those who can't
  39. Re:Real Programmers... by TheCarp · · Score: 2, Interesting

    I don't fully agree... however, I do think its sometimes true.

    Often, one of the ways I know that my code is pretty good and well organized is that I find few places
    where comments would even be helpful. Often the comments just end up deliniating sections so I can skip to them easily "// check parameters ... // setup the connection... // submit queries ... // check return values"

    Of course, are we counting the comments that document what a function does? As I have been mostly playing with Java lately, the javadoc comments for documenting methods seem to be another beast entirely.

    I was always a fan of the Linux Kernel coding style statement that if your code is too complex to be understood by a less than gifted high school student, then you should consider rewritting it.

    -Steve

    --
    "I opened my eyes, and everything went dark again"
  40. The reality... by TemporalBeing · · Score: 2, Interesting

    The reality is that comments tell what the code ought to do; while the code only shows what it actually does.

    I tend to write comments of varying lengths - sometimes, writing longer comments not for my own benefit, but for the benefit of the next coder - someone who may or may not have my understanding of the system or code; and more likely than not, either won't have the time to learn the code 100% in-and-out, or are not up to the same par. So sometimes, I will write a large comment block on an important thing in the code - so that they (whoever they are) will be able to understand it quite quickly. However, that is (as it should be) quite few and far between; sometimes documenting complex logic from elsewhere in the system that I have no control over but the programmer needs to be able to understand.

    Of course, there is also the typical PHB managers who evaluate their programmers based on LOC, SLOC, and CLOC (LOC = SLOC + CLOC), and look for an even distribution of SLOC/CLOC - e.g. SLOC/CLOC = 1. In some cases that is good; but in most it is not.

    All in all, you can't tell how good the program is by just general comments or comment analysis.

    BUT if you are sloppy in your comments (grammar, spelling, etc.), you have probably been sloppy in your code. To that end, I do very well agree with the article.

    P.S. BTW, I've been in 3 positions where I have replaced people. One fired; one died; and one quit. In two of those three, the original developer was no longer available for inquiry; in the third, it was possible but not easy and only for a short time after he left.

    --
    Truth is like the sun. You can shut it out for a time, but it ain't goin' away. - Elvis Presley (source: imdb.com)
  41. You've got it backwards. by gillbates · · Score: 2, Insightful

    "You" - who formally prove your code, comment it, and make sure it works right - are called at 2 am in the morning to fix code that "He" wrote. "He" is now your boss, because:

    • "He" realized that his boss doesn't read code, and hence, comments don't matter. He didn't waste time with thoughtful analysis, good architecture, testing, or even commenting.
    • "He" shipped his code on time and under budget, and was promptly promoted to manager.
    • "He" can't understand why it takes "You" so long to ship code. "He" is constantly promising management increasingly shorter deadlines, which "You" have to work overtime to make.
    • "He" thinks you're an idiot because you can't fix his awful, spaghetti code 15 seconds after it breaks. After all, it never took him longer than that to hack something up to fix the problem, why would it take you that long?! If you can't figure out how to fix the program, just hardcode the "correct" result and move on.

    Programmers beware: the meticulous, but correct, programmer is a valuable asset to the company; the sloppy but fast programmer is his boss.

    --
    The society for a thought-free internet welcomes you.
  42. Comment bugs and lack of comments a worse problem by presidenteloco · · Score: 2, Insightful

    Worst: Originally erroneous or out of date therefore erroneous comments. Actively destructive to comprehension of the program, and once detected, causes all other comments in the program to be rejected as untrustworthy and worse than useless. "Comment Bug".

    2nd Worst: No comments - indicates the developer either does not understand the purpose or method in their madness, or is lazy and sloppy. Either is very bad.

    3rd worst: Redundant comments: /** Gets the Foo! */ Foo getFoo() See Java api documentation for prime examples.

    I would much rather read a long rambling philosophical comment that was essentially correct and did add some information than to deal with any of the above slackerware.

    --

    Where are we going and why are we in a handbasket?
  43. Re:Real Programmers... by Tetsujin · · Score: 4, Funny

    Your code should be a narrative. How about

    checkParamaters(...);
    setupConnection(...);
    submitQueries(...);
    checkReturnValues(...);

    The problem with this idea is that the actors in play don't lend themselves to a very compelling narrative. I mean, suppose I've got a data line that I've previously pulled low, and now I'm allowing it to float high - but I want to make sure it's actually floated high so I can be sure there's not somebody else pulling it low...

    What is the data line's motivation for floating high? Apart from a current-driver driving the line high, I mean... Will the reader actually be able to relate to this conflict between two different slaves trying to assert different states on the data line? And, if we do make a narrative about this conflict, won't we have to explore the individual slaves' motivations for the conflict? Won't we need some depth of background information about the source of the address collision? Wouldn't the narrative demand proper explanation of the first slave's feelings upon learning he's lost arbitration, and condemned to forever remain in the shadow of the second slave? And what about the narrative of the second slave, who doesn't even know there was a conflict, because he's won it? These don't sound like very appealing characters to me...

    --
    Bow-ties are cool.
  44. I can't believe the OP is even possible by syntap · · Score: 2, Insightful

    Whoever is criticizing grammar in comments obviously never had to look through legacy code and ask him/herself "WTF was this developer thinking?!" Or better yet, looking at one's own code written five years earlier and asked him/herself "WTF was I thinking?!" In those cases, any comments at all will provide clues.

    We should be encouraging coders to use comments _at all_, not giving incentive to shortchange it because they are going to be graded on stuff the compiler ignores. Any coder stuck with making changes to old code will be very thankful to see long-winded comments.

    Let's not forget that code is read many more times than it is written. Yes, it would be nice to have precise comments that tell all. But if a coder wants to go into detail then friggin let him, to suggest otherwise is just dumb.