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

660 comments

  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 Anonymous Coward · · Score: 1, Informative

      complex perhaps, but usually most comments are just plain irrational.

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

    4. 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
    5. 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.
    6. 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
    7. 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. */

    8. 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*.

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

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

    11. 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.
    12. Re:The comment may also be complex.. by haystor · · Score: 1

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

      --
      t
    13. 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.
    14. Re:The comment may also be complex.. by Chris+Mattern · · Score: 1

      if it passes the Unit Tests, then how is it really bad?

      If you believe that passing the unit tests means the code is acceptable and bug-free, you are fool and I don't want you touching any code I am responsible for.

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

    16. 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?

    17. Re:The comment may also be complex.. by Jared555 · · Score: 1

      And keep notes for yourself so you know to make sure it is someone else who has to work on that project next time something needs changed so you aren't going to be blamed for the guarant.... possible issues

    18. 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.
    19. 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.

    20. Re:The comment may also be complex.. by Z00L00K · · Score: 1

      Some mathematic formulas appears simple by themselves, but do the work that did result into the formula E=mc2 and you will realize that it takes some work to end up there.

      But comments for their own sake - no, that's not necessary.

      As for grammatical errors - it also depends on the native language of the programmer. Some coders does write good code, but their skill in English sucks big time - sometimes it would have been better if they hadn't written the comment at all.

      --
      If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
    21. 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?

    22. Re:The comment may also be complex.. by darkgrayknight · · Score: 1

      No, you still want to figure out why, so at the very least you'll know what to do for other projects with similar problems.

    23. 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.
    24. Re:The comment may also be complex.. by vertinox · · Score: 1

      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.

      I dunno. The problem with a lot of code is that it is quite possible that it works and not even the people who wrote the API knows why it is.

      I worked tech support a few years at company writing foxpro code who got on a conference call with Microsoft before and they told us they didn't know why it was doing this either because as far as their documentation was concerned it shouldn't be working under those circumstances.

      And as management was concerned we were wasting time and MS support call fees if we continued any further on the matter.

      --
      "I am the king of the Romans, and am superior to rules of grammar!"
      -Sigismund, Holy Roman Emperor (1368-1437)
    25. 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.
    26. 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
    27. Re:The comment may also be complex.. by Anonymous Coward · · Score: 1, Interesting

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

      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.

      You sir, are a snob. A programming snob at that, congrats.

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

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

    30. Re:The comment may also be complex.. by clone53421 · · Score: 1

      Well, at least it (hopefully) elicited a chuckle, from you at least. Some mod apparently didn't have the same sense of humour.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    31. Re:The comment may also be complex.. by realityimpaired · · Score: 1

      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.

      That's about what I do when I'm commenting... put a note at the start of every function/method saying what the function is supposed to do. Give an idea of the algorithm that I'm using, and what kind of input/output to expect. Each one gets maybe a paragraph or two at most.

      It's not useless commentary, it's useful information... if something isn't working right, I can look at the comments to know what the code is supposed to do, and have an idea of how to go about doing that. If I return to something months later that has stopped working, that outline of the algorithm will probably give me an idea of where to go to find it in the function. It may also give me an idea, later on, of what I did wrong and how I can fix it. Perhaps most importantly, if I'm writing code for the corporate machine, how do I know that I'm going to be the one, two years from now, who has to figure out why function X is returning bad results?

      I've seen my share of useless comments in code. I'm sad to admit that some of it was from my own early work. I've also seen people who are overly pedantic... like a function that looks like:


      float sum(float a, float b) { /* a function intended to provide a sum value of two variables, that can be floating point variables, and return that to the user. */
          return (a+b); /* add the two variables together and return the value to the user */
      } /* end of function. */

      That level of commenting for something that obvious (and that useless) is a waste of space. And really really irritating. But I know people who would provide that kind of comments for a function they've written. Still, I'd rather have too much pertinent information than too little of it....

    32. Re:The comment may also be complex.. by Tyberius · · Score: 1

      Most likely the details of the comment outlined specifically what you posted. Caveat utilitor.

    33. 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... ***
    34. Re:The comment may also be complex.. by Abcd1234 · · Score: 1, Insightful

      I worked tech support a few years at company writing foxpro code who got on a conference call with Microsoft before and they told us they didn't know why it was doing this either because as far as their documentation was concerned it shouldn't be working under those circumstances.

      And as management was concerned we were wasting time and MS support call fees if we continued any further on the matter.

      That's not at all the same thing. In this case, the code is clearly not conforming to the requirements/specification laid out, and as such, the behaviour you've identified is a bug, and MS should, internally, be treating it accordingly, which means investigating the issue, and then either fixing it in a subsequent release, or documenting it if a fix isn't possible (eg, backward compatibility concerns, possible unintended side-effects, etc).

      As for the customer, it may be perfectly acceptable to live with the issue as a known bug in the current release and move on.

      But the GP admitted to something very different, whereby he actually wrote code he didn't understand, and then *never bothered to try and understand it*. And that is behaviour indicative of someone who, frankly, isn't fit to be a professional software developer.

    35. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      I often like to put comments in like
      // Magic happens here
      and other similar things but that's just because it amuses me. (Also they're good to put in lecture notes when the lecturer hasn't put in the entire proof).

      You are allowed to put pointless and facetious comments in as well as the helpful descriptive ones. I usually put in a liberal sprinkling of both kinds.

    36. Re:The comment may also be complex.. by Kjella · · Score: 1

      Trouble is when you can substitute "IE5 or IE6" with "The legacy codebase that noone ever really wanted to take the cost of cleaning up made by contractors or developers that have quit or retired, ancient technologies and most of it written to pass only the exact use case the business wanted when it was written." Disturbingly enough, I don't think IE would win any real WTF-contests.

      --
      Live today, because you never know what tomorrow brings
    37. 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.

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

      If you are responsible for the code, you are a fool if you let ANYBODY touch it.

    39. Re:The comment may also be complex.. by element-o.p. · · Score: 1

      Okay, I'll bite. What happened to "c)"?

      --
      MCSE? No, sir...I don't do Windows. Yes, I am an idealist. What's your point?
    40. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      It may be very bad coding, but that's exactly when comments matter most! In the real world, there are time pressures, combined with scenarios that are very difficult to debug (such as timing issues, threading issues, etc.) In other words, bad coding is sometimes a necessary evil hoisted by business needs...

      I've spent too many hours trying to understand some bit of horrible sloppy code, known the developer was under time pressure, but wishing they could have spent the moment to write a comment explaining how the bad code came to be. In the real world I've needed to tweak very bad code that 'just worked', and of course, the number one requirement was that it continue, at least, to just work.

      So I have issue with the entire gist of the article -- we need to be encouraging coders to write exhaustive comments especially when the coding gets tricky. If we label these sorts of comments as only coming from "lazy" coders, we discourage their use, at our peril.

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

    42. Re:The comment may also be complex.. by element-o.p. · · Score: 1

      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.

      Oh....that explains Windows, then :D

      --
      MCSE? No, sir...I don't do Windows. Yes, I am an idealist. What's your point?
    43. 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?

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

    45. Re:The comment may also be complex.. by ircmaxell · · Score: 1

      Fair point on the fitness of the Unit Tests... I guess what I meant is that if you understand the problem, then you can still create working code even if the resultant code isn't "perfect". If you don't understand the problem, even a 'perfect solution' is bad...

      I agree 100% on the difficulty of defining 'good enough'. However, I think you'll agree with me that there is a trade off between finding perfection and getting shit done. There's a fine line there, but so long as you understand the problem and are careful, I think you can safely stay on the productive side of that trade-off...

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

      I believe the traditional expression is "...and then a miracle happens here."

    47. Re:The comment may also be complex.. by jafac · · Score: 1

      I tend to work in an environment where sometimes, we have to toss in a quick-n-dirty hack. I often feel compelled to record, for posterity, a lengthy explanation of why I did what I did - the way I did it. If for no other reason, than so the next coder who has to come in and "fix" what I wrote doesn't go - "WTF?". Sometimes, that next coder is me, maybe a year, and two or three projects later, having completely forgotten what I was thinking. My excessively verbose comments have saved my bacon many times over the years.

      Yeah, I understand how "real" programmers and "professional" software engineers work in the world of "grown ups". Sometimes I wish I could work like that. Sometimes I'm glad I don't.

      --

      These are my friends, See how they glisten. See this one shine, how he smiles in the light.
    48. Re:The comment may also be complex.. by wtbname · · Score: 1

      Make him stand under the bridge?

    49. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      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.

      That was just a sympathetic underpants gnome.

    50. Re:The comment may also be complex.. by Pieroxy · · Score: 1

      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 said, I'm on your side for software development. The analogy is crap however.

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

    52. 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
    53. Re:The comment may also be complex.. by Monkeedude1212 · · Score: 1

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

      Yes. Period. If you don't understand what your code is doing - how each variable is being assigned, used, and altered - from start to finish, then it is bad coding.

      The "It Worked!" Arguement goes almost nowhere in programming. You got it going, great stuff. What happens when a year down the road a change needs to be made, and you are absolutely blundered on how it was working in the first place?

      What if someone ELSE has to maintain your code? The "It worked!" is the reason why Programming can be such a painful job. PLEASE leave it to the professionals or keep it to private use.

    54. 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
    55. Re:The comment may also be complex.. by Kjella · · Score: 1

      I've found the following to work well: Place a one-liner comment per method in the header, that's for the public interface giving a clue what it's about, more only if it's really not obvious. This should only explain it as a blackbox function, what it does not how it does it.

      In the implementation, add pseudocode comments every 5-15 lines depending on complexity. I usually keep them brief like "// load from database", "// loop to find items", "// display items". The good part is that you can just skim the code this way, and yet the comments are so close to the code it's easy to keep them updated.

      Plus, another pattern that I'm very fond of is the exit early pattern, though I know it's deeply hated. To me it keeps functions far more readable with less "active" branches you have to keep in mind, if it failed that test it existed, so assuming this then... I'd much rather see:

      If ( !foo ) {
              log( "bad stuff happened" );
              return false;
      }

      than five levels of

      if ( foo ) {
              if ( bar ) {
                      if ( whatever ) { ...

      --
      Live today, because you never know what tomorrow brings
    56. Re:The comment may also be complex.. by interploy · · Score: 1

      Absolutely.

      I work for a place that deals with XML from multiple vendors and we spend a lot of hours working out how to normalize that code. Many times an otherwise simple regex becomes a convoluted mess as we try to account for each vendor's various coding quirks. And unfortunately my predecessors weren't the type to leave many comments. I don't care how long it gets, a comment should explain exactly what your code is doing and why. It's much better to have a long-winded speech about the scripts inner workings in the middle of your code than nothing at all. Code might be poetry, but when it comes to complex code a comment should be an essay.

    57. Re:The comment may also be complex.. by Rob+the+Bold · · Score: 1

      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!

      Bad code, good comment, I'd say. That way at least Monday man doesn't come in and re-use your code thinking you had some particular insight that he oughta copy! Cause Monday man could be you.

      --
      I am not a crackpot.
    58. Re:The comment may also be complex.. by TheUnknownCoder · · Score: 1

      You missed the classic:
      // Here be dragons

      --
      Uncopyrightable: The longest word you can write without repeating a letter.
    59. Re:The comment may also be complex.. by ByOhTek · · Score: 1

      Maybe the author should have put longer than necessary.

      Heck, even ignoring that, no matter how well coded, printf won't have short documentation.

      The question is - is it a 5 page set of documentation on printf, or 50?

      --
      Self proclaimed typo king, and inventor of the bear destroying coffee table (patent not pending).
    60. Re:The comment may also be complex.. by oldhack · · Score: 1

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

      Are you kidding? If it somehow stops "working" and they come to you (the author) to fix it, how will you fix it?

      --
      Fuck systemd. Fuck Redhat. Fuck Soylent, too. Wait, scratch the last one.
    61. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      So you code something just to pass the unit tests without understanding how or why they pass. That means when it breaks you won't understand how or why it broke.

    62. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      Don't bother.

      Everything's an excuse to someone who would say that grammar is essential to good programming. You stub your toe while walking down the street; it's proof that you write bad code. Communication is part left brain and part right brain. This debate isn't.

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

    64. Re:The comment may also be complex.. by cayenne8 · · Score: 1
      What is this "comments" in code thing you are talking about?

      Interesting concept...please, do go on....

      --
      Light travels faster than sound. This is why some people appear bright until you hear them speak.........
    65. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      I think you missed the point. They are not figuring out something that isn't broken. They have no idea if it is or is not broken. "It just works" is not a valid reason to release code. If you don't understand why code works, you won't understand why it might NOT work and/or give back bad results that could lead to costly decision making.

      Case in point, you are working on an algorithmic trading program that will analyse the stock market and make buy/sell decisions based on the data it sees. Do you really want to release code that you think works when it could potentially lead to bad decisions and bankrupt your company?

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

      Also known as survivorship bias.

    67. Re:The comment may also be complex.. by Per+Wigren · · Score: 1

      /* 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,

      Done that. About 10 years ago I drank about a litre (~34 oz) of 40% booze (moonshine), passed out at around 9 pm in the rain in a shrubbery. A remote acquaintance found me and helped me home at around midnight (I was told, I don't remember a second of it).

      I woke up around noon and on my computer screen, vim (on Linux) was up with some code I couldn't recognise. It was about three screens of gibberish programming code. I had written things like "if exec.library then STA $A000,X" and other random references to C64 and Amiga programming, something I had not touched or even thought about for at least 4 years (Amiga) or 10 years (C64) by then. It was a really, really scary experience.

      --
      My other account has a 3-digit UID.
    68. Re:The comment may also be complex.. by EmperorOfCanada · · Score: 1

      I agree if you have some complex math or a crazy business rule you could end up with paragraphs of comments explaining the functionality in detail. I would not expect the programmer behind me to understand a comment like //A modified Black Scholes. I would leave almost line by line comments showing how the whole thing was implemented with even greater comments as to why it was modified. The same with a crazy business rule. You might even go on and on about how the stupid shipping department used some crap system where they had to type stuff in and that this apparently bad design was to accommodate a bad business flow. On the otherhand I hate code nazis who comment code like: //FUNCTION: GetUserList //PARAM 1 an integer named group_id which identifies which group will be used to generate a user list //RETURNS: class userList; which is an array of user objects //This function takes the group ID for any given list of users and returns that group, if any members, and will return an empty array if there are no users. It will only take a single integer as a parameter. //Developed by Binky the Clown //Date modified Sept 09, 2007 //Date created Aug 23, 2007 //Last modified by Billy Bob array GetUserList(int group_id){...} Self commenting code rules. Comments should basically be the exception not the rule.

    69. 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!

    70. Re:The comment may also be complex.. by Abcd1234 · · Score: 1

      ROFL, well, it looks like someone came along and fixed it, not only modding your comment Funny, but giving mine a +1 Informative.

    71. Re:The comment may also be complex.. by wasabioss · · Score: 1

      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.

      What's even more unsettling is waking up with a naked girl on my bed, and having no recollection of ever doing anything with her. It did make for a nice breakfast, though. Perhaps I should do it more often.

    72. Re:The comment may also be complex.. by JD770 · · Score: 1

      I have found that the following old maxim holds true in the real world:

      Pick Two: Fast, Accurate, Cheap.

      I've found that clients understand that very well and will quite often toss not only thorough code commenting, but in-depth documentation overboard if it will save money/time. But, that's their choice.

      If they want to include the extra time, I'll comment thoroughly and provide reams of documentation if desired. Other times, the client is only interested in rolling-out ASAP and I'm specifically told to minimize any and everything that could delay roll-out or exceed budget -- including comments and documentation. They are fully aware of the downside and accept it.

      It has been my experience that you have to be flexible. Excepting the laws of nature, there are no absolutes...

    73. Re:The comment may also be complex.. by clone53421 · · Score: 1

      Yup. Gotta love username jokes... like this gem which happened not too long ago. I had to take a screenshot...

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    74. Re:The comment may also be complex.. by maxwell+demon · · Score: 1

      Comments are a sign of bad code. That's because the more comments you have, the more errors you have in your comments. Uncommented programs have zero errors in comments, which points to excellent code.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    75. Re:The comment may also be complex.. by Ornedan · · Score: 1

      You're working on biased data. All of the Roman stuff still standing is grossly overspecced. Everything they did not overspec has fallen apart by now. We could build to last as long if we wanted to, it is merely that we choose not to (because it would be more expensive - this may not be a good choice, but it would be difficult to convince the accountants of that). It is our knowledge of physics that lets us decide how sturdy we want to build.

    76. Re:The comment may also be complex.. by clone53421 · · Score: 1

      Hmm, I'd much prefer to remember my drunken orgies. Cooking, on the other hand, is one boring tedium which I am perfectly happy to forget. Puking is another.

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

      Eww, gross... no telling where his hands have been!

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    78. 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...

    79. Re:The comment may also be complex.. by cheshiremoe · · Score: 1

      I think that sort of comment is useful when the person reading it might not be looking at the code like a the Java docs for an API.

      In the real world poor spelling and punctuation don't necessarily mean poor code. There are a lot of developers that are commenting in English but its not there first language, they know perfectly well what the code does and is supposed to do but they can't articulate it in English. While modern IDE's do a good job of detecting syntax problems in code, many don't do much if anything for spelling/grammar suggestions on comments.

      I like to descriptive explanation of larger code blocks but not every line likes some of my college professors make their students do. I understand that is to get students in the practice of making comments, but there is such a thing as over board.

    80. Re:The comment may also be complex.. by mea37 · · Score: 1

      This is a passable explanation for why the majority of code is bug-infested crap. The coders who write quality code aren't as prolific as the ones who don't care as long as they can sucker the QA department into beleiving the code "works".

    81. Re:The comment may also be complex.. by MikeDirnt69 · · Score: 1

      Perfect

      --
      Am I eval()? - http://www.monst3r.com.br
    82. Re:The comment may also be complex.. by Rob+the+Bold · · Score: 1

      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.

      This is a frequent rationale for tediously long comments: that the code commented is really complicated and "you are not expected to understand". In reality, such problems are rarely as atomic and complicated as commenters/coders would have you believe. More frequently, it's a sign that the coder simply didn't have the time or interest in breaking up the problem into easier to understand (and easier to maintain) chunks. Truly obtuse and opaque problems do exist, but not nearly to the same extent as long-winded comments.

      --
      I am not a crackpot.
    83. Re:The comment may also be complex.. by Rob+the+Bold · · Score: 1

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

      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.

      You sir, are a snob. A programming snob at that, congrats.

      I'd rather follow up on the work of a programming snob than a programming slob.

      --
      I am not a crackpot.
    84. Re:The comment may also be complex.. by Bakkster · · Score: 1

      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.

      How do you know it isn't broken if you can't prove it works? You don't. It could be platform specific, it could be compiler specific, it could be accessing invalid memory that is by chance set to a valid value in another section of code. This means the algorithm doesn't work, and would need to be rewritten when it breaks later down the road. Any software developer worth hiring should know this. If you can't figure it out yourself, ask another developer, because shit like this is not acceptable in production code.

      Sure, coding until it passes isn't the ideal, but it's a whole lot better than not coding at all (you).

      Erroneous code can be worse than nothing. I'd rather know that I didn't have code for a task, rather than depend on faulty results. Just ask the 23 soldiers killed when their patriot missile battery did not launch and they were killed by a Scud missile. Better to know you are exposed and to seek cover, rather than have a false sense of security and die.

      Extreme example, of course, but I'd much rather have no software, instead of software that just appears to work.

      --
      Write your representatives! Repeal the 2nd Law of Thermodynamics!
    85. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      Ignore the above poster. I appreciate the fact that there are so many like him out there, so after a company has hired a few monkeys like the above, I can walk in and get paid what I do to actually do it right.

    86. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      That's not insightful. A man-made construction standing for 2000 years is not the normal state of things. _All_ of the bridges (shitty or otherwise) should have fallen down by now.

      The real reason who those bridges are standing while the Bay Bridge keeps going down is called "cars". The Bay Bridge is under much greater load than any Roman bridge ever was. Tectonic activity in the Bay Area probably doesn't help either...

    87. Re:The comment may also be complex.. by mikael_j · · Score: 1

      I actually used that one as a comment for a bit of code that sorted a dictionary in a language that supposedly doesn't allow sorting of dictionaries in any way (but I needed it sorted or code further down the line wouldn't give the desired output), once I was finished putting together a horrible hack that actually sorted the dictionary I left a // Here be dragons (do not edit unless you know why you're editing this) to warn anyone who might be tempted to "clean up" that particular piece of code.

      /Mikael

      --
      Greylisting is to SMTP as NAT is to IPv4
    88. Re:The comment may also be complex.. by plopez · · Score: 1

      Your list is what I normally do. But I would add "how it handles exception". And possibly dependencies.

      --
      putting the 'B' in LGBTQ+
    89. Re:The comment may also be complex.. by Rob+the+Bold · · Score: 1

      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.

      When coders are hired as temps or on project-duration contracts, their motivations may not necessarily align with the "professionals" who'll have to maintain the crap. And if you know that you'll be out of there once it ships (or your time is up), you'd have to have a mighty strong ethical commitment to quality to do much better than "hack it till it works". It's not ideal, but individuals are gonna primarily look out for themselves (and for good reason). You'd think this would give such an individual or a firm a bad reputation, but that would depend on management listening carefully to the concerns of the maintenance coders.

      --
      I am not a crackpot.
    90. Re:The comment may also be complex.. by clone53421 · · Score: 1

      Sigh...

      Yeah, coding tan2 was a bitch. I wish the language I was using had just included the command natively.

      It was for this, BTW: [1 | 2 | 3 ]

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    91. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      ...Any developer worth their salt would spend the time to understand *why* their code is mysteriously working...

      No offense, but this is frequently not the programmer's decision. I've been in many jobs where work is thrown at you like water from a fire hose. The best programmers will know what code needs to be bullet proof (or at least bullet resistant) and which parts of code just need to get done. I'll go so far as to say that you need to make your case to management for good coding and sufficient programmers to get good work done. However, you're there to do the work that needs to be done as best you can.

    92. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      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.

      When your only tool is a hammer...

    93. Re:The comment may also be complex.. by Abcd1234 · · Score: 1

      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.

      Are you *seriously* trying to equate the ability to understand one's own code with "a formal and rigorous proof"? Really? To that, all I can really say is: Wow. Please, get out of the industry. Now.

    94. Re:The comment may also be complex.. by PitaBred · · Score: 1

      When you're delivering stuff to people paying you, versus just dicking around, I think he's right. There is no substitute for proper design, instead of just "does it pass the tests?". I can write code that passes all tests, but won't work outside of those. Hell, just a lookup table instead of actually computing results would pass the tests.

    95. Re:The comment may also be complex.. by kbielefe · · Score: 1

      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.

      I've worked with guys like this before. It's more like while he's heedlessly off coding the next thing, I'm trying to figure out yet another piece of his prolific yet unmaintainable code in order to do my job, or debugging yet another stack overflow that is caused by his code but crashes mine, because he didn't understand it well enough to consider a corner case. He may have gotten his part "done" faster, but it's still delaying the release. I've also worked with guys who get just as confused, just as often when they don't understand how they managed to hack something together, so they ask a colleague to take a second look at it. Guess which one most people would rather work with?

      --
      This space intentionally left blank.
    96. Re:The comment may also be complex.. by YojimboJango · · Score: 1

      I haven't seen anyone else post comments as CYA yet.

      I have lots of functions that look like: // "The X indicator must always be true in all situations" - Jim of Partner Company X, 02-11-2006 // "The X indicator must always be false if this is not the first one in the file" - Jane of Supplier Y, 2-26-2006 // "The X indicator is true if the value of Y is 3, 6, 7 or 9 and this is not the first indicator in the file" - Jim of Partner Co X, 6-23-2007 // "X is always false, everyone else is smoking crack." - Dave of Partner Z, 7-01-2007

      Most of the time I get by on doing what I'm told. If I think the solution is wrong, but office politics is forcing me to do it another way then I'll document in code who told me to do it, and the when. That way when someone else looks at it years later and it looks like crap, they'll know why. I get particularly wordy when I know that the spec I'm working from is likely to change 4 times before, and 6 times after the projects deadline.

      Anyone else CYA in your comments?

    97. Re:The comment may also be complex.. by nortcele · · Score: 1

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

      Perhaps, but there's a thing called "homework" that one can never escape. Things not well understood which require more time to figure out than is available in the regular workday are going to demand extra effort during off-hours. Anyone that retorts with an excuse of "I don't have time to..." is going to eventually be replaced by someone that will. Being one of the older programmers in our dept, I've witnessed too many over-40 folks who disengage from learning and personal development. Those not driven to understand the how and why of their work might be in the wrong profession.

      We should all strive to have the highest integrity, be productive, be detail oriented, and to be continually learning. What employer wouldn't want their building full of employees like that?

    98. Re:The comment may also be complex.. by ub3r+n3u7r4l1st · · Score: 1

      " "Hacking it until it works" is completely antithetical to those goals."

      Depends where you came from. In some culture, the society is objective-based driven. If it works, it works, and move on.

    99. Re:The comment may also be complex.. by Chees0rz · · Score: 1

      oh snap!

    100. Re:The comment may also be complex.. by Chees0rz · · Score: 1

      the Bay Bridge comes to mind...

    101. Re:The comment may also be complex.. by Zontar+The+Mindless · · Score: 1

      Whoosh.

      --
      Il n'y a pas de Planet B.
    102. Re:The comment may also be complex.. by VJ42 · · Score: 1

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



      Bingo! I once wrote a JavaScript roll-over menu that only seemed to work with a blank comment "<!-- --!>"underneath the closing script tag. If I deleted that comment it stopped working in IE6 (still worked fine in Phoenix or was it Firebird back then (this was about 7 years ago)...?). Ever since then I started writing roll-over menus in CSS, and decided to ignore IE6 compatibility (before I get flamed by people telling me this is\was unprofessional behaviour, I write websites for fun, not profit so have no corporate overlord I'm beholden to).
      --
      If I have nothing to hide, you have no reason to search me
    103. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      Hey, don't be too hard on the blue-collar...

    104. Re:The comment may also be complex.. by Rary · · Score: 1

      You sir, are a snob. A programming snob at that, congrats.

      He may be a snob, but the next time I'm hired to maintain or extend someone else's code, I hope it was written by someone like him.

      I say this as someone who is currently maintaining (and mostly rewriting, whenever I get the chance) somebody else's hastily hacked together code that, more or less, works — at least until I have to add functionality, at which point I see the house of cards it really is.

      --

      "You cannot simultaneously prevent and prepare for war." -- Albert Einstein

    105. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      No, that's the sort of situation where you tell the company that they're going to stop using or supporting IE5 or IE6, or you're going to leave. And then you do leave, if necessary.

      I've had to do this several times. I've told them flat out that, as a professional, I will not use IE, nor will I develop software that uses IE. If they want, I will explain to them what is wrong with it.

      At three of the places I've done that, they smartened up and agreed to immediately adopt Firefox or Opera. I'd be fine recommending Chrome these days, too.

      One other place decided to deprecate IE, in favor of Firefox.

      I ended up leaving one place that refused to change. The crashed and burned later that year, quite expectedly.

    106. Re:The comment may also be complex.. by Rakishi · · Score: 1

      The job of a programmer is NOT to code. The job of a programmer/developer is to get working maintainable software created. Everything else, including coding, is secondary.

      In reality people with your and the GPs attitude always seems to wonder why they get such shitty jobs and why they have such a hard time finding jobs. Want to know the secret? People don't want to hire idiots like you and we can tell. It's also a small world, good developers will network with past coworkers who were also good developers. At the same time they'll try to put as much distance between themselves and their idiotic ex-coworkers as humanely possible.

    107. Re:The comment may also be complex.. by zullnero · · Score: 1

      Or, you may have created the project with no intention of maintaining it yourself, and had a pretty good idea that a less skilled (read, lower paid) developer would be stuck trying to understand how a moderately complex region of code worked. I know I for one would rather have a company I consulted at not get frustrated with my dev work after I'm gone, rather than write complex stuff that I can "hope" they'll pay me to come back and fix later. I'd rather they feel comfortable to bring me back to work on bigger and better things...which is why I put a little extra meat into my comments to make a new dev feel comfortable enough at getting a handle on things.

    108. Re:The comment may also be complex.. by DutchUncle · · Score: 1

      An explanation may be long if it is explaining something complex that the code is doing.

      ...if it really does require that complicated of an explanation, you might need to re-factor your code and make it less arcane.

      Sometimes the whole point is to do something arcane because of efficiency, or hardware issues, or really weird special case in the requirements. Or worse, sometimes attempted changes ran afoul of similar hardware issues, and you want to remember *not* to try changing it again without considering the non-obvious issues. It's like surgery; the cut might be simple, but knowing WHAT to cut and what NOT to cut took years of schooling.

    109. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      So how is India treating you? After all, if you're gonna get shit code you may as well get shit code at a tenth the price.

    110. Re:The comment may also be complex.. by O('_')O_Bush · · Score: 1

      "It's usually a business of maximizing productive features versus minimizing cost and time."

      That might have been true 10 years ago, but most technical managers now realize that to minimize cost and time, you must first thoroughly test, maintain, and understand all code that is written.

      In the corporate software development world, it's constantly drilled that a small overhead in development for maintainability is orders of magnitude less expensive and time consuming than dealing with problems in the future.

      The only thing that keeps borking that principle up are lazy developers that make broad assumptions and check their code off as correct.

      --
      while(1) attack(People.Sandy);
    111. Re:The comment may also be complex.. by uncqual · · Score: 1

      It's good to see a poster who worked on the Therac-25 - we don't get many of those here anymore.

      --
      Why is there an "insightful" mod and why isn't it "-1"? If I wanted insight, I wouldn't be reading /.
    112. Re:The comment may also be complex.. by codeguy007 · · Score: 1

      Well he is getting paid overtime to fix the bug. Some would say that's a plus. :P

    113. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      Kudos for pointing out the Survivorship bias.

    114. Re:The comment may also be complex.. by StuartHankins · · Score: 1

      Quantity without quality is meaningless. If you have no understanding how something works you have no business coding it. Or are you reduced to a copy and paste "coder" who simply copies snippets they find on the web? Don't wonder why you get replaced or downsized, surely the problem isn't your careless attitude.

    115. Re:The comment may also be complex.. by uncqual · · Score: 1

      Apparently there *is* a dark side to a high-quality unit test suite...

      How true... I worked at a place where one group used agile methods (sort of). It was amusing to watch them argue to a group that their software interfaced with that "it can't be our problem, it passed unit tests". d'oh! (Of course, it was their problem - their unit tests hadn't, and couldn't, have covered everything - a code review probably would have caught it though).

      --
      Why is there an "insightful" mod and why isn't it "-1"? If I wanted insight, I wouldn't be reading /.
    116. Re:The comment may also be complex.. by danlip · · Score: 1

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

      Nope. The sloppy programmer may get his code out the door sooner, but then it comes back after QA. Then you try to fix the bugs from QA and introduce more bugs because the code is crap. Unit tests may help but sloppy programmers write crappy unit tests and never think though all the cases that need covering. I take 2-3 times as long to complete my code as that sloppy programmer but I almost never have a bug filed against my code, and when I do it is quick and easy to fix, so in the end I get more done in the same period of time.

    117. Re:The comment may also be complex.. by ircmaxell · · Score: 1

      I think you missed my point. Your reply most definitely hits the heart of what I was trying to convey. If you're writing code for a system that has the potential to kill someone, good == good enough (meaning that there is no metric of "good enough"). But if I'm writing a non-mission critical script, that is only a time saver (To be used once or twice), than "good enough" is a quite different metric...

      There are 2 extremes... One in that it HAS to be perfect because there is too much at stake if something went wrong. The other being that it's not worth the time to be good, when good enough will do quite fine. It's all dependent on the requirements of the project you're currently working on.

      --
      If a man isn't willing to take some risk for his opinions, either his opinions are no good or he's no good
    118. Re:The comment may also be complex.. by Anonymous+Brave+Guy · · Score: 1

      The problem is that if all you've got is some code you don't understand and some tests, you don't really know whether it works. At most, you only know that it gives the correct answers in the specific cases you're testing.

      Then your customers, who are using your product in other cases, will find bugs.

      Then you will have to spend several times as much effort fixing the bug post-release as it would have taken to avoid the bug in the first place, and your developer morale will start to take a beating because all they ever do is fix bugs instead of working on creating cool new stuff that is what motivates a high proportion of people who get into this industry.

      Then your good people will all leave, except for two who you have to pay a small fortune in salary because they're the only guys left who know how your code works at all.

      Ultimately, you will be left running a dead company walking for as long as you can keep selling the increasingly out-of-date and bug-ridden product before your poor PR and your increasingly distant competition steal all your customers.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    119. Re:The comment may also be complex.. by getSalled · · Score: 1

      This is called "coding by coincidence."

    120. Re:The comment may also be complex.. by myrdos2 · · Score: 1

      I prefer: While he's spending hours and days picking out bizarre bugs from his code, I'll be coding something else. While my program works every time, his crashes and sometimes gives odd results. He'll never get it working, and it would be easier to start again from scratch.

      I'm speaking from experience, here.

    121. Re:The comment may also be complex.. by Krishnoid · · Score: 1

      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.

      On the scale of:

      1. No comments
      2. Useless comments (increment i by one)
      3. Comments describing the working part
      4. Comments describing the situation
      5. A complete solution

      You fall somewhere between 3.5 and 4.5. While you didn't solve the problem in its entirety, anyone who has to debug your code after the fact doesn't have to start from item one. Should they decide to solve the problem, they have less work to do -- you've made it easier to incrementally improve the code. Good job.

    122. Re:The comment may also be complex.. by uncqual · · Score: 1

      I agree for the most part - I meant to push back on the "if it passes the Unit Tests, then how is it really bad?" part - passing unit tests is almost never sufficient, although it's almost always necessary.

      Also, it doesn't sound like the "quadrant coder" was writing some script to be used only once or twice -- he bothered to put comments in it which suggests to me it wasn't created in /tmp and intended to never be run again. (I actually assumed the poster was going for "funny" until I read the number of responses to his comment!)

      Also, no real life complex system is ever "perfect". That's why we sometimes try to reduce the risk of catastrophic failure in life critical systems by implementing independent systems whose entire job is to detect a failure in another part and enforce safety constraints. But this solution still isn't 'perfect' - just much less likely to result in catastrophic failure.

      --
      Why is there an "insightful" mod and why isn't it "-1"? If I wanted insight, I wouldn't be reading /.
    123. Re:The comment may also be complex.. by Tetsujin · · Score: 1

      You sir, are a snob. A programming snob at that, congrats.

      I'd rather follow up on the work of a programming snob than a programming slob.

      Sure, but which would you rather work with? Which programmer, I mean?

      If you were just going to take over a project previously maintained by another programmer, then the snob is possibly the best choice. But if you're going to work with them - and especially if this other programmer is going to be reviewing and possibly rejecting your code - wouldn't the snob be a real hassle to work with? :)

      --
      Bow-ties are cool.
    124. Re:The comment may also be complex.. by carrier+lost · · Score: 1

      It's been my experience that people who leave competent comments are both the people who write competent code and who can touch-type.

      I would imagine that when you have to peck out 400 lines of code using four fingers, there's very little incentive for you to go back in and start trying to explain things.

    125. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      Yeah, but the crap we're building today also won't require the lifetime labor of hundreds of slaves and soldiers to build one bridge...

    126. Re:The comment may also be complex.. by cesutherland · · Score: 1

      It also needs to be readable, comprehensible, and maintainable.

      It needs to be elegant.

    127. Re:The comment may also be complex.. by yttrstein · · Score: 1

      I always tried to do this when I was programming. I took every project as an exercise in teaching; not only to pass down handy kung fu secrets that no one tells you in college, but also to hone my own teaching skills. If I can't explain what I'm doing so that it's interesting to a duck, then I need to be a better teacher. /* Willfull recursion here. Note that nothing I say will likely ever be interesting to a duck, therefore I will always by my own measure come up short on the teaching skills, therefore I will always take every opportunity to sharpen what I have. Also, implicitly if I cannot explain what I've done in a way that *I* can understand, I probably shouldn't have done it at all. */

    128. Re:The comment may also be complex.. by syousef · · Score: 1

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

      The problem is that if you don't know why something works, you don't know that it does work for all cases. There are always consequences to the code failing - anything from an irritation to the user, to large financial loses or loss of life. It all depends on whether you want quality and a product that works, or something cobbled together out of spit and duct tape.

      --
      These posts express my own personal views, not those of my employer
    129. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      No.

      The metric for "good" code is .. Euros.

    130. Re:The comment may also be complex.. by sconeu · · Score: 1

      /* You are not expected to understand this */

      --
      General Relativity: Space-time tells matter where to go; Matter tells space-time what shape to be.
    131. Re:The comment may also be complex.. by Rasperin · · Score: 1

      I tend to study from the same book, my co-worker and I debated over it for awhile but an exit early system is not only easier to read, uses less code, etc it tends to be more efficient as it kills the method before any heavy activities are run. Now this isn't always true but then again I haven't reached a case where it wasn't~

      --
      WTF Slashdot, why do I have to login 50 times to post?
    132. Re:The comment may also be complex.. by clone53421 · · Score: 1

      P.S. My memory was faulty; it was actually the atn2 function. Geek cred goes to anyone who can look at those pictures and tell what that function was needed for.

      They aren't screenshots, by the way... I was limited to 1024x768, with 16 colours on-screen. Those were generated by plotting directly to a 24-bit BMP file, the format of which I personally reverse-engineered...

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    133. Re:The comment may also be complex.. by St.Creed · · Score: 1

      Actually, I always use the Web-philosophy. No, not the internet web-thing, the old one by Donald Knuth using Tangle and Weave.

      Basically, i write a short story of what the program is doing, and why, and how. Then I comment that story. Then I add in the code at the points it should be. Most of the logical errors I can catch this way before I even start to program. Using invariants and pre/postconditions make it even possible (if you're so inclined) to prove the code as correct.

      Short comments, or long comments, who cares. Just make them meaningful and readable.

      --
      Therefore, by the (faulty) logic you're using, you're just a cow with a keyboard - osu-neko (2604)
    134. Re:The comment may also be complex.. by St.Creed · · Score: 1

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

      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.

      You sir, are a snob. A programming snob at that, congrats.

      I'd rather follow up on the work of a programming snob than a programming slob.

      True, but try asking for explanations :)

      --
      Therefore, by the (faulty) logic you're using, you're just a cow with a keyboard - osu-neko (2604)
    135. Re:The comment may also be complex.. by Sandbags · · Score: 1

      I used to be the opposite. We had a professor who did nothing but try to throw BAD data at good code to see if he could break it. Extreme levels of code validation....

      I wrote all kinds of software to TRACK such attemtps (including cross assignment/project), and would do crazy stuff to him and his computer when he kept failing to actually find holes in my test scenarios...

      I had simple programs that could have been a few dozen pages of basic commented code otherwise, but they'de be nearly 100 pages of code by the time I tacked in all the other crap to mess with him :)

      I had a seperate proffessor who graded code projects as much on good code commentiung and formatting as he did on code execution. If it compiled, and ran his test data set, you got a 50%... the other 50% was all in how it looked on paper!

      Rule fo thumb: Every line needs both a coment and a debug line. Every function or code loopp/process needs a header description. every subprogram should have an inline manual. Any entry should be able to accept a null input (or a ? or something), and output to a user the correct input (ie, if you fail to give it the right format, it shoudl automatically prompt/repromt including help lines to get it from you).

      Give me 100 lines of good readible raw code, and I'll give you back 300-400 lines of formatted, commented code that would get an A in his class.

      --
      There is no contest in life for which the unprepared have the advantage.
    136. Re:The comment may also be complex.. by sjames · · Score: 1

      I could equally well say that while I am gaining better understanding of my own code and probably correcting a few bugs (if I didn't understand it, how would I see a bug), he is off to the next project right until a production failure yanks him back. As he is desperatly trying to figure out what's wrong with the clock ticking (code failures in production are much worse than during development), I am leaping ahead of him in my next project.

      Alternatively, a year later when the code needs updating, I find a cakewalk and he bangs on that again failing quadrant 2 randomly. Perhaps he'll get lucky twice but probably not.

    137. Re:The comment may also be complex.. by Sandbags · · Score: 1

      To carry the analogy, a mexican can build a house and need not understand WHY the boards get put where they do, that's the contractor's job. however, it is his job to understand the building code, and to ensure the board is placed and secured properly. he's told "put a door here" and he knows how to make the boards become a door, but he doesn't need to know anything about foundations, or roofing to do that. Same applies to a bridge builder vs a bridge architect. Someone CAN build a bridge without knowing physics (other than gravity else he ends up in the river under the bridge).

      A programmer may or may not have an understanding of the mathematics of a function, he only needs to understand the function represents the math he was given, or that the output is as desirted. He needs to know how the code is placed in order to get the desired result, but not every programmer necessairily understands the nature of the program.

      In large environments, codes are often told an input, and an output, and a function, and told to code it. They have no idea what's providing the input or accepting the output.

      That said, not know HOW you wrote something should not be the case. Not understanding some massive calculus equation used in 3 spacial lighting and reflection is OK, as long as you understand that when someone gave you a math problem to input, you did. Your comment need not explain the math, but it does need to explain what each line is doing as it progresses, and if you wrote a line of code, and you can't write 1 line of comment to say what it does, then you can't know that it is...

      --
      There is no contest in life for which the unprepared have the advantage.
    138. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      /* I'm not sure why this works, but it does */
      should immediately be replaced with: /* I'm absolutely sure that this is correct. */
      That makes it so much easier to find problems later on.

    139. Re:The comment may also be complex.. by Sandbags · · Score: 1

      It's almost like having the code, and the pseudocode it came from side by side, and that you could remove the code, give someone the comments, and they would produce the same code back to you.

      --
      There is no contest in life for which the unprepared have the advantage.
    140. Re:The comment may also be complex.. by Krokus · · Score: 1

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

      Agreed. I started a job with a company that had developed a client server application meant to support thousands of customers at one time. The programmers working there at the time I started were, for the most part, incompetent boobs. Case in point: the first thing I noticed during my whirlwind tour of the server code was the initialization. They would fork the server and have one copy watch the other. When the server crashed (which was frighteningly often), this forked copy would detect it, throw away the crashed server and automatically fork a new one. Naturally, every connected customer would be unceremoniously disconnected whenever this happened and all active transactions were rolled back.

      They did this because they got tired of doing it manually, since the server crashed constantly. Once I finished my tour of the code, from which I could fill half a notebook with a sizable list of coding atrocities, the first thing I did was remove the forking initialization code (hehe) based on my personal conviction that the server should not crash. I then spent the next several weeks fixing the astounding number of crash bugs that were now laid bare, and rewriting scads of horrible functions.

    141. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      Wrong, haystor. An software engineer, computer programmer, or hacker worth their salt would want to understand the reason for the failure and if the fix was only needed for the code handling that particular quadrant it is time to step back and re-evaluate the design decisions. On the surface the code should be able to handle all four (4) quadrants equally well with at most an in-bound argument specifying the quadrant to be computed with the associated logic able to handle the computations using the same algorithm.

    142. Re:The comment may also be complex.. by FlyingBishop · · Score: 1

      Only if you're not also responsible for fixing the code in a few months when it comes back to you anyway with a serious bug.

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

    144. Re:The comment may also be complex.. by Sandbags · · Score: 1

      I will say, in college, I had code marathons that lasted 30+ hours. At the end, i had code that not only compiled, but also error validated against any possible invalid input. After a night's sleep, and going back to recomment the code, sometimes it took days to comment what only took me hours to write, as i churned through logic loops that only a mind in a coder's trance could rightly produce and understand, and coders in a writing trance don;t pause to comment...

      Granted, such code happens, but it shoudl NEVER be released!!!! If you can't figure out what you wrote to comment it, REWRITE IT AGAIN.

      --
      There is no contest in life for which the unprepared have the advantage.
    145. Re:The comment may also be complex.. by FallinWithStyle · · Score: 1

      /* 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. */

      Ahhh, I believe you're referring to the Ballmer Peak...

      --
      Does this smell like Chloroform to you?
    146. Re:The comment may also be complex.. by Tetsujin · · Score: 1

      Only if you're not also responsible for fixing the code in a few months when it comes back to you anyway with a serious bug.

      What if you're made responsible for fixing your non-broken changes to the code because the previously-mentioned snob programmer has some vague dislike of its style?

      --
      Bow-ties are cool.
    147. Re:The comment may also be complex.. by FlyingBishop · · Score: 1

      Debugging is part of coding. If you're looking for the source of a bug, you are coding. And yes, I would call a function that fails under 25% of inputs bugged. Even if you've decided to write another method to handle those 25% of inputs, it's probable that the bug is not confined to the known problem cases.

    148. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      non-salaried programmers? ha! hahahaha!

    149. Re:The comment may also be complex.. by Nefarious+Wheel · · Score: 1

      I so believe in the premise. I used to write a lot of 3GL code - hundreds of thousands of lines of it, mostly Fortran or C. I also ran a couple of very large teams of software developers. I would say "Write this thing so you can understand it at 3am".

      You see, it's not really enough if you understand it at your desk, when you're fully alert. You have to code so you can understand it when you have a headache and the phone calls are coming too close together. For this you need clear narrative comments that mean something, and you shouldn't have to decode the English (yours or other peoples') in the comments at the same time. Distracting!

      And over the hundreds of programs that I had to review across the various teams, the the programmers who had tidy code with understandable comments were uniformly the most productive programmers and the ones who had the fewest bugs. And for those who tended to spin their wheels around a bit of code, I would say "Delete that chunk of code, write the test first and write it in English. Then code." Always worked. Bad code reflects muddy thinking, and - like it or not - most programmers' first language is English followed by math. You have to be logical everywhere to get that box of switches to think.

      Oh, and obligatory - good comments look like "Increment first array pointer", not "Add one to I".

      --
      Do not mock my vision of impractical footwear
    150. Re:The comment may also be complex.. by Devalia · · Score: 1

      Out of interest do you expect code to compile first time?

      I'm always suspicious if this happens, but it's probably because I don't do much coding in my job - when I do code it tends to be scripts to quickly test something/process data (or some embedded code for a micro controller) - as such I always tend to be using different compilers (esp embedded ones which always seem to have their own set of non standard stuff), languages (python then C++ etc).

      As a result I'm always making some sort of grammar mistake (i.e commenting out C++ with # instead of //, missing the odd semi-colon, pressing tab instead of spaces (or not setting up the text editor to handle this correctly) or forgetting the correct way to refer to a member function via a pointer etc..)

      It could just be that I'm used to compiling being the fastest way to catch this kind of problem in most cases.

    151. Re:The comment may also be complex.. by uncqual · · Score: 1

      Failing to include good comments in a complex regex in production code, esp. if the regex needs to deal with oddities in the input, should be a capital offense.

      --
      Why is there an "insightful" mod and why isn't it "-1"? If I wanted insight, I wouldn't be reading /.
    152. Re:The comment may also be complex.. by swillden · · Score: 1

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

      I do the same, but I add a third step: delete the comments (most of them, anyway)

      Comments are dangerous because they often become wrong and misleading when changes are made later. A misleading comment is far worse than no comment.

      My process, then, is to write a detailed comment at the top of each function, then write a series of comments in the body outlining how it should work. Then I fill in the code iteratively, testing at each step (with unit tests). Once the code is fully functional, I go back and pare down the comments. Where a comment can be made unnecessary by simplifying code or choosing better names, I do that and eliminate the comment. Where that's not possible, I look to see if the comment itself can be made more concise, and I also check to see if maybe the comment implies something about the code that might not be true.

      I consider myself to fully satisfied with the code when no comments are left because none are needed. I'm rarely fully satisfied, but I try.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    153. Re:The comment may also be complex.. by clone53421 · · Score: 1

      I actually went and dug up that program again... from the date modified on the source code, it looks like I did it in late 2006.

      This is a screenshot. NOTE: THAT IS 16 COLOURS. I customized the palette and simulated "true" colour using 5 shades each of red, green, and blue, plus black (16 colours total). Then I plotted triads of adjacent pixels to approximate the desired hue. I was pretty pleased with it. :D

      Here is a screenshot from another program I wrote using the exact same plot routine. Again, 16 colours. (The program displays BMP images. The code is god-awful ugly, though... large segments with line numbers interspersed between blocks of code added later without. GW-BASIC, which it was originally written in, required line numbers, but the compiler I later transitioned to didn't.)

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

      But if you're going to work with them - and especially if this other programmer is going to be reviewing and possibly rejecting your code - wouldn't the snob be a real hassle to work with? :)

      Not if you're coding correctly yourself.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    155. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      Teutonic activity in the Roman times knocked down plenty of bridges, too.

    156. Re:The comment may also be complex.. by poopdeville · · Score: 1

      Are you *seriously* trying to equate the ability to understand one's own code with "a formal and rigorous proof"? Really? To that, all I can really say is: Wow. Please, get out of the industry. Now.

      Speak to yourself. Every program is a constructive proof, via the Howard-Curry correspondence theorem.

      Ignore that at your peril. You're only wasting everybody's time with "patterns", when what you really need is existential and universal quantification.

      --
      After all, I am strangely colored.
    157. Re:The comment may also be complex.. by clone53421 · · Score: 1

      I used to be the opposite. We had a professor who did nothing but try to throw BAD data at good code to see if he could break it. Extreme levels of code validation....

      And as well he should ... although not truly all he did, I hope. Your code should be able to take anything in stride, and if it must crash, at least do so gracefully with an error message explaining what happened.

      Give me 100 lines of good readible raw code, and $50, and I'll give you back 300-400 lines of formatted, commented code that would get an A in his class.

      Shhh... ;)

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    158. Re:The comment may also be complex.. by Rick+the+Red · · Score: 1

      IMHO the documentation should be written first, and the code should then be written to behave as documented, with the user acceptance tests also based on the documentation. Really, you shouldn't need a requirements document if you start with the user's manual, and if the user can't understand the user's manual they probably won't understand the software and you should re-think your design. IMHO.

      --
      If all this should have a reason, we would be the last to know.
    159. Re:The comment may also be complex.. by Tetsujin · · Score: 1

      But if you're going to work with them - and especially if this other programmer is going to be reviewing and possibly rejecting your code - wouldn't the snob be a real hassle to work with? :)

      Not if you're coding correctly yourself.

      But that's the point: the snob may reject your code even if nothing's wrong with it...

      --
      Bow-ties are cool.
    160. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      > ... but because the comments describe its function as a narrative.

      I guess you'd love Smalltalk. It's a very expressive programming language, you can "read it as english." No need for comments. :)

    161. Re:The comment may also be complex.. by Alanbly · · Score: 1

      I agree there. I run into way too many situations when "just get it done" becomes "why doesn't it work?" Oddly, my "just do it right" doesn't have these issues. Programmers never look at these things from a business standpoint, as evidenced by comments in code that say things like "loop through values 0 to 1000" above a for loop instead of "examine all widgets for bugs." It shows a lack of foresight and larger perspective to produce shoddy or lucky code and it always shows in the comments.

      --
      -- Adam McCormick
    162. Re:The comment may also be complex.. by clone53421 · · Score: 1

      Then he's an idiot and/or a jerk, not a snob. The snob merely demands the code be correct and well-thought-out.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    163. 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
    164. Re:The comment may also be complex.. by mhajicek · · Score: 1

      In the ideal case I agree with you, but often management doesn't let you code to the ideal case. They want it to work now, and while your at it get this and that working too. Oh, and before you do that fix this other thing, but don't let it slow you down on those other things.

    165. Re:The comment may also be complex.. by mwvdlee · · Score: 1

      Comments are a great way to reduce the error-to-linecount ratio of your code, while increasing your lines-of-code productivity level.

      --
      Slashdot social media options: AIM, ICQ, Yahoo, Jabber and Mobile Text. Why no MySpace?
    166. Re:The comment may also be complex.. by Rob+the+Bold · · Score: 1

      You sir, are a snob. A programming snob at that, congrats.

      I'd rather follow up on the work of a programming snob than a programming slob.

      Sure, but which would you rather work with?

      I see your point -- if you're the slob -- or rather just the "sloppier/less snobby" of the two of you. Having a real slob would take some of the heat off you when it came to code review time.

      That, and he's probably good at mixing drinks.

      --
      I am not a crackpot.
    167. Re:The comment may also be complex.. by operagost · · Score: 1

      ... until the drug pump started administering lethal doses.

      --

      Gamingmuseum.com: Give your 3D accelerator a rest.
    168. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      I once saw a comment in some tricky z80-assembly code back in the day: "This works - believe it!"

    169. Re:The comment may also be complex.. by Rick+the+Red · · Score: 1

      Or C - (re)-write it yourself. If you don't understand what it does, why do you want to use it in the first place? If you want it because of what it's documented to do (a function in a library) then either trust it works as documented or use something else.

      --
      If all this should have a reason, we would be the last to know.
    170. Re:The comment may also be complex.. by BobMcD · · Score: 1

      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.

      Correct me if I'm wrong, but aren't bridges designed by one party, on paper, then actually assembled by someone else?

      Do we assume the latter party is capable of completely designing the bridge, or merely assembling it according to the plan?

    171. Re:The comment may also be complex.. by 5pp000 · · Score: 1

      I once wrote this line of code in a routine that was reading a config file:

      if (line[0] == '#') continue; // comment

      I thought a comment consisting entirely of the word "comment" was amusing, and in this case not uninformative.

      --
      Your god may be dead, but mine aren't!
    172. Re:The comment may also be complex.. by nschubach · · Score: 1

      Unit tests are only for consistency... the test could be totally wrong and supply irrelevant information, but it will work like the last copy. Congrats to backwards compatibility.

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
    173. Re:The comment may also be complex.. by Logic+and+Reason · · Score: 1

      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.

      This is especially fun when the original requirements were never written down, and nobody knows exactly what they were any more (if anyone ever did). You know what the code is supposed to do at a very high level (most of the time!), but you frequently end up having to figure out whether some corner case in a piece of convoluted code is working correctly, is buggy, or doesn't actually matter either way. The last case is the best, because it often frees you to rewrite the code in a much simpler way. There's nothing quite like reducing a 70-line function down to a one-liner!

    174. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      Can you imagine what state the world would be in if a bridge DESIGNER was given 1/4 of the time required to properly build and test a bridge? That is routinely the situation in the programming world.

      I'm not defending this guy's "It just worked" policy, but I think comparing software engineering to design engineering is almost as silly.

    175. Re:The comment may also be complex.. by keytoe · · Score: 1

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

      Please explain that to management. They will strongly disagree with you, so make a good case.

    176. Re:The comment may also be complex.. by Bat+Country · · Score: 1

      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... /* 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. */

      On a few occasions I've found myself *needing* to code something while having an alarmingly high fever. Sometimes this is because something is actually due and sometimes it's because I just think I understand something.

      The surprising thing about this was when I had a fever of 103.4 and was snowed in so I couldn't get to the hospital so I stayed awake all night. I programmed a 3d graphics engine... without properly understanding what I was doing... and it worked. It took me the next 2 weeks to figure out what I'd done, why it worked, and what it was doing before I could improve it. Took me almost that long to verify that I hadn't just cut and pasted from random websites while in my delirium. My browsing history was full of all sorts of random crap. I'm still not sure how it happened.

      Suffice it to say that I now believe in the Ballmer Peak.

      --
      The land shall stone them with the bread of his son.
    177. Re:The comment may also be complex.. by Blakey+Rat · · Score: 1

      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.

      If you're using Visual Studio, it's dumb *not* to do that. It's intellisense will pick-up on your comment, and from then on every place you see that function call, BAM, there's the explanation of it right there.

      It always bugs me how many people use an IDE, but fail to use any of the benefits of using an IDE.

    178. Re:The comment may also be complex.. by deadkennedy · · Score: 1

      Agreed. If the comment is difficult to follow, odds are the code will also be difficult to understand.

    179. Re:The comment may also be complex.. by severoon · · Score: 1

      Yea, that's probably bad code. Here's why...

      If you regard software as something that is written to meet a set of fixed goals—in other words, something that can be "completed" and released—then this would be ok. In fact, there isn't much about software that's like that. Real software should be written as though it will continue to evolve and grow forever...because, if it's successful, that's exactly what it will do. Many features of modern programming languages and the point of software development processes is aimed at dealing with this one simple fact of life.

      That's not to say code or developers have to be perfect. It's ok to let the occasional code section like you describe by...however, if you can't figure out why what you've written works, the onus is on you to prove that it actually does do what you say it does. That means your unit tests have to be extra-tight, to the point that they literally define the specification of the desired behavior, and you should document the living hell out of that code and the unit tests for the next poor guy that inherits it and has to change it, extend it, etc.

      --
      but have you considered the following argument: shut up.
    180. Re:The comment may also be complex.. by Logic+and+Reason · · Score: 1

      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.

      Often, identifying a block of code that does one discrete, self-contained task and pulling it out into a function, even if that code is only used once, can make the code far more readable. You're essentially just naming a block of code. I need to work on that myself, since it doesn't come naturally like the urge to eliminate duplicate code does.

      You could easily do this with comments, of course, but I prefer self-documenting code to heavily-documented code.

    181. Re:The comment may also be complex.. by severoon · · Score: 1

      (By the way, I can't help but wonder if a good solution to your problem would have been to encapsulate the code that handles the different logic for each quadrant in a Strategy pattern, to physically isolate it from other code given the apparent complexity of what you were doing.)

      --
      but have you considered the following argument: shut up.
    182. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      There are tons of things that can't be expressed in today programming langages. Sometimes it could be but is just not (allowed execution context and various other reentrancy characteristics in an operating system comes to mind ; that could be easily checked in a dedicated type system, and even _is_ in some OS), sometimes it is just not possible anyway. In either cases, when your job is not delivering a better development platform but instead doing what you are supposed to do: delivering a product somebody pays you to write, the best place to write these informations down, which you should definitely do, is in comments.

      Of course this is less current in simple programs, or in the mind or less experienced programmers who don't know as intuitively what is the kind of _extra_ information needed for future maintenance of a function / method / class whatever. Having read (worked on) huge quantities of code helps a lot.

    183. Re:The comment may also be complex.. by Capsaicin · · Score: 1

      If you believe that passing the unit tests means the code is acceptable and bug-free, you are fool and I don't want you touching any code I am responsible for.

      If code passes unit testing it is acceptable by defintion! The issue isn't whether the code is "bug-free," it's whether the unit tests are.

      --
      Better to be despised for too anxious apprehensions, than ruined by too confident a security. --Edmund Burke
    184. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      Often my long winded comment are only there because I KNOW that the guy that reviews the code isn't gonna understand it.

      Micro-Managers are FUN to work for, *sigh*.

    185. Re:The comment may also be complex.. by AuMatar · · Score: 1

      No it isn't. Unit tests are not an acceptance test. Unit tests are meant to be run by developers to look for regression in working functionality. While passing unit tests is a good sign correlating with correctness, it does not prove the code is correct or even good enough to be acceptable. The unit tests may be buggy, or they may be missing important cases.

      Of course failing unit tests doesn't mean it won't pass acceptance testing either, if the unit tests include corner cases that just aren't important to the customer, or are too expensive/time consuming to fix compared to their impact.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    186. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      It's good to see a poster who worked on the Therac-25

      The article you linked to says Therac-25 failed unit testing (on live units unfortunately). Clearly this is the opposite of what OP was saying.

      If you want to show OP up, you need to provide an example that works exacly to specification (as Therac-25 clearly did not), yet is in some sense "not good enough" for its intended purpose.

    187. Re:The comment may also be complex.. by AuMatar · · Score: 1

      I've used the "it passed unit tests" excuse before. Basically, the situation was some code of ours where the test suite was pretty good and we were passing, but code that called our team's code was finding a bug and they wanted to pin it on us. It's actually quite common to hear that from decent programmers being cornered by managers/bad programmers looking to pass the buck. It translates to "I don't think the bug is mine, do you have any evidence or a solid reason to think it's me?" Sometimes they did and I'd look into it, sometimes they were even right. Other times it was a weird interaction and I didn't begrudge the time to look into it. Most of the time the bug was there's, and they just didn't want to investigate it.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    188. Re:The comment may also be complex.. by yorktown · · Score: 1

      The remarkable thing is that any 2000 year old bridges survive at all. The city of Pripyat in the Ukraine is falling apart and its been only been abandoned for twenty years.

    189. Re:The comment may also be complex.. by jedwidz · · Score: 1

      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.

      In my experience, by the time the code has been through acceptance testing, the behaviour of the messy existing code is a far better indication of what is needed than the requirements documents.

      Documentation is rarely subject to the same level of quality control as delivered code. It's more prone to being vague, incomplete or out-of-date.

      I think the way forward is to replace detailed documentation with a working prototype, written in an expressive high-level language.

    190. Re:The comment may also be complex.. by uncqual · · Score: 1

      The article you linked to says Therac-25 failed unit testing (on live units unfortunately).

      I think the confusion is yours - the failures were in production not unit test. The point is, the Therac-25 seems to have passed the unit tests - but that clearly wasn't enough to determine that the product worked correctly.

      --
      Why is there an "insightful" mod and why isn't it "-1"? If I wanted insight, I wouldn't be reading /.
    191. Re:The comment may also be complex.. by Capsaicin · · Score: 1

      While passing unit tests is a good sign correlating with correctness.

      I wasn't talking about "correctness," but "acceptability." Remember the OP was about the distinction between "good" and "good enough." A unit test is a definition of what contitutes acceptable behaviour by code. It says nothing about correctness, elegance, readibility or whatever. It really is about what is "good enough" as opposed to what is "good." And note, I'm not personally endorsing the "good enought," as opposed to the "good" approach here.

      [Passing unit tests] does not prove the code is correct or even good enough to be acceptable.

      If code passes unit testing it is acceptable by defintion! The issue isn't whether the code is "bug-free," it's whether the unit tests are. ... But I'm repeating myself.

      The unit tests may be buggy, or they may be missing important cases.

      You know you really ought to read the posts you respond to.

      --
      Better to be despised for too anxious apprehensions, than ruined by too confident a security. --Edmund Burke
    192. Re:The comment may also be complex.. by Senjutsu · · Score: 1

      You cannot argue with idiocy, but that doesn't mean its anything other than idiocy.

    193. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      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.

      Horseshit.
      The code does not explain "what" a program should do, the ONLY thing the code does is show what it actually does.
      Comments should explain why, and in some cases also how, you are trying to do something. But the whole point of the comment is to explain what your original intent was when you wrote the damn thing to start with.

      I will agree that there's no point in re-inventing the wheel in your comments. If you're using a standard pattern, algorithm, data structure, etc. then by all means just say something like "Bucket sort the array" and then note any deviation from the standard, but it generally does help to somewhere mention why you are (for example) using a bucket sort vs. a merge sort, etc.

      As for the claim that wordy comments indicate sloppy code, I don't necessarily agree, but if you notice yourself writing a novel that might be a good time to step back and see if there's a better way to accomplish things. Personally, I would rather have wordy comments than no comments, since the complete lack of comments usually indicates someone being either lazy or intentionally obscure.

    194. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      Is that bad coding?

      Yes.

    195. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      Typical documentation:

      /* yes it looks like crap. yes, it works.
            no, I won't change it. */
      #ifdef HAVE_USB_DRIVE
      # include "/mnt/my_usb_drive/work/lib/really_dope_lib.h"
      #endif
      #include <stdio.h>
      int main ()
      {
          float my_utility_check;
          unsigned my_rent_check;
          signed my_pay_check;
          do_it_all_sub43_proj13();
          return 0;
      }
      // yes, I only worked here as a subcontractor. haha on you

    196. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      They survived because they didnt use concrete, I bet in 200 years time every single New York tower will be gone.

      They actually used better materials like a mix of volcanic ash/sand that fuses better and doesn't erode away.

    197. Re:The comment may also be complex.. by poopdeville · · Score: 1

      The problem is that if all you've got is some code you don't understand and some tests, you don't really know whether it works. At most, you only know that it gives the correct answers in the specific cases you're testing.

      Then your customers, who are using your product in other cases, will find bugs.

      Surprisingly, laziness works in this regard, if you know some category theory (heh). If your data types are initial algebras, and you avoid side effects, you don't need tests beyond testing the induction steps. Bugs are 100% impossible, assuming you pass the initial test case, and the induction cases.

      --
      After all, I am strangely colored.
    198. Re:The comment may also be complex.. by GlassHeart · · Score: 1

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

      I use those words in a different way. To me, the code explains HOW the programmer wanted the task completed in explicit detail, but not WHAT the programmer's intention was. Thus, I would always like a programmer to document WHAT he thinks he's trying to do, so that I can determine if the HOW is right or wrong by inspection. The WHY is doubtlessly a nice bonus, but IME most bugs are discrepancies between the WHAT and the HOW.

    199. Re:The comment may also be complex.. by jbengt · · Score: 1

      At the risk of seeming to support an fairly inept analogy:
      Bridge designers understand a lot of things required to make sure bridges stay up. But I'll bet that many, for example, will specify grades of steel, types of paint, and other materials by reference to standards, without knowing the physics behind exactly why those particular materials perform as they do. Indeed, some of that physics/chemistry may not be fully understood by anyone, but rather based on empirical evidence.

    200. Re:The comment may also be complex.. by lsatenstein · · Score: 0

      Comments in code should be a summary of the code following after it. The details are in the code listing itself. At times, it is good to say at step 3, the code does this and this, and then at step 5 it does xxxxx. As far as grammatical errors, I know spanish programmers who write comments in henglish. The use the Spanish spelling rules and grammer rules for the english comments. So Esther. There is always a good reason for grammar errors in comments, and it is on indication of code quality.

      --
      Leslie Satenstein Montreal Quebec Canada
    201. Re:The comment may also be complex.. by poopdeville · · Score: 1

      I take 2-3 times as long to complete my code as that sloppy programmer but I almost never have a bug filed against my code, and when I do it is quick and easy to fix, so in the end I get more done in the same period of time.

      Pick up the pace, man. I take a third as long as the sloppy coders in my team, and in three years at my last place, I had one bug filed against my code (and really, it was an unclear spec I took at face value). This stuff is trivially easy.

      --
      After all, I am strangely colored.
    202. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      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.

      Are you sure those were hash browns and eggs? Did you smell them first?

    203. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      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!

      One thing's for certain: the code didn't work as you intended it to. That means it probably won't work in some circumstances and it definitely can't be maintained. If you can't figure out how it works, then how can someone else modify it to do something different? Code like that is a recipe for disaster down the road.

      In short, your code worked by accident, not by design. Shame on you.

    204. Re:The comment may also be complex.. by Anonymous+Brave+Guy · · Score: 1

      I'm all for proving things properly, but unfortunately, in the real world, we mostly deal with infinite problem spaces that don't lend themselves to a convenient recursive analysis.

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
    205. Re:The comment may also be complex.. by poopdeville · · Score: 1

      I use algebraic data types every day. It doesn't matter if the "problem space" is infinite. Induction and co-recursion are equivalent.

      --
      After all, I am strangely colored.
    206. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      In short, your code worked by accident, not by design. Shame on you.

      Better my code than me! Oh wait...

    207. Re:The comment may also be complex.. by lonecrow · · Score: 1

      For me the problem comes a year after completing a project and the client calls and wants a change made.

      Lets say the client wants something that sounds to them and you like a small change. How do you explain to them that it will take 1 hour to make the change and then 9 hours to conduct a thorough regression tests. Testing that is all the harder because you haven't worked with the code for over a year and it might take an hour or two to really get back into the groove of it.

      Typically what I will do is spend a modest amount of time considering what the implications will be for the change. Then I preserve any code I am about to change with a comment about why I changed it.

      It can be hard sometimes to find the middle ground between responsible development practices and not going broke :)

    208. Re:The comment may also be complex.. by lennier · · Score: 1

      "Could you imagine what we'd do to a bridge builder who just tacked stuff on until it kinda sorta stood?"

      Buy a million copies of his product, because it was cheap, it would be replaced in three years anyway, and maintenance came on someone else's budget?

      --
      You are not a brain: http://books.google.com/books?id=2oV61CeDx-YC
    209. Re:The comment may also be complex.. by lennier · · Score: 1

      "Rarely is the answer to further investigate working code."

      And that's why we have botnets, because code with exploits 'works'.

      Can I forward all my spam to you?

      --
      You are not a brain: http://books.google.com/books?id=2oV61CeDx-YC
    210. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      In all seriousness... my in-line documentation was never really something you could describe as short and/or sweet. It was in story form, usually involving a magical kangaroo (again, not kidding). Why? Because it was fun for me to write, and fun for others to read. People were encouraged to read the commentary before they read the code... which in turn gave them a better understanding of the hows and whys. Win-win.

    211. Re:The comment may also be complex.. by poopdeville · · Score: 1

      Sorry, I didn't mean to sound patronizing with those quotes. I meant to quote both "problem space" and "infinite". As you know, what this means varies by context, and we haven't picked a specific one. But still, induction and co-recursion are equivalent. In fact, since induction and co-induction are duals, they're basically equivalent too (as theories/languages anyway). Some of these are naturally used to model infinite structures, on demand.

      --
      After all, I am strangely colored.
    212. Re:The comment may also be complex.. by AuMatar · · Score: 1

      If code passes unit testing it is acceptable by defintion!

      No it isn't. That's why they're called unit tests and not acceptance tests, which is a separate step in testing. You don't understand what a unit test is. Here's a hint- it has nothing to do with the code's correctness or acceptability.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    213. Re:The comment may also be complex.. by GarryFre · · Score: 1

      I guess this person never has been under the gun from a boss who is more concerned about getting the coding done than in making comments. I make comments because I want to save the next person to work on the code some frustration - its an act of compassion and not intended to please a nit-picking arrogant English teacher!

      --
      www.Migrainesoft.com - Computer giving you a headache? We can fix that!
    214. Re:The comment may also be complex.. by jrumney · · Score: 1

      Personally I think you've got the WHAT and HOW around the wrong way. The code itself perfectly documents the HOW, but the bigger picture of WHAT the code is actually doing in the scheme of things is not always obvious.

    215. Re:The comment may also be complex.. by Capsaicin · · Score: 1

      No it isn't. That's why they're called unit tests and not acceptance tests, which is a separate step in testing.

      I'll concede, strictly speaking it's possible to draw a distinction between unit testing and various types acceptance testing. But the in the sense it was being used (and criticised) at the top of this thread, (which is also the sense it is used in XP), such a distinction is not apposite. Unless by "acceptance testing" you mean User Acceptance Testing, which is a whole different kettle of fish.

      In test-driven development, you code to silence the test's error messages (or to elicit their praise). Passing the full suite of unit tests is passing the acceptance test.

      Here's a hint- it has nothing to do with the code's correctness ...

      I'm glad you agree.

      ...or acceptability.

      Given that the code is written in order to silence error message, how else can you measure the code's acceptability?

      --
      Better to be despised for too anxious apprehensions, than ruined by too confident a security. --Edmund Burke
    216. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      I've got some even more unsettling news for you. That wasn't hash browns and those weren't eggs!

    217. Re:The comment may also be complex.. by Draek · · Score: 1

      Yourself included.

      --
      No problem is insoluble in all conceivable circumstances.
    218. Re:The comment may also be complex.. by Draek · · Score: 1

      He may be a snob, but that doesn't mean he's wrong. I've often said that the mark of a poor programmer is that they can't understand their own code after being a single week away from it, but it takes a truly special breed of idiot not to understand their own code the moment while they're writing it.

      --
      No problem is insoluble in all conceivable circumstances.
    219. Re:The comment may also be complex.. by SL+Baur · · Score: 1

      Esther Schindler is a troll.

      You are not expected to understand this.

    220. Re:The comment may also be complex.. by locofungus · · Score: 1

      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.

      Amen to that.

      http://clc-wiki.net/wiki/Portability_and_ANSI_C_Compliance

      There's a worrisome sort of class distinction in programming between programmers who are satisfied with code that seems to work, versus programmers who insist on code that works for the right reasons. Unfortunately, of course, just because some code does work you don't necessarily know whether it's working for the right reasons or the wrong reasons. Code that merely seems to work today can just as easily stop working tomorrow, leading to neverending bug-chasing. Code that works for the right reasons, on the other hand, has some decent chance of continuing to work properly tomorrow and next week and next month and next year, without continual hands-on maintenance (meaning among other things that the programmers involved are free to move on to new and different projects).

      Tim.

      --
      God said, "div D = rho, div B = 0, curl E = -@B/@t, curl H = J + @D/@t," and there was light.
    221. Re:The comment may also be complex.. by AuMatar · · Score: 1

      And that's a total misuse of unit tests. If you're using them like that, you don't understand their purpose. The purpose of unit tests is to catch regressions in functionality by the dev team before either checkin or hand off to QA. If you're using them for anything else, especially acceptance, your process is broken.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    222. Re:The comment may also be complex.. by vegiVamp · · Score: 1

      Sounds to me like one of you guys is coding business-critical stuff, while the other one is doing websites for marketing.

      --
      What a depressingly stupid machine.
    223. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      It must be excellent to live in a world where you can tell your manager "well, it's working as far as I can tell, but I don't know why, so hold off on all my other tasking until I track it down, it may only take a few more weeks of effort". Must be excellent indeed.

      Arrogant prick.

    224. Re:The comment may also be complex.. by Alioth · · Score: 1

      No, he's probably coding something that should be on The Daily WTF while you're trying to understand a problem.

      Coding isn't just about churning out lines of code. If you're just churning out lines of code, you're a glorified typist, not a software developer. The coder who writes less, but writes correct lines of code is a lot more productive than the one who writes lots of buggy code.

    225. Re:The comment may also be complex.. by clone53421 · · Score: 1

      Eh? Then how'd the rest of my raw eggs end up in the freezer?

      Fuuuuuuuuuuuuuuuuuu...

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

      What I imagine is that if an engineer could build the bridges he designs by hitting the "Compile Bridge" button, that his design and testing process would be entirely different.

      Just imagine nightly builds of bridges.
      Getting to test your bridges with cars, winds, earthquakes, boats first.

      --
      t
    227. Re:The comment may also be complex.. by morgan_greywolf · · Score: 1

      The question I always ask myself as to whether it's bad code or not: would you trust it to keep your [ spouse | child | mother ] alive? If the answer is no, it sucks.

    228. Re:The comment may also be complex.. by haystor · · Score: 1

      I started with the poster's premise that it works. This would imply that he has some method for knowing that it works.

      I've had all sorts of situations like this with graphics programming where I know at the end of it that it works, but I didn't follow a rigorous mathematical outline to get the code done. Sure, I could go back and figure it out after the fact, but I generally don't.

      I might write some code that renders something from a new file format. Visual inspection of the results is worth far more to me at the end than the formal proof that it works.

      --
      t
    229. Re:The comment may also be complex.. by bhartman34 · · Score: 1

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

      1) Who says someone who is trying to figure out why something works isn't "coding at all"? What kind of ridiculous assumption is that?

      2) The way you find out why something works is by coding. You change the code to test for different conditions. If you find a condition under which the code fails, then you try to figure out why (maybe by entering in different parameters in some kind of systematic way). Does this process take longer? Of course it does, but it's a whole lot better than ascribing the successful output of a program to black magic, which is what you're doing if you don't understand why it works.

    230. Re:The comment may also be complex.. by mcgrew · · Score: 1

      So that's why all my cabbages exploded when I tried Vista!

    231. Re:The comment may also be complex.. by Anonymous Coward · · Score: 0

      The code may be explained by a well known phenomenon called Ballmer peak.

      As for the hash browns, well... my guess is as good as yours

    232. Re:The comment may also be complex.. by clone53421 · · Score: 1

      Perhaps. I did wish that the intoxicated me was a better cook, though... the hash browns were slightly under-done.

      Oh well. The conscious me can't complain, as the conscious me didn't have to make them.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    233. Re:The comment may also be complex.. by Cederic · · Score: 1

      Although if you can highlight a bug in my code, I'll do my best to add a unit test that exposes it.

      Thus passing all the unit tests tends to mean 'no known bugs'.

      Strictly that's not true, as there may be environmental bugs or bugs that are cost ineffective to unit test, but it's a worthy start point.

      I think I've just agreed with you by disagreeing with you. Doh.

    234. Re:The comment may also be complex.. by Cederic · · Score: 1

      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.

      Only where the test suite has been retrofitted to the code.

      The mere act of testing as you develop changes your development methodology, your design approach, and the quality of your code.

      Well, assuming you're doing it right of course. There's a whole new area of discussion..

    235. Re:The comment may also be complex.. by sohp · · Score: 1

      Programmers that code like that and actually get hired and supported by management that are one reason I'm giving up my career in IT. If the industry really wants results no better than what a trained chimp could do, they can have them. I'm going to go do something that at least is honest about the results being judge purely on personal preference and whim.

    236. Re:The comment may also be complex.. by T.E.D. · · Score: 1

      That was exactly my idiom for years. Lately I've started adding a new twist though. Now when I'm done coding I go back, delete the comments, and only put in new comments where I find the code itself unclear or tricky. Sometimes the design comments can get a new life as method header comments, sometimes those are rewritten to.

    237. Re:The comment may also be complex.. by Marillion · · Score: 1

      And that may be fair. What I was trying illustrate is a kind of ridiculous commenting i've seen over the years. Management prescribed a certain quantity of comments. So there were many comments that read as follows:

      /* increment the array index to the next position */
      i++;

      That comment added no value whatsoever. The i++ is already clear enough to anyone who calls himself or herself a C programmer. Additionally, this was long before the days color syntax highlighting, the useless comments actually got in the way of the code. The comments was the same monochrome green as the text. You had to read around comments to see the code.

      Code is a language that expresses concepts in a way both computers and computer professionals understand. It is a simple language. When that simplicity fails to express the complexity, comments are required.

      --
      This is a boring sig
    238. Re:The comment may also be complex.. by tbannist · · Score: 1

      At time like this I remember this bit of advice: "If it needs a long explanation, you're probably doing it wrong."

      --
      Fanatically anti-fanatical
    239. Re:The comment may also be complex.. by awright69 · · Score: 1

      I second that. I am responsible for supporting a steaming pile of code from a major electronics company well-known for their reasonably good hardware. I can't tell you how many times I was told, "But all the modules passed their unit tests!" - to which I reply, "All fine and dandy, but did any of your tests check the INTEROPERABILITY of the modules, or the application's behaviour when linked and assembled?" I've caught them in this little oopsie too many times; I'd have had the SQA manager fired long ago were I a direct employee of said organisation.

  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 Anonymous Coward · · Score: 0

      Comments? What comments?

      JK

      Actually, when I need to learn what someone else's code does, 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.

    2. Re:Comments are good by Jared555 · · Score: 1

      2. When you have to explain what you are doing, it helps you to discover possible errors in your code. Particularly logic errors.

      What if the logic error was in the choice you made not to comment that piece of code because its function should be obvious to anyone working on the project?

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

    4. 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.
    5. 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?
    6. Re:Comments are good by Anonymous Coward · · Score: 0

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

      Only if you never ever update that code again.

    7. Re:Comments are good by mjschultz · · Score: 1

      Well, it seems like if you left the comments and followed the algorithm:

      Read comment,
      Read code,
      Do they agree?
          - Yes, good, this is probably not the bug
          - No, is this a bug?
              - Yes, comment is correct, fix code, check if bug still exists
              - No, correct comment.

      It seems faster, and leaves the comments for the next time you or someone else looks at the code. Also, the comments are correct now.

      More often than not, people *THINK* correctly and code incorrectly, so the comments are useful. If the thought is incorrect, you've probably just found a bug in the software. Yeah, it is useful to understand the entire code base yourself, but that will come naturally as you have to dig down farther to find the flaws.

    8. Re:Comments are good by Nerdfest · · Score: 1

      On occasion I've used them to apologise ...

    9. Re:Comments are good by Anonymous Coward · · Score: 0

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

      *rolls eyes*

      Of course the person who wrote the code *THINKS* the code does something which, in fact, it does not, because if the code actually does what the person who wrote it *THINKS* it does then I wouldn't even be looking at it in the first place because it would be working properly and I wouldn't have been asked to look at it.

    10. Re:Comments are good by element-o.p. · · Score: 1

      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.

      I run into this frequently with typical *Nix .conf files (not code, but you get the idea). The solution, I found, was simple:
      egrep -v "^(#|[\ ]*$)" ${heavily_commented_file}

      --
      MCSE? No, sir...I don't do Windows. Yes, I am an idealist. What's your point?
    11. Re:Comments are good by clone53421 · · Score: 1

      Not true. Five years from now, someone in management will look at the application and ask "why can't it do this?"

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    12. 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.

    13. Re:Comments are good by Knackered · · Score: 1

      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. :-)

      I don't want to know what the code does, I can see that. I want to know why the code does what it does. Why was the algorithm chosen? Why isn't it simpler? Comments that just repeat the code in prose are only useful when they precis a large section of code.

      --
      a.
    14. Re:Comments are good by TheUnknownCoder · · Score: 1

      Comments shall be avoided as much as possible :

      No. Bad comments should be avoided. Those are the comments that add nothing to the code.

      1) the code shall be simple and the name of variables and methods shall be self explanatory in most cases.

      Reasonably naming variables and methods is a given. Most of the time the comments are (or should be) used to explain why a certain function was created and coded that way, rather than putting in plain english what we can tell just by reading the code. The requirements behind your coding can be (and often are) as relevant as the code itself.

      2) the more you add comment lines, the less lines of code you can see on your screen.

      True, but unless you're coding with chisel and stones, this is really irrelevant. A program is not a novel that requires two pages of comments to explain a few lines of code. Whoever does this is missing the whole point of code commenting.

      3) comments introduce a redundancy.

      They do not, if they're done properly. As aforementioned, comments are needed to explain reasons that one cannot tell from the code.

      --
      Uncopyrightable: The longest word you can write without repeating a letter.
    15. Re:Comments are good by Anonymous Coward · · Score: 0

      What about comments in header files? The code is not there, and if the function is complex enough, just the name of the function (and arguments) may not be enough to clarify the API.

    16. Re:Comments are good by gwjgwj · · Score: 1

      Read comment,
      Read code,
      Do they agree?
      - Yes, good, this is probably not the bug
      - No, is this a bug?
      - Yes, comment is correct, fix code, check if bug still exists
      - No, correct comment.

      When code and comments disagree, both are probably wrong.

    17. 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*.

    18. Re:Comments are good by shentino · · Score: 1

      Comments are quite useful in expressing metadata, especially the kind you can't see because it's in another file.

      I see this all the time just by browsing the linux kernel.

      There are some things you cannot express in the code itself, such as when you are or are not allowed to call the function. For example, there are many things you cannot do in interrupt context, or with certain spinlocks held. Comments, as far as I know, are the only way of documenting such rules.

    19. Re:Comments are good by Anonymous Coward · · Score: 0

      Ditto. I see/complain about bad code way more often and gladly take"ugly" comments any day. I can delete comments that are unappealing, but I can't modify fuzzy/seemingly redundant lines of code that I'm not sure what's the original intention of the coder. I've seen comments like "// this check is to preempt when X happens, but I'm not sure why X happens". Bad code happens and excuses written in comments are usually helpful.

    20. Re:Comments are good by flimm · · Score: 1

      I suppose you also delete all the white-space and use one letter variable names?

    21. Re:Comments are good by Anonymous Coward · · Score: 0

      1. the first part is a good point, the second is spoken like someone who never really did any large-scale coding, particularly in a group environment.
      2. learn to use your development software. this is a complete non-issue. If you can't figure out how to hide your comments then read the help document.
      3. yes, the redundancy is good. when they differ you should trust neither.
      4. comments are often used for a lot of stuff they shouldn't be. comments are there to tell you what why someone put that code where they did, and what they hoped to accomplish.

      but strangely, the parts of the code that are difficult to understand are generally not commented.

      Not strange at all. When people don't understand the code they have trouble writing comments that don't reveal they have no clue. So it's a red flag when they're missing- either someone is just hacking crap into a pile of straw, or being intentionally obscure. Either way, it needs review and clarification, if not a complete re-work.

      I really hope you have to clean up code from someone who subscribes to your maxims, because you will quickly change your tune.

    22. Re:Comments are good by e70838 · · Score: 1

      1) fully agree, it was just for the joke
      2) I disagree. The annoyance of too many comments for code reading is such an issue that development software provides options to hide comments. But these tools are imperfect, they can not hide bad comments and leave only the good ones. The tools only reduce the importance of the issue.
      3) Can you elaborate why you think that "The redundancy is good" ? I have spend some years in database domain where redundancy shall be avoided like hell. And I continue to try to avoid redundancy. I am more in the mood that "small is beautiful" and "less is more" (less characters for solving cleanly the same problem results in more flexibility and more maintainability).

      fully agree on the remaining, the use of word "strangely" was irony.

    23. Re:Comments are good by Anonymous Coward · · Score: 0

      No. I wish I hadn't burned all of my mod points already, you'd have a troll mod right now.

    24. Re:Comments are good by Anonymous Coward · · Score: 0

      Comments explain WHY the code is doing what it is doing. Sure you can see WHAT it does, but that isn't the whole story.

      I'm guessing you write horrible unmaintainable code that is going to cost your company millions to repair once you're gone. Hell maybe while you're still there!

    25. Re:Comments are good by Cederic · · Score: 1

      Which is why comments are bad. Why change the tests, the code and the comment when you can just change the tests and the code?

      Good comments are rare. Good comments in changed code are even rarer. Easy to read uncommented code is actually more common, and quicker to write.

      It's a no-brainer.

  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 Abcd1234 · · Score: 1

      Well, I think the parenthetical is actually the key bit. 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. But a large comment at the start that sets the stage and outlines the algorithm takes care of that for you, and the inner comments then make more sense within that framework.

      But this is *very* different from a large comment that comes down to, as the author puts it, an "excuse". OTOH, I can't say I've ever come across such a thing... a developer embarrassed by their code is far more likely to not document it at all, rather than take the time to justify themselves.

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

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

    6. Re:Co-workers by clone53421 · · Score: 1

      Job security, eh?

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    7. Re:Co-workers by Nerdfest · · Score: 1

      An excellent idea. Best to get it out of the way up front, as that's what tends to happen to them anyway. Getting people used to them being correct is just setting them up for disappointment in the future.

    8. Re:Co-workers by ari_j · · Score: 1

      The only reason to use any kind of machine-readable format for comments is to exploit vulnerabilities in the program that does the reading. Ideally, you can get the auto-documentation system to produce more lies on top of your own.

    9. Re:Co-workers by element-o.p. · · Score: 1

      I've seen a couple of comments along the lines of, "This is an ugly hack, but I don't know of a better way to do this." IMHO, it's usually a developer who knows that there's got to be a better way of doing something, but is running into a constraint of the language. Of course, I typically work in Perl, so it's somewhat to be expected :)

      --
      MCSE? No, sir...I don't do Windows. Yes, I am an idealist. What's your point?
    10. Re:Co-workers by Anonymous Coward · · Score: 0

      That explains a lot thanks! I grep'd the code and could not for the life of me figure out why 'old MacDonnald needed to be incremented before Little Miss Muffet sat on her tuffet' ..

    11. Re:Co-workers by Abcd1234 · · Score: 1

      True enough. Any kind of external dependency may force hacky solutions to problems, be it buggy libraries or a wonking programming language (BTW, I quite enjoy writing Perl, but it's definitely... idiosyncratic :).

      But in a case like that, it's important that the developer describe what they'd like to do, and why they settled on the solution they selected, so that someone coming along later can understand why it's written the way it is.

    12. Re:Co-workers by Abcd1234 · · Score: 1

      Comments need maintained.

      So do design documents and test suites. Are you suggesting we shouldn't bother with those, either?

    13. Re:Co-workers by Frequency+Domain · · Score: 1

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

      So do the majority of my students.

    14. Re:Co-workers by Thing+1 · · Score: 1

      Other responder to this AC suggested design documents and test suites.

      I will also add: the source control revision history will clearly show you whether the code was changed last, or the comment. I leave it as an exercise to the diligent reader to determine which is more current, and adjust appropriately.

      --
      I feel fantastic, and I'm still alive.
    15. 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.
    16. Re:Co-workers by ari_j · · Score: 1

      If you're teaching people to code, point them to the guide How to Write Unmaintainable Code. It teaches this and other lessons and is a much more poignant way to get some of the points across than just giving a laundry list of not-to-dos.

    17. Re:Co-workers by Anonymous Coward · · Score: 0

      > Comments need maintained. /* removed unnecessary 'to be' from this line, but forgot to document it - AC 17NOV09 */

    18. Re:Co-workers by Cederic · · Score: 1

      db.connect;
      if (db.schema == null)
            db.setSchema(newSchema);
            db.loadTemplate(initialTemplate);
            db.configureNode(Nodes.getInitialNode());
      db.addNode(node); //etc

      Sorry, but how exactly do your comments add value to the code? Why on earth would you write code any more complex than my example (syntax aside) for so simple a task?

      Sure, 'db' may not have the necessary methods, but I can replace steps 3,4,5 with a method called

      initialiseDatabase(db);

      that hides the complexity, and thus retains readability. And nobody has to maintain the comments. Nobody has to go mad reading

      # 1. Initiate communication with database
      db.connect();

      You may not code maliciously, but the effect is much the same.

    19. Re:Co-workers by Anonymous Coward · · Score: 0

      Nobody has to go mad reading

      # 1. Initiate communication with database
      db.connect();

      That's missing the point: comments are not supposed to explain what or how, but why the code is written that way.

      I had an astute programming instructor who made this abundantly clear. He wrote on the board: "a = 0; /* set a to 0 */" and told us, "anyone I catch doing this will be SHOT!"

  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
    1. Re:comments explain what isn't there by Kenja · · Score: 1

      I always add // And then a miracle happens!

      --

      "Have you ever thought about just turning off the TV, sitting down with your kids, and hitting them?"
    2. Re:comments explain what isn't there by b4dc0d3r · · Score: 1

      Comments are for bug fixes. You see what was in there and makes sense, and then there's a hackish line that makes no sense - so you comment that the data source has a bug and this is a workaround.

      So your comment applies for new code, but then all of the bug fixes need explanation.

    3. Re:comments explain what isn't there by clone53421 · · Score: 1

      Even better, a properly situated miracle = God("please"); works wonders.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    4. Re:comments explain what isn't there by Anonymous Coward · · Score: 0

      Bravo

      I'd add that comments can also directly address the coded logic - but the real issue is that comments should say why - the code already says how

  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 pem · · Score: 1

      Yes, back in the 90's, I worked with a junior developer who thought that everyVariableMustTellItsOwnStoryIncludingItsLifeHistoryInItsName. He misspelled one of these gems, and I was grepping for a solid half hour before I figured out why I couldn't locate it, after glancing at the name in one of the source files.

    2. Re:bad spelling in variables/etc get me by Anonymous Coward · · Score: 0

      in general poor spelling - category vs. catagory, etc.

      Ugh. Now this is an excellent example. Even if your code is great in every other respect, this kind of error makes it unusable shit. And in reality, it's a strong indicator that it's probably written by a moron and will be unusable in many other ways.

      Or correct but "alternative" spellings - like honor_no_cache vs. honour_no_cache

      Like any other style issue, pick a convention a stick with it. 'Murkins have no trouble using and contributing to OGRE, even though it uses British spelling extensively. As long as it's consistent, it doesn't really matter.

    3. Re:bad spelling in variables/etc get me by ari_j · · Score: 1

      Find/replace is dangerous in that situation, because it's possible that the correct spelling has been used for something else. I really despise bad spelling in variable and function names, and really in general in life, but you have to watch out for the case where honor and honour are truly different variables.

    4. Re:bad spelling in variables/etc get me by TheRaven64 · · Score: 1

      One (non-)word: creat().

      --
      I am TheRaven on Soylent News
    5. Re:bad spelling in variables/etc get me by BrotherBeal · · Score: 1

      I see this as a corollary to a phrase a Latin professor of mine used to use all the time: "Clarity of grammar is clarity of thought."

      If you haven't taken the time to think through what you mean in order to translate it from concepts into words, then there's a high probability that you have missed something at the conceptual level and are hiding it in the noise and ambiguity of language. Misspelled words such as variable names or even misspellings in comments, ESPECIALLY when they're not consistently misspelled, strike me as the same sort of disregard for the rules of the system and throw up a big red flag that something may not be as it should. At best, it's an impediment to grep, but frequently I find that misspellings in and around code mean that there is more work to be done.

      --
      I'm disabling ads until because I choose not to reward redesigns that are less usable than "view source".
    6. Re:bad spelling in variables/etc get me by Anonymous Coward · · Score: 0

      I'd be cautious about passing off such a coder as "a moron". It's very common for very bright and skilled coders to be dyslexic. Their spelling makes it real easy to pass them off as dumb, uneducated or lacking in attention to detail, but it's not their fault. And you'd miss out on cream of the crop talent by passing on such a coder.

    7. Re:bad spelling in variables/etc get me by Cyberax · · Score: 1

      Well, it's better than InitializePrintProvidor.

    8. Re:bad spelling in variables/etc get me by Anonymous Coward · · Score: 1, Funny

      Yeah, I can't believe how badly they typo'd the word REEFER.

    9. Re:bad spelling in variables/etc get me by plague3106 · · Score: 1

      Well using a decent tool eliminates this problem. VS2008 has a smart rename that alerts you to that problem.

    10. Re:bad spelling in variables/etc get me by Monkeedude1212 · · Score: 1

      Double standards also cause these problems - we had a Web page designer and a coder to handle the back end of a web page form. Simple form, name, number, address, email, and a few handful of other things, basically to get some client info.

      But because the coder was used to putting underscores to seperate words where the web page designer just uses a new capital Letter, basically this_and_that versus thisAndThat.

      In the end, about 2 of 15 fields worked properly, making the entire thing pretty much useless. I don't know how - I don't know why - but this was pushed live to production and remained that way for 3 years before anyone noticed. I took one look at it and went insane.

    11. Re:bad spelling in variables/etc get me by Anonymous Coward · · Score: 0

      I'd be cautious about passing off such a coder as "a moron". It's very common for very bright and skilled coders to be dyslexic. Their spelling makes it real easy to pass them off as dumb, uneducated or lacking in attention to detail, but it's not their fault. And you'd miss out on cream of the crop talent by passing on such a coder.

      I'm sorry, but "cream of the crop talent" does not get a pass because they are "lacking in attention to detail". If they lack attention to detail, then they simply are not "cream of the crop talent".

    12. Re:bad spelling in variables/etc get me by The+Iconoclast · · Score: 1

      I think you mean it is a 'bare' to deal with. :P

      --
      Quando Omni Flunkus Moritati
    13. Re:bad spelling in variables/etc get me by Anonymous Coward · · Score: 0

      Fair enough, genuine dyslexics get a pass on the moron comment. It doesn't make poor spelling any less of a problem, though.

    14. Re:bad spelling in variables/etc get me by Ray · · Score: 1

      That's why it's best to stick with meaningless acronyms and abbreviations. A bit of hnc and ctg would've fixed that right up. ;)
       

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

    16. Re:bad spelling in variables/etc get me by tool462 · · Score: 1

      It can be really unfortunate when spelling errors get made in some widely used function, hash key, or whatever. It becomes so entrenched that you are forced to stick with it. I cringe every time I have to type one in.

    17. Re:bad spelling in variables/etc get me by Anonymous Coward · · Score: 0

      By alternative, you mean British english? You know the "alternative" version of english that is used by the country where the language started. There are more countries practicing this "alternative" version than the US standard. Also, how you think that using British spelling somehow affects comment quality or is indicative of poor spelling is amazing to me.

    18. Re:bad spelling in variables/etc get me by rgviza · · Score: 1

      LOL so true... Hopefully I won't be around when one of the perfect programmers decides to fix the spelling of this.

      --
      Don't kid yourself. It's the size of the regexp AND how you use it that counts.
    19. Re:bad spelling in variables/etc get me by R3d+M3rcury · · Score: 1

      My favorite was a guy I worked with who wrote code to handle inventory valuation and such. He continually misspelled "received" as "recieved."

      I merely added a comment into his struct definition that said, "recieved is misspelled for historical reasons."

    20. Re:bad spelling in variables/etc get me by shentino · · Score: 1

      Having two variables named so closely together is IMHO itself a sign of bad design.

      Generally, the proper way to do a find/replace is to first do a find on the target, to make sure you don't have a collision.

    21. Re:bad spelling in variables/etc get me by ari_j · · Score: 1

      This essay says that it's good practice.

    22. Re:bad spelling in variables/etc get me by Anonymous Coward · · Score: 0

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

      It's nice being able to define functions like setColour and getCentre without ever having to worry about conflicting with a reserved word or library function.

      In fact, the only common keyword I can think of that the americans share with us is "class", ironically...

    23. Re:bad spelling in variables/etc get me by Blakey+Rat · · Score: 1

      Oh man, that one pisses me off every day. (I work with web analytics.)

    24. Re:bad spelling in variables/etc get me by stephows · · Score: 1

      correct but "alternative" spellings

      Which is why those of us outside the US grind our teeth when we have to use the 'wrong' spelling for functions like SetColor() .

    25. Re:bad spelling in variables/etc get me by i.r.id10t · · Score: 1

      So lets say you have a team of 5 British coders (or Canadians, etc) and you add an American to the mix... either way, what one group has learned as the "correct" way to spell it is the "alternative" way for the other member(s)

      Not saying which is right and which is wrong, just that it helps for everyone to use the same spelling...

      --
      Don't blame me, I voted for Kodos
  6. My comments are pretty works of art by Anonymous Coward · · Score: 0

    /*
      * get_tail(node* list)
      * gets the tail!
      */

    Damn you racist filter!
    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 b

    1. Re:My comments are pretty works of art by ari_j · · Score: 1

      /*
      * get_tail(node * list)
      *
      * This function destructively sorts the list with the tail element
      * as the new head of the list and the remaining elements
      * sorted according to their hamming distance from the tail element.
      */
      node * get_tail(node * list) {
      /* The code here does nothing of the sort, and actually returns the
      * element with the highest-valued md5 hash, but only after freeing
      * the original list. */
      }

    2. Re:My comments are pretty works of art by digitig · · Score: 1

      /* * get_tail(node* list)
      * Throws BadParameterException if list is null.
      * Returns a null pointer if list is empty
      * Otherwise returns a pointer to the last entry in list.
      * Ownership of the memory remains with list.

      --
      Quidnam Latine loqui modo coepi?
    3. Re:My comments are pretty works of art by tgrigsby · · Score: 1

      The guy that wrote the second comment should be slapped. If the function has been changed to do something else, then change the comment. I've seen examples of the same thing, and this isn't commenting so much as ego: "You're stupid and I'm smart and this is how I'm going to show everyone that I'm smarter than you, so THERE!" It's juvenile, and it eventually will bite you in the butt.

      It's like making a smartass remark about your boss in your comments, thinking that he'll never see it...

      --
      *** *** You're just jealous 'cause the voices talk to me... ***
    4. Re:My comments are pretty works of art by ari_j · · Score: 1

      The second comment would be removed when the actual code is inserted to do what it says. I apologize that I was not clear about that.

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

    1. Re:Seems reasonable by Tablizer · · Score: 1

      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.

      Not necessarily. Some may be anal about thing A but not thing B. I observe a lot of this in tech. Techies tend to have pet obsessions, and people vary too much to make reliable generalizations like that. Damn that recombinant DNA! Often there's not enough time to be fastidious about everything, so trade-offs have to be made.
           

    2. Re:Seems reasonable by CastrTroy · · Score: 1

      Also, along the same lines. If you are limited by time constraints, as most developers in the real world are, you would be much better off spending your time writing clear and concise code, and leaving out the comments entirely, than to spend time writing comments and code, simply because of some belief that comments must be there. Quite often, comments fall out of date with the code that was written, as they aren't updated every time the code is updated, and at that point, only serve to confuse the user.

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    3. Re:Seems reasonable by Anonymous Coward · · Score: 0

      "your" huh?

    4. Re:Seems reasonable by jgtg32a · · Score: 1

      Sue me I was in a rush to write a semi-intelligent comment to get a +5 Insightful/Interesting; and your is shorter than you're.

    5. Re:Seems reasonable by Anonymous Coward · · Score: 0

      Fortunately, you don't have to spend any time or effort on your grammar when posting to Slashdot.

    6. Re:Seems reasonable by Anonymous Coward · · Score: 0

      [...] willing to spend time on the comments your most likely going to spend [...]

      Ouch.
      you're.

  8. Excuses... by Anonymous Coward · · Score: 0

    The only times I find myself making excuses is when management didn't properly give the requirements or change the requirements to late in the game...so you have to make bad programming decisions as a band-aid until a complete rewrite can be done proper...just to meet a deadline that was shortened or a deadline that was insanely impossible because someone oversold your departments abilities...or a deadline that doesn't adjust to the new fangle features that were always supposed to be in there. Not everything is the prgrammer's fault in this world...in fact I think you'll find that very little of it is to be laid to rest at the programmer's feet. Expectations are high, pay is low, and management simply assumes cause there are teenage kids telling them they can write the same thing in shorter time means they know what they are talking about when they don't have the slightest clue...haven't coded anything over 500 lines of code.

  9. Nonesense by Anonymous Coward · · Score: 1, Insightful

    Many people who write code are not native English speakers. it would be silly to expect their code or comments to read like a Thomas Hardy novel.

    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.

    Someone who wastes time producing grammer-school perfect comments is wasting time that could be better used by making the code itself better.

    1. Re:Nonesense by Yvan256 · · Score: 1

      /* What you mean, my comments not good? My comments very good! You very bad man! */

    2. 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.
    3. Re:Nonesense by JesseMcDonald · · Score: 1

      If the code evolves, fix the comments.

      Or at least delete them, if you can't be bothered to keep them up-to-date. It's better to have no comments than to have misleading ones. (The old comments are recorded in the repository, right? If so, you're not really losing anything.)

      --
      "The state is that great fiction by which everyone tries to live at the expense of everyone else." - Bastiat
  10. // 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. */

    3. Re:// teh code is obvius by R3d+M3rcury · · Score: 1

      What are these "comments" of which you speak? These sound intriguing and I'd like to subscribe to your newsletter...

    4. Re:// teh code is obvius by Anonymous Coward · · Score: 0

      Rather a wimp than a ****ing idiot.

  11. 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 JoshuaZ · · Score: 1

      That's true for standard algorithms. But sometimes one is working with an algorithm that is either too new or too obscure to appear somewhere. This often occurs most obviously when what one is coding is related to one's own research. Sometimes also the algorithms aren't that obscure but one just knows the result as a sort of folk-lore rather than peer reviewed or included in a useful book like Knuth. For day to day programming this happens surprisingly often.

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

      You could always put that kind of explanations in a separate NOTES file though.

    4. Re:Long-winded comments can be very useful by pz · · Score: 1

      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.

      I am similarly long-winded when I optimize code and end up using a particular, sometimes non-intuitive, phrasing because it ends up being faster. I leave as much of the evidence and analysis in the comments as possible -- as the parent wrote, mostly so I don't need to convince myself again at a later time. If there's a magic number, I provide the derivation of that number (e.g., explaining why 2 seconds is an appropriate timeout for a file transfer, and giving the empirical evidence). Sometimes I'll even leave in commented out versions of the code that were particularly tempting, but that ultimately proved to be incorrect or slower. But the MOST important version of these long-winded comments is when I'm going balls-to-the-wall for execution speed and the optimized code ends up being non-intuitive. Then, I include the original source (that was previously shown to be correct) and any important intermediate stages in developing the final form, so that the optimized version can be validated.

      Of course all of these different long-winded comments are important when the code itself is not clear, when there is substantial reasoning that was required to create the code, and when the code does not itself contain that reasoning at first inspection. When writing high-quality code the first priority is correctness, and a very, very close second is clarity.

      --

      Put my fist through my alarm clock with its ding-dong death inside my ear. - The Blackjacks.
    5. 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.

    6. Re:Long-winded comments can be very useful by tgrigsby · · Score: 1

      I completely agree: I have, at times, given a short explanation and included a reference to a design document, published work, or Internet resource. It would not only be a waste of my time to include the entire referenced content, but that content might change over time and I see a huge benefit in having code updated based on updated specs. Credit card number encoding and ranges or UPOS interfaces are good examples of this.

      --
      *** *** You're just jealous 'cause the voices talk to me... ***
    7. Re:Long-winded comments can be very useful by clone53421 · · Score: 1

      I'd argue for in-lining the proof, or at least a enough of a basis whereby its validity is assured. Two reasons: (1) Sources change. Wikipedia today will not be Wikipedia tomorrow. Even a printed resource may be difficult to obtain someday. (2) Comments fold in nearly any decent editor. There is no reason to allow them to interrupt the reading of your code.

      Honourable mention should also go to (3) Comments do not affect the running of your code in the least, so there's no real need for unnecessary brevity on that account.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    8. Re:Long-winded comments can be very useful by FrankSchwab · · Score: 1

      It would not only be a waste of my time to include the entire referenced content, but that content might change over time and I see a huge benefit in having code updated based on updated specs. Credit card number encoding and ranges or UPOS interfaces are good examples of this.

      Are you really saying that by linking to a reference rather than including the content directly, you expect your code to get automatically updated for you?

      I am interested in your theories and would like to subscribe to your newsletter.

      Or are you saying that when I read your code 2 years later, click the link to read the latest Credit card number encoding and see version 3.7 of the spec where you implemented 2.2, I should "just know" that the code represents a solution to a different spec than the current one?

      Frankly, directly include content so I know what you think you implemented.

      /frank

      --
      And the worms ate into his brain.
    9. Re:Long-winded comments can be very useful by JesseMcDonald · · Score: 1

      Who said anything about external references? You could just point to a separate file in the same source-code distribution. Most large project have a directory set aside for documentation; use it.

      IDEs and source-code-oriented editors are nice, but in my opinion one should be able to read and edit source code in a pure plain-text editor (or web browser, e.g. for browsing SVN repositories online) without getting completely lost in embedded multi-page proofs only incidentally related to the code. Long explanations should go into separate files for much the same reasons that source modules are divided into separate files; among other things, long files are harder to navigate and search through, regardless of how advanced your editor may be.

      --
      "The state is that great fiction by which everyone tries to live at the expense of everyone else." - Bastiat
    10. Re:Long-winded comments can be very useful by DHM · · Score: 1

      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.

      I agree 100%, and would add that this can even happen with good programmers. A few years ago I worked at a company whose culture was deeply invested in the XP "comments are a code smell" philosophy. The engineers were all extremely bright, but as a newcomer I found the code to be difficult to work with, in part because there were no comments anywhere. No API docs, no explanations of hacky code (there was plenty of hacky code, by the way), no nothing.
      The idea was that 1) if code is not clear without comments, it should be rewritten to make it more simple, and 2) if you need help understanding someone's code, just walk over and ask him/her about it. Well, regarding 1), I was trying to maintain/improve some nasty code which had been touched by multiple people over several years and it didn't seem like its lack of comments had led to any kind of refactoring or simplification. And regarding 2), the company now no longer exists, and while the IP now belongs to another company, all of the original engineers have moved on to bigger and better places. I bet the people who had to take over the code would not have minded the additional "smell" of a few well-placed comments. :-)

    11. Re:Long-winded comments can be very useful by gabebear · · Score: 1

      The longest comments I've written are definitions of terminology. If I'm working on a problem that is truly unique, I'll make up terminology for the different parts of the problem so that I can write short simple comments throughout the rest of the code.

      I normally put these in the primary header file, but it probably is a better idea to put these in a separate file.

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

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

    1. Re:Well, duh. by NoPantsJim · · Score: 0

      Same here. I'm the only one that touches my code. My stance is that if I can't figure it out without a comment, then I didn't know what I was doing to begin with.

    2. Re:Well, duh. by Eudial · · Score: 1

      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.

      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. But that's because the professor (or rather, the TA:s) need to quickly read through 50 or so computer lab reports every couple of weeks, and doing so without comments takes ages (especially what with the more dubious code that occasionally gets handed in.)

      Documenting module interfaces is generally a good thing, but actually littering the implementation with comments is quite another (unless there is some outstanding reason to do so).

      --
      GAAH! MY PRINTER IS ON FIRE!!! PUT IT OUT! PUT IT OUT!
    3. 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.
    4. Re:Well, duh. by McNihil · · Score: 1

      Natural language in code tend to distract at best and mislead at worst. Also when coding is done with users writing comments in their preferred natural language (and character set) it just goes to hell.

      If the code is not clear to understand then it should be re-written so that it is much clearer. Spending time writing clear code is far more superior than writing bibles of comments because no matter what you write in the comment there will be bugs in the code.

      If I get unknown code from anyone I ALWAYS strip out the comments... the comments mean nothing to me... the code does mean everything... also one gets to understand how the original author was thinking... thus knowing where they most likely would have coded wrong and where there is a problem with the data structure.

      Comments were useful back in the day when the code base was very small and a manager could potentially feel good by reading pages and pages of commented source code... this however is mere self gratification for the managers and has nothing to do with how good code really is. I'd rather have good code than code that is commented well so that a lay person can "read the code."

    5. 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... ***
    6. Re:Well, duh. by plague3106 · · Score: 1

      I see you've never maintained anything for a few years. I've looked at code not sure why something was done, and it makes it harder to maintain. Of course the answer is usually "business requirements," but knowing the exact one is helpful, especially if its no longer a concern.

    7. Re:Well, duh. by ericspinder · · Score: 1

      . But that's because the professor (or rather, the TA:s) need to quickly read through 50 or so computer lab reports every couple of weeks, and doing so without comments takes ages

      However in the business world we have all the time in the world?

      --
      The grass is only greener, if you don't take care of your own lawn.
    8. Re:Well, duh. by Kjella · · Score: 1

      But if you can't rely on the comments because they're often bogus, and you know that even if you spend time writing good comments the next guy won't believe the comments either and go check the source anyway, then what? One man cant turn the comments from a timesink into an asset, there must be a shared confidence in them. That's where all the bad training comes from.

      --
      Live today, because you never know what tomorrow brings
    9. Re:Well, duh. by Anonymous Coward · · Score: 0

      Dealing with this exactly. Maintaining code from a third party contractor who decided to put all sorts of neat bells and whistles and new programming paradigms and yadda yadda in his code. It's all very well put together and works well, but there are ABSOLUTELY NO COMMENTS. Sure, I can figure out what each class and each method does, but a simple one line comment at the head of each function would cut my reading/comprehending time down exponentially. Is this the method I wants? Hmm, let me read the whole thing, interpret what it does, evaluate if that fits... Even a simple /* Prints form xyz */ would save me a lot of time/headaches.

      And don't presume that "well, I know what it does and i'm the only one coding it" because a year from now you'll be cursing yourself for not commenting when you can't figure out what the f* you were thinking when you wrote that code...

    10. Re:Well, duh. by Eudial · · Score: 1

      . But that's because the professor (or rather, the TA:s) need to quickly read through 50 or so computer lab reports every couple of weeks, and doing so without comments takes ages

      However in the business world we have all the time in the world?

      In the business world you have hopefully more experienced programmers than the average undergrad. (Okay, some undergrads are pretty good, but the bulk of them are mediocre.) And as such, the code can be expected to be of higher quality.

      Furthermore, it is important in studying computer science to show that you actually understand the assignment, beyond managing to get the code to work as expected through trial and error or lifting examples from the internet / literature.
      Comments are integral to demonstrating that, knowledge, but there is no need for doing that in actual application development.

      --
      GAAH! MY PRINTER IS ON FIRE!!! PUT IT OUT! PUT IT OUT!
    11. Re:Well, duh. by ericspinder · · Score: 1

      In the business world you have hopefully more experienced programmers than the average undergrad.

      You weren't talking about the 'average undergrad' reading the code, but the Professor, and his TAs. Somehow you seem to think that academics are the only people who need to understand code quickly.

      Comments are integral to demonstrating that, knowledge, but there is no need for doing that in actual application development.

      I read that as: "I don't comment code, it's only good for showing that you've learned your lesson". Sounds to me that you were taught properly in college, but just don't 'like' to do it in real life.

      Truly good code is both 'easy to follow' (for a coder of appropriate skill) and well documented. Bad code is neither. Good code and bad documentation (inline and external) is generally acceptable, but harder to learn/fix/change (well, without errors).

      I don't have the time/energy to produce documentation appropriate for everything that I do, but at least I don't lie and say that it is never needed.

      --
      The grass is only greener, if you don't take care of your own lawn.
    12. Re:Well, duh. by carrier+lost · · Score: 1

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

      Sort of like the guy who declines to explain something to you because, "It's too complicated"

      The inability to provide a simple layman's definition is, to me, a sign that someone really doesn't know his stuff all that well.

      Either that, or he just doesn't like you much.

    13. Re:Well, duh. by Thing+1 · · Score: 1

      I see your Steaming Heap of Innovative Technology, and raise you one Critical Update Notification Tool. (Yes, it really existed!)

      --
      I feel fantastic, and I'm still alive.
  13. 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
    1. Re:Sounds right by smallfries · · Score: 1

      Wow, zero spelling mistakes, and one minor grammatical error - you seem to have poked fate in the eye and survived.

      --
      Slashdot: where don knuth is an idiot because he cant grasp the awesome power of php
    2. Re:Sounds right by MrSenile · · Score: 1

      Not entirely true. I've put in comments and sidelines in code when you had to put in code to get around anomalies in compilers, or sadly still, poor design decisions on 3rd party software you don't have time to work around or don't have the authority or decision to work around that you're forced to include as an API or maybe a subset library.

      For example, in an older glib if you had time_t defined before a char * pointer, you could mess up with the stack on the linker.

      Other platforms have certain library calls and/or function calls that are slightly different and require different methods to attack with various #ifdefs or autoconf changes. Having a bit of rhetoric to define why you did something the way you did, guarantees that the next person to pick up your code won't spend unnecessary time digesting code that a simple 20 second read followed by an 'oh yea, that's right' would solve.

      In today's world, making things as fast as possible to do 'catch up' could make the difference between 'make' and 'break' in the corporate model.

    3. Re:Sounds right by Brad+Eleven · · Score: 1

      It's a mixed bag, i.e., a blessing and a curse.

      I once inherited 10,000 lines of C source running under SCO Xenix (circa 1990) with exactly two comments, viz "Watch out, this part's tricky," and "Just in case." The code featured one- and two-letter variables, heavy variable reuse, and, yes, GOTOs. The only two parts that were difficult were the custom curses and termio "modules".

      Then there was the stuff written for DOS that had uneven numerical/ASCII conversions.

      Fortunately, my boss understood the problem and gave me time to figure out, fix, and document the source. It was maddening at times, but at the end of that tunnel, I'd learned a lot about several topics that I don't think I could have figured out without having to implement it myself.

      After fixing the bugs, the next task was to implement a new feature. I was very glad I'd taken the time to document everything before adding to the monolith.

      Then my boss gave me 30 days off to make up for the extra hours I'd worked without compensation. He asked that I check voicemail daily and remain available. Meanwhile, they fired my old boss and neglected to tell me. On the day I returned, my new boss stopped me before I'd even reached my desk to tell me that he was my new boss, and that they'd be taking the unauthorized vacation out of my paychecks. I stood there, wondering what it was that held me there, and found nothing. I said, "You know what? I quit." I turned to leave, and the new guy grabbed me and said, "But you're the only one who knows how this thing works, now!"

      I replied, "Exactly," and left. I did not look back. Armed with my recently acquired expertise, I found a job paying exactly twice the salary I had. A month later I heard that they had re-enlisted the contractor who'd written the crappy code. He charged them $1000/day to rewrite my revisions back into his cryptic style in 100 days, then another $100K to re-implement the new features I'd put in.

      The supreme irony is that I'd been hired because they didn't want to shell out for his $50K bid to add the features they wanted. My original boss also wanted FTEs to provide continuity.

      (shrug) A year later the CIO was convicted for an elaborate price fixing scheme, but received a lenient sentence because the scam relied on that same contractor's code--which was deemed unreadable, making the criminal intent difficult to prove.

      --
      "Press to test."
      (click)
      "Release to detonate."
    4. Re:Sounds right by clone53421 · · Score: 1

      Wow, I actually went back and re-read his entire comment – twice – to try to find the "minor grammatical error". I still didn't find it.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    5. Re:Sounds right by smallfries · · Score: 1

      I did say it was minor - you'd have to be really picky to spot it (like most editors). Where he says "it won't spot it", it's obvious that the first "it" refers to the compiler at the beginning of the sentence, but grammatically the "it" refers to "local", as in the local variables he was just discussing. Many would argue that it is not an error as such, but it is ambiguous at best. Still far and away, the most grammatically correct I've ever seen on slashdot.

      --
      Slashdot: where don knuth is an idiot because he cant grasp the awesome power of php
    6. Re:Sounds right by clone53421 · · Score: 1

      Ah, yes, you're correct. "It won't spot this" would clear up any confusion.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    7. Re:Sounds right by kartan · · Score: 1

      If your grammar is poor in the English then it's probably poor in the code too (unless you are not a native speaker).

      Not sure if this is what GP was referring to, but this "the" seemed gratuitous to me.

    8. Re:Sounds right by LMacG · · Score: 1

      So you're saying that the scope of the pronoun was ambiguous?

      --
      Slightly disreputable, albeit gregarious
    9. Re:Sounds right by smallfries · · Score: 1

      Essentially. The scope of the pronoun is not actually ambiguous - it always refers to the most recent object of speech. But many people would claim that the commas in the sentence are parenthesis in disguise and that compiler was the most recent object. These people are of course wrong, but common enough that it is best to humour them.

      --
      Slashdot: where don knuth is an idiot because he cant grasp the awesome power of php
    10. Re:Sounds right by clone53421 · · Score: 1

      parentheses

      ;p

      The main problem is that "it" is used twice, referring to two different things (the compiler, and the error). Pronouns don't work that way.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    11. Re:Sounds right by smallfries · · Score: 1

      OK, I have sacked my spellchecker and will make sure that it never works again ;)

      --
      Slashdot: where don knuth is an idiot because he cant grasp the awesome power of php
  14. See Previous Story: Agile Is by Anonymous Coward · · Score: 0

    NOT using MicroSLOP. I 'm sure you the know the intended reference.

    Yours In Astrakhan,
    K. Trout

  15. 10 PRIN "WTF" by mcgrew · · Score: 1

    This seems like a no-brainer to me. Sloppy people are sloppy and stupid people are stupid, how is this not evident? The only difference is that a lot of bugs are obvuous, 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.

    There are a lot of times I'll see slashdot comments like "you might loose your mind" and I think "I hope that guy's not a programmer." Loosing your mind is quite a different thing than losing it, and like some software bugs might not be evident the first time the code is run.

    1. 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
    2. Re:10 PRIN "WTF" by dkh2 · · Score: 1

      The classic is a block of select_case logic with no default. The developer is given a static list of current cases for which results are calculable. Yet, they #FAIL to consider that the case list may be not as finite and immutable as presumed. When a new case is presented then code without a default response will fail.

      --
      My office has been taken over by iPod people.
    3. Re:10 PRIN "WTF" by clone53421 · · Score: 1

      obvuous

      Must... refrain... from... commenting...

      Loosing your mind

      Elicited a "wut" reaction from me, until I read the rest of the sentence and realized you'd meant to say that. ;)

      I agree with you, anyway – I read the headline and though, "well, duh."

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
  16. Comment removed by account_deleted · · Score: 2, Insightful

    Comment removed based on user account deletion

  17. I'd rather... by Purist · · Score: 0

    ...see somewhat verbose comments than none at all. However, a good developer should be able to provide very clear and concise comments and let the code say the rest. I think this is what the original post's point is - of the code is not concise and clear, the comments won't be either. P

    --
    I used to fear clowns...but I'm discovering that chimps are far, far, worse.
  18. 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
    1. Re:Non-native English speakers by Rakshasa+Taisab · · Score: 0, Flamebait

      Thank you for your understanding of the lacking language skills of us non-native English speakers.

      Now take your fucking prejudices and go play wow or something.

      --
      - These characters were randomly selected.
    2. Re:Non-native English speakers by mcgrew · · Score: 1

      English is not most people's first language.

      Neither is COBOL, Fortran, C, Java...

    3. Re:Non-native English speakers by tepples · · Score: 1

      It takes longer to become competent in English than in Python, Java, Perl, etc.

    4. Re:Non-native English speakers by Anonymous Coward · · Score: 0

      And I suppose you're "John" when we get you on the phone. That is, when we can even understand your clicking sounds. You sound like chimps or birds or anything except humans.

      Go be a sand nigger somewhere else, Patel.

    5. Re:Non-native English speakers by Anonymous Coward · · Score: 0

      I'd rather they wrote well in their own language, rather than in a pidgin version of mine.

    6. Re:Non-native English speakers by Anonymous Coward · · Score: 0

      I like to throw in some latin phrases for fun.

      I also use foreign language unicode characters for test values when i can.

    7. Re:Non-native English speakers by Anonymous Coward · · Score: 0

      I have to agree with this one. I've known plenty of people who are absolutely phenomenal programmers and can't spell for s*** (many of them were non-native English speakers). Language competency and attention to detail have no real correlation. I really detest broad sweeping judgements like this... It's just incredibly ignorant. Also, just because someone isn't OCD to that extent doesn't mean that they aren't good programmers; they just don't place as much value on spelling/language errors in comments as they do on the code. As long as the code itself is solid, errors in comment language aren't really that important.
      (I have a Master's degree in English as well as Computer Science, but I realize when language can take a back-burner to correct code.)

    8. Re:Non-native English speakers by ignavus · · Score: 1

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

      Some lines of Perl look like they were written by a baby at the keyboard.

      34;#(*$(*%)FKF))#$_

      Surprisingly, that is a valid Perl program.

      --
      I am anarch of all I survey.
    9. Re:Non-native English speakers by Anonymous Coward · · Score: 0

      It really depends on the programmer.

      I've seen code that was written by a Japanese guy, with all comments in Japanese - which turns out to be mostly machine-translatable (yay babelfish). Given that he marked a few methods with "not impremented", I'm glad he did it in his native language.

      Of course, it also ended up being that he had reasonably clean code and it was faster and easier to just ignore the comments... English proficiency was definitely not tied to programming ability.

    10. Re:Non-native English speakers by clone53421 · · Score: 1

      You apparently haven't met many programmers.

      My personal experience is only from college, but I can assure you that most of the students were better in English than they were in C++. They couldn't code their way out of a wet paper bag. Most of the time their syntax was decent, but the algorithm was completely wrong. ("No failure is quite so disheartening as creating a complete solution to the wrong problem," or something to that effect.)

      Maybe English is a little harder, but it's not drastically so.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
  19. Arguments for and against by NtwoO · · Score: 1
    One of the best programmers on our team can not spell to save his life. He also does not touch type (a proficiency I always considered a basic requirement when interfacing with computers for your profession). He thus proves that it is not a hard and fast rule.

    That being said, we work in a company where virtually all code is reviewed. Long winded comments introduce maintainability issues, since the comment can diverge from the working in time. Extensive spelling mistakes in them certainly becomes irritating, especially since there are plenty of good editors available with spell checking included. That just points to sloppiness. Not bothering to use a tool's features shows no pursuit of excellence and that certainly places doubts on the rest.

    --
    ! /* */
    1. Re:Arguments for and against by mcgrew · · Score: 1

      Extensive spelling mistakes in them certainly becomes irritating, especially since there are plenty of good editors available with spell checking included

      Dew knot truss you're spill chucker.

    2. Re:Arguments for and against by NtwoO · · Score: 1
      I never said trust your spell checker implicitly, I said, use it. There is a huge difference.

      We are outsourcing a project to India and I review the code. One of the coders delivered a file absolutely riddled with spelling mistakes. I know that the code was reviewed by one of the senior Indian programmers, so the code had some errors, but the spelling was useless. A few code deliveries later, a module written by the same coder was checked in without review by accident. The quality of the code was absolutely horrendous! Most art or law students would would write better code. It resulted in a breach of confidence within our management that the outsourcing company will not recover from it.

      --
      ! /* */
    3. Re:Arguments for and against by Zet · · Score: 1

      If people are not keeping the comments in synch with
      the code, *that* is the maintainability issue. Bad
      comments (not concise, not informative, not clear)
      may be harder to keep up-to-date, but that's not any
      different from poorly-written code being hard to
      understand or update.

      Comments should be viewed as an intrinsic part of the
      code--and if you change the machine-oriented part you
      better be sure that the human-oriented part is updated
      to reflect the change. And if necessary, improve the
      comments while you're at it.

  20. Bad spelling too often = bad thinking by gestalt_n_pepper · · Score: 1

    Or at least sloppy thinking. I have no idea why this is, but as anyone who has looked at internet blogs can attest, the people who can't be bothered with proper spelling, grammar, punctuation or capitalization, or who can't differentiate between "loose" and "lose" are also (usually) the biggest idiots.

    --
    Please do not read this sig. Thank you.
  21. Comment removed by account_deleted · · Score: 1

    Comment removed based on user account deletion

  22. You must be joking. by newdsfornerds · · Score: 1

    You expect computer people to know the difference between "your" and "you're?" Hah! Good luck with that. Most of the people I have worked with over ten years refuse to spell correctly or use proper grammar. If being literate was a requirement for employment, that could change.

    --
    Damping absorbs vibrations. Dampening is caused by moisture.
    1. Re:You must be joking. by clone53421 · · Score: 1

      *sigh*

      Sadly, all too true. I'll be happy if they simply refrain from using AIM-speak in their comments.

      My mom thinks it's "cute" 2 u, r, gr8, and so on. I've actually seen her type "you", then backspace over it and replace it with "u". It drives me crazy. At least she isn't writing code.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
  23. Not always true by cecille · · Score: 1

    Yes, spelling and grammar in comments are important for understanding, and proper spelling in variable names in particular makes it easier for developers after you to follow and track through code. However, I disagree with the generalization that long comments always mean you don't know what you are doing. Most of my code comments are 1-liners, but I always leave long comments for function headers so everyone is clear on what the inputs are. I also leave larger comments for equations that aren't immediately obvious, ESPECIALLY if the equations are coming from spec documents. A spec number, section number and explanation help developers FIND these things later and actually understand them. Spec documents in particular can be thick and it's not always easy to see at a glance how things are supposed to work. Plus, if there IS a mistake (let's face it, no one is perfect), it's way easier to track where something went wrong if you know what the start point is.

    --
    ...no two people are not on fire.
  24. 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.

    1. Re:Doesn't work by tsstahl · · Score: 1

      And yet you felt the need to comment on that too. Maybe you should rethink what your behavior is doing for you... ;)

    2. Re:Doesn't work by Yvan256 · · Score: 1

      How were you able to read what I wrote? It was a comment!

  25. 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 Anonymous Coward · · Score: 0

      Dim UntilTheCowsComeHome as Boolean
      UntilTheCowsComeHome = False

      Do ...
      Loop UntilTheCowsComeHome

    2. Re:I'm an expert! by McNihil · · Score: 1

      People may laugh at this (it is funny don't get me wrong) .... however it is not funny when you get this source dumped on your desktop to find a bug in the project and make a delivery later the same day.

      Function names... sed!

    3. Re:I'm an expert! by Nerdfest · · Score: 1

      kick_ass() should be specified in an interface. Chuck Norris is the implementation.

    4. 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.
    5. Re:I'm an expert! by Anonymous Coward · · Score: 0

      No-no-no...

      chuck_norris = true ...
      while(chuck_norris)

    6. Re:I'm an expert! by Verity_Crux · · Score: 1

      I have two comments, and they both go with a the same line of code:

      Application.DoEvents(); // the special sauce
      //Application.DoEvents(); // somebody's special sauce that needs to be done some other way

    7. Re:I'm an expert! by TheTurtlesMoves · · Score: 1

      however it is not funny when you get this source dumped on your desktop to find a bug in the project and make a delivery later the same day.

      As someone who has had that happen i assure you, its no longer funny, its hysterical.

      --
      The Grey Goo disaster happened 3 billion years ago. This rock is covered in self replicating machines!
    8. Re:I'm an expert! by Cederic · · Score: 1

      Surely his implementation merely ensured the donkey would be kicked whether it needed it or not?

    9. Re:I'm an expert! by clone53421 · · Score: 1

      Yes, but it didn't explain why. Code should be self-documenting, whenever possible!

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
  26. ES is not a prrogrammer by Anonymous Coward · · Score: 0

    She's a hack who likes dressing like a man, man !!

    1. Re:ES is not a prrogrammer by clone53421 · · Score: 1

      prrogrammer

      sttammererer?

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
  27. Job Security by Mekkah · · Score: 1

    I barely comment; JOB Security baby...

    I do however keep a personal notes file of the few items I find interesting, or harder to work out; JUST in case I can't remember or tie together wtf I was doing.

    --
    ~Mekkah
    1. 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.

    2. Re:Job Security by Mekkah · · Score: 1

      haha I'm okay, I work for the gov and I mainly do easy scripting. I was joking for the most part, because I'm to dumb not to comment on larger apps.

      But I would make a good car salesmen. Preferably used cars.

      --
      ~Mekkah
    3. Re:Job Security by dmgxmichael · · Score: 1

      Failure to comment doesn't secure your code - it just insures your code will be thrown away when the next guy comes in. It also increases the likelihood that your pissed off prior employer doesn't give you any references.

      I'm currently digging through a nightmare code base. Not only are there no comments, but there's NO INDENTING EITHER. At all. I don't see how the guy who wrote it got as far as he did but. I take that back - he did occasionally comment, but only to mark the end of loops and functions which would be obvious if he would have indented his blasted code.

      The decision has been made to patch what urgently needs to be patched in his code, then can it and start over from scratch. And I and my boss have already explained in detail to two calling in programmers exactly why it would be foolish to hire the moron.

    4. Re:Job Security by natehoy · · Score: 1

      I spent an hour indenting a fairly large program so I could read it once. Too bad it was my first introduction to RPG II on a S/36.

      The compiler was NOT happy.

      --
      "This post contains words, known to the State of California to cause thought. Wash brain thoroughly after reading."
    5. Re:Job Security by plague3106 · · Score: 1

      Why are you dealing with this nonsense? Your dev. environment can't reformat the code for you automatically?

    6. Re:Job Security by murdocj · · Score: 1

      Well, I'll take no indenting over random indenting. I once had to work through some Perl code that was so ugly that I felt dirty just being in the same directory with the code. Lots of copies of the same code, commenting used as source control, random indenting... at some point I felt like no one could have written such stuff by accident, it had to be malign intent. I think I decided that when I realized that the code was deliberately taking the log output and rewriting the log out of order, which explained why the impossible sequence of events I was seeing in the log.

    7. Re:Job Security by dmgxmichael · · Score: 1

      Auto reformatting won't catch some of the other stupidities of this guy like outright empty blocks of code, code blocks that do nothing, or one of my favorites, passing a value between 4 to 6 variables before finally throwing it away and doing nothing with the value.

      And then there's his habit of converting variables to strings with the sprint_f function AND THEN trying to add them numerically.

      Oh, and while I'm in there I'm slowing pulling the bloody mess of interspersed PHP and HTML into something resembling a View / Control separation - at least enough of a separation to make editing the in the future code less of a pain.

  28. comments and complexity by bigogre · · Score: 1

    Two comments:

    1. Comments are there to tell WHY the code is doing what it is doing, not necessarily what the code is doing. I deal with code all the time that has comments that tell me what I can easily learn by reading the code, but they don't tell me why so when it is broken I don't know if it is because there is a subtle problem with the code or that the developer didn't know what they were doing.

    2. After literally getting headaches from reading code written by other people I came up with a simple metric: The complexity of the coding solution to a problem is inversely proportional to how well the developer understood the problem they were trying to solve. In other words, someone who understands the problem will have a simpler solution than someone who doesn't understand the problem as well. You can apply this metric to things other than code, too, but it is usually very apparent with software.

  29. Ascii Art? by Spazed · · Score: 0

    That's it! I'm making all of my comments ascii art from now on!

    1. Re:Ascii Art? by clone53421 · · Score: 1

      /*
      \\ /\ //[= || "' ||
        \/ \/ ||_ |L_ L_

      ||D) || ' ' A \\// [= ' '||
      ||....|L_// \\ || ' ||_ ((|| */

      Filter error: Don't use so many caps. It's like YELLING.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
  30. Too wordy by Anonymous Coward · · Score: 0

    That was a long-winded blog post, which indicates he probably doesn't know what he's talking about.

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

    1. Re:Yes, that's bad coding by cppmonkey · · Score: 1

      Is it bad coding? Yes. Is this the worse coding? No. We've all been pressured to ship and all too often it sucks. But you commented the code indicating that you don't know why it works which helps your or the next person to come along to fix the problem. Points for actually commenting and saying you don't understand, shipping code you don't understand; not good. But the big question is did you go back and review the comments and try to fix the problem (ie understand your code)

    2. Re:Yes, that's bad coding by Cederic · · Score: 1

      I've written unit tests that test all known valid inputs before.

      I'm now trying to remember why that was the appropriate level to which to test, and why we just didn't turn the test cases into a simple map...

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

    Comment removed based on user account deletion

  33. 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 richg74 · · Score: 1

      I've working in software development since the early 1970s, and have also taught classes in math and science. In both areas, sloppiness is a very good indicator that the person doesn't know what he's doing. Good math students turn in assignments and exams that are easy to read. The best programmer I've ever met wrote brief, but lucid, comments; if he wrote a parsing routine in C, let's say, you could hold the code at arm's length and recognize it was a parser.

      Long comments are fine if they are long for a reason. For example, someone above commented that he puts spec references in for things like formulas / equations. This is an excellent idea, which I advocate, too. It's the long-winded, rambling ones that are a danger flag.

      As far as folks for whom English is not a first language, one of course must make allowances. But this is usually not hard to do, since the kind of mistakes that come from laziness and sloppiness are mostly easy to distinguish from honest difficulty with the language.

    2. 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.
    3. Re:I agree, with reservations by Anonymous Coward · · Score: 0

      It seems most of these people live in a different universe than the
      one I worked in before I retired. Estimates were continually undercut,
      workload added, features tacked on; fundamental changes to requirements
      appeared with great regularity. All of these things with no allowance for
      the added time required. Is it any wonder that comments get pushed aside or
      even ignored. Yes, well written code is wonderful. Yes, good comments helps
      to make any code easier to understand (read BETTER). However do not
      be surprised when circumstances make it difficult to create such wonders.

    4. Re:I agree, with reservations by Bengie · · Score: 1

      If you're that worried about your job, keep an eye out for another decent job and jump on that. 15 years of experience working for an unappreciative company is not what you should be doing. I've heard nothing but horror stories about outsourcing programmers. You get EXACTLY what you pay for.

      Typically outsourced programs could be done by fewer and more educated people, be easier to manage, fewer bugs, and run faster.

    5. Re:I agree, with reservations by Anonymous Coward · · Score: 0

      Don't blame it om them! "they're" will get you compilation errors if you use it as a variable :)

    6. Re:I agree, with reservations by syousef · · Score: 1

      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.

      Oh what horse shit. There are plenty of good coders that know to focus their efforts on conveying the meaning in their comments without worrying about. People get anal about the wrong things. For example I've seen SVN and Checkstyle filters that prevent checkin of code if any comment has a first line that does not end in a full stop. That is fucking ridiculous and a misdirection of effort and abuse of the tools as far as I'm concerned.

      I only have 15 or so years in software, but I feel it's enough to make this comment.

      --
      These posts express my own personal views, not those of my employer
    7. Re:I agree, with reservations by JustNiz · · Score: 1

      You're making the same mistakes as many other software engineers by allowing yourself to be walked all over by sales.
      Did you ever stop to think that you're actually being less productive by working 80 hour weeks and throwing out low-quality stuff?
      All that rework...
      If its really you talking to the salesman and not your boss, then you've already sold your own ass down the river by continually giving the sales guys what they want all the time at the cost of your own life. You need to train the sales guys to not turn up at your desk and expect/demand the impossible, but to involve you early at the negotiation time with the customer so your input into realistic deadlines gets considered BEFORE they make commitments you cant keep to the customer.

    8. Re:I agree, with reservations by JustNiz · · Score: 1

      Yeah its funny but the more someone doesn't agree with my point usually the worse their own code is. I guess yours must be pretty bad, not that you would ever see it yourself.

    9. Re:I agree, with reservations by JustNiz · · Score: 1

      Interesting to see that the same thing also occurs in other disciplines. It adds credibility to this being a real phenomenon rather than just software engineering oneupmanship.

    10. Re:I agree, with reservations by bidule · · Score: 1

      I totally agree with you.

      The big joke is that when you see crappy written English, you know it's a native.

      "Ce qui se conçoit bien s'énonce clairement et les mots pour le dire arrivent aisément" - Boileau

      I will add that if you cannot grok your own native language, which you've used to 20+ years, how can you affirm that you understand a programming language. If you cannot make an instantaneous difference between a subject/verb pair, a pronoun and an adverb, why should I trust you'll know the difference between lvalue and rvalue?

      --
      ID: the nose did not occur naturally, how would we wear glasses otherwise? (apologies to Voltaire)
    11. Re:I agree, with reservations by Volguus+Zildrohar · · Score: 1

      the last thing I'm worried about is making sure I don't confuse "they're" with "their" or with "there"

      What's with "making sure"? It's not exactly hard.

      They're playing with their balls over there.

      Holy shit, how did I do that so quickly?

      Bah.

      --
      When confronted with one problem, some think "I'll use recursion". Now they are confronted with one problem.
    12. Re:I agree, with reservations by prichardson · · Score: 1

      People who learn english as a second language are less likely to make that mistake because the mistake comes from them sounding the same. Usually second languages are learned as much from reading as from speaking, so the difference is clearer.

      --
      Help I'm a rock.
    13. Re:I agree, with reservations by rackeer · · Score: 1

      That's probably true for all areas, not just programming (although you should make allowances for dyslexic and so on). This is also mentioned in TFA. The original article is BTW 30 years of C. It's actually only a paragraph there:
      2. Good programs do not contain spelling errors or have grammatical mistakes. I think this is probably a result of fractal attention to detail; in great programs things are correct at all levels, down to the periods at the ends of sentences in comments.
      “Aw, c’mon! You’re kidding!” You might think that nit-picking like this is beneath you, whereupon I will start pointing out errors in your code. It was embarrassing the first couple times this happened to me.

      I think this categorical statement ("does not contain") is a bit harsh, but there's certainly a relationship between clear thinking in language and style and the quality of content (the code).

    14. Re:I agree, with reservations by Cederic · · Score: 1

      The point of the article, and of the person you replied to (or should that be 'to whom you replied') is that people that write high quality code will instinctively care about, know or just get right the difference between their, there and they're.

      I've had enough experience (without joining the pissing match) hitting tough deadlines to know that no comment is better than a wrong comment, and my brain gets upset with poor grammar/spelling in comments.

      You're right that productivity is impacted by grammar. Alas the evidence appears to be that companies benefit from higher productivity if their staff care about it.

  34. 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
    1. Re:Existence of Comments by Jahf · · Score: 1

      Pfft. Self-documenting code is fine if you know for certain everyone who is going to work with the code has at least as much experience in everything that you use to code. Otherwise if you refuse to comment you're just causing a barrier to entry for someone who may be able to get up to speed very quickly and help you out. The type of project it is should dictate your commenting as much as anything. Especially if it is a project others use and that you may abandon in the future.

      If you don't -want- to share the code and/or have less experienced help start in working on it that's a valid decision. But not putting comments in to prove to everyone that you know your stuff (which I've seen happen plenty of times) is not. It typically takes a very little amount of time to create a decent comment. And if you're good enough to re-read your own code at any time you can go put them in after you are done.

      That said, I tend to just mod stuff as I need and/or script for myself. That means I don't know any one language masterfully and so yes, not only do I rely on comments on code that isn't painfully obvious but I also document my own code in the extreme (including citing sources if I borrowed from other code) so that I can go back and pick it up quickly if I need to edit it years in the future. For instance I usually write my comment -before- the code and use it as a guide so I can remember my place while I'm figuring out how to do something (and then update the comment as I change what the code ends up doing) and yep, I put in apologetic or excusatory comments mostly to remind myself to go find a better way to do it. So I agree with the basic premise of the article that comments can indicate a lack of knowledge on the commenter. But I also feel that purposefully not commenting is a bad call as well. There is a good middle ground.

      --
      It is more productive to voice thoughtful opinions (reply) than to judge (moderate) others.
    2. Re:Existence of Comments by linuxgurugamer · · Score: 1

      Sorry, you're wrong.

      30 years of programming, for a variety of companies, tells me that.

      When I have to look at someone else's code, it helps if, for example, each function has a set of comments which briefly describes what the function is, the parameters it is expecting, and what it is returning. Even if you wrote "self-documenting" code, it never documents itself enough.

      Speaking of Perl, it is one of the worst languages for documentation. When I see it, I will either spend time figuring out what it is trying to do and document it, or not use it. I will not use code which I don't understand, because then I can't debug it. Comments help in that.

      Also, sometimes comments will document a history of changes, and may explain why the code is doing something a certain way.

    3. Re:Existence of Comments by Anonymous Coward · · Score: 0

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

      (Any good Perl programmer knows this.)

      Ever code in APL?

    4. Re:Existence of Comments by Anonymous Coward · · Score: 0

      Not sure if you were being sarcastic, but in case you weren't, here's a protip: your code isn't as self-documenting as you think it is, and, even if it was, reading a paragraph of English is still an order of magnitude faster. For the sakes of all of us who actually have to read other peoples' code, I wish the self-documenting myth would just die.

    5. Re:Existence of Comments by tgrigsby · · Score: 1

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

      The tragic part about your comment is that there are so many people out there that don't know it's just a joke. It's the same crowd that thinks that Saddam hid his WMDs in Syria and that the House healthcare bill would legalize "death panels" and will never be convinced otherwise.

      --
      *** *** You're just jealous 'cause the voices talk to me... ***
    6. Re:Existence of Comments by Anonymous Coward · · Score: 0

      If comments even exist, then the code is ugly. Code should document itself. (Any good Perl programmer knows this.)

      This from a language with functions like chomp() *eyeroll*

    7. Re:Existence of Comments by Anonymous Coward · · Score: 0

      Right! Who needs comments on complex regular expressions?

    8. Re:Existence of Comments by Anonymous Coward · · Score: 0

      Bah. Perl looks like Bruce Schneier shat on your keyboard and it happened to compile.

    9. Re:Existence of Comments by Sandbags · · Score: 1

      Yea, and then what do I do with LISP?!?!?!? lol.

      Self commenting code is what CoBOL was designed to do. Have you ever coded in CoBOL? it sucks... Too restrictive, and too long winded. I want my code clean, compressed, and simple. the comments can spell it out in a readable language...

      Also, apparently you have also never written in Assembler, RPG, or any of the other obscure languages of old.

      Further, just because i know the code calls libraries and variables and strings/lists, does NOT mean i want to go digging through other sections of code to know what that is or why. If I'm calling something, i state what it is there next to it for reference unless its so glaringly obvious it doesn't need it.

      I'm not saying every line needs a comment (it doesn't hurt), but there should be zero ambiguity in what a code segment does, what the inputs, outputs, validation, debug lines, etc are.

      --
      There is no contest in life for which the unprepared have the advantage.
    10. Re:Existence of Comments by Lord+Ender · · Score: 1

      (Any good Perl programmer knows this.)

      Therefore, there exists no person X such that X knows this. QED.

      --
      A slashdotter who didn't build his own computer is like a Jedi who didn't build his own lightsaber.
    11. Re:Existence of Comments by Adm.Wiggin · · Score: 1

      Why is this modded Funny? Perl can be quite readable. Too many bad programmers have given it a bad rep.
      My favorite example of code readability is: go_outside() and play() unless its_raining();

    12. Re:Existence of Comments by Blakey+Rat · · Score: 1

      My favorite super-verbose language was HyperTalk:

      "set the x of button1 to 500; set the y of button1 to 240; set the caption of button1 to "continue"; set the action of button1 to ( go forward 2 cards visual effect vertical wipe)"

      From memory, forgive syntax errors. AppleScript wasn't much better, IIRC.

      You can see some code samples on the Wiki page: http://en.wikipedia.org/wiki/HyperTalk

    13. Re:Existence of Comments by Anonymous Coward · · Score: 0

      In Soviet Russia, the code comments on YOU!

    14. Re:Existence of Comments by tieTYT · · Score: 1

      Why was this marked funny? I actually agree with this. Obviously, you need comments once in a while, but, they should be rare and the code should document itself most of the time. The people talking about how helpful comments are probably haven't read Refactoring or Clean Code.

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

    1. Re:How much code is written by outsourcing? by Antiocheian · · Score: 1

      I would say that most coders who don't know good English aren't good coders either. By limiting themselves to literature available in their native language they limit their knowledge and they miss quite a lot. When teens ask me how to start learning programming, my advice is to learn English first and C later.

  36. What if... by Mr.Fork · · Score: 1

    there are no comments? I was once a programmer for EDS - I was responsible for the UNIX API that back-ended our helpdesk system. It was mostly written in C. The single biggest issue I had were the contractors who we brought in who either didn't comment on their function libraries they wrote, or their comments didn't follow proper function header commenting that you get if you went to school.

    The bottom line, if you don't have established code-commenting procedures and processes on how you code and a quality assurance process to ensure that code is written properly and documented, you get back what kind of 'box' you put around your programmers. Those procedures are not suppose to limit how you put smarts into programming, but establish common programming language 'parameters' all programmers use on your team. Beware of the contractor however, they tend to follow their own rules, and try to ensure their own self-worth by documenting poorly.

    --
    Management is doing things right; leadership is doing the right things. - Peter F. Drucker
  37. Bullshit! by bongey · · Score: 1

    Talk is cheap. Show me the code.Linus Torvalds

    I am going with Linus on this one, not some tech author nazi.
    I have found too often the comments says the code does X, and it does Y. What is even better is when the code is wrong. Just love it when that happens. I have had to go as far to prove to someone in the comments that there code was wrong to accept that there code was wrong, and he are grammar nazi too, so I say bullshit on this.
    Programming is a art in itself, good coders can "read" the code. Comments are nice, but they are not end all, nor a guarantee the code is correct or good.Often it can be the opposite.

    1. Re:Bullshit! by CarbonShell · · Score: 1

      I agree fully.
      This is just another arrogant jerk trying to label off people in a lame attempt to make themselves look good.
      Is this the only thing you can measure yourself against others with?

      OMG, his spelling sucks, he must be such a baaad programmer.

      Seriously, I've seen these kind basically have a discussion about the most ridiculous and redundant things.
      One I remember was 'should one write BR in an email and if so, would it show a sign of disrespect'. WTF?

      Yea, my spelling sucks but I surely do not get paid all this money to write a friggn blog.

    2. Re:Bullshit! by natehoy · · Score: 1

      The important thing that a comment gives you is not the how. You can get the how by reading the code.

      What an appropriate comment will give you is the WHY.

      Unimportant for a lot of web development, I suppose, when you are pretty much dealing with the data on a form and bouncing bits of it against a database. But for transactional processing, the why can be easily non-obvious in the code, and important to know.

      --
      "This post contains words, known to the State of California to cause thought. Wash brain thoroughly after reading."
  38. All I can say is "few anecdotes don't make data" by Anonymous Coward · · Score: 0

    All I can say is "few anecdotes don't make data"

  39. Forget the comments, look at the documentation by metamatic · · Score: 1

    If the documentation is incomprehensible or missing, then the software generally wasn't well thought out or planned ahead of time, but rather just grew as an accretion of hacks.

    This is particularly true of API documentation. I've even encountered crackpots in the Rails community who think that you don't need API documentation if you have unit tests; their code was abysmally unreliable, unstable, and performed poorly.

    --
    GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
    1. Re:Forget the comments, look at the documentation by Anonymous Coward · · Score: 0

      And Rails people are SQL-haters. SQL is usually more powerful than their loopy slow imperative object crap. (I know, off-topic. That's life, topics drift so why punish me for that? Do you mod people in bars for doing that?)

  40. Practical application of comments by dkh2 · · Score: 1

    The group I work with views code commentary as a requirement of the job of the go-coder.

    Initial development of a new method (procedure, function, whatever a discreet unit of functional code is called in your language of choice) begins with inclusion of a summary comment of the specification. This puts the spec where the developer is working and can use it. This comment block gets tweaked and resequenced to fit the logical and technical demands of delivering the specified result and to segregate each logical step into distinct comments.

    Once functional code has been implemented and unit tested the comments are reduced or eliminated along side a focused and targeted walk through variable and method names to produce final code that is as self documenting as possible.

    Comments remaining in the code are there as bookmarks/breadcrumbs, or provide insight into why a particular logical approach was taken. As for the variant spellings issue - we are a small shop in the U.S. so we tell our international employees that we use EN-US spellings. ("There is no 'U' in 'honor.' and it's 'aluminum' (4 syllables) not 'aluminium' (5 syllables).")

    --
    My office has been taken over by iPod people.
  41. What about foreign coders? What about dyslexics? by Viol8 · · Score: 1

    There are many coders who work in a country where the language is not their first language. Does this mean the code they write is rubbish if they make some spelling mistakes in the comments? And I've met at least 2 genius level coders who had serious dyslexia and you could hardly make head nor tail of their comments, but the code they wrote was superb.

    This whole premise is just a joke. Next they'll be saying people who can't program very well wouldn't be good at writing any form of document.

  42. Why doesn't Literate Programming catch on? by WillAdams · · Score: 1

    There's a terrible irony in Donald Knuth feeling that it's an even more important development than TeX, yet outside of the TeX world, almost no one uses it:

    http://www.literateprogramming.com/

    William

    --
    Sphinx of black quartz, judge my vow.
  43. If you like that sort of stuff... by Viol8 · · Score: 1

    ... learn COBOL. Nice and long winded and "englishy". And an utter PITA.

    1. Re:If you like that sort of stuff... by dzfoo · · Score: 1

      Hmmmm! I like PITA, specially with hummus.

            -dZ.

      --
      Carol vs. Ghost
      ...Can you save Christmas?
  44. 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

    1. Re:Forced to use Bad API by Divide+By+Zero · · Score: 1

      No mod points, so a "me too". Fully half my comments are of the "API unexpected outputs" variety or the "language braindead a/o insane, here's the workaround" variety.
      //Can't handle this elegantly due to race condition with otherFunction().
      //This visual element shouldn't need padding, but doesn't look right unless you specify the following margins
      //The only way to tack a listener onto this element is to do it this hacked-up way:
      //IDE code highlighting gets confused with regexps - this works as it seems it ought, despite funny colors.

      --
      Dare to Hope. Prepare to be Disappointed.
  45. 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 rgviza · · Score: 1, Insightful

      UNIX is simple, but you have to be a genius to understand the simplicity.

      --
      Don't kid yourself. It's the size of the regexp AND how you use it that counts.
    3. Re:You are not expected to understand this by Anonymous Coward · · Score: 1, Interesting

      The hero worship is getting rather tiresome. As someone who has dabbled in OS development, I understand what that is doing, though not for lack of obfuscation.

      The biggest problem with that code is the lame function name, it's an abbreviation of something though I'm not sure what exactly [Might be absolute return]; here is how I would have written that:

      /* If the new process paused due to being swapped to disk
        * then wipe the stack call frames for all our parent callers
        * and return immediately all the way to the last function
        * to execute a stack state save.
        */
      if (rp->flags & PROCESS_STATE_SWAPPED) {
              rp->flags &= ~PROCESS_STATE_SWAPPED;
              restore_stack_pointer(u.saved_stack_pointer);
      }

      It's hard to be sure this is completely equivalent given the lame variable names but I am pretty sure this is what is happening; it's essentially a primitive setjmp/longjmp process. As to why, the comment is even more unhelpful in that regard; it looks like it's being used to throw an exception [before exception throwing existed] by returning all the way to the last function that registered a handler to deal with the swap out.

    4. 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
    5. Re:You are not expected to understand this by Anonymous Coward · · Score: 0

      The real WTF is that he doesn't expect the people reading the code to understand it. ken is teh sucks.

    6. 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
    7. Re:You are not expected to understand this by Anonymous Coward · · Score: 0

      In this case, the code is commented, and says exactly what it does and why, and the comment is totally useless.
      Wouldn't it have been a lot more useful to use more time to make descriptive variable/method names that tell what what they do, and just skip the commenting?

    8. Re:You are not expected to understand this by clone53421 · · Score: 1

      /* If the new process paused due to being swapped to disk
        * then wipe the stack call frames for all our parent callers
        * and return immediately all the way to the last function
        * to execute a stack state save.
        *
        * You are *still* not expected to understand this.

        */

      As someone who has not dabbled in OS development, I've taken the liberty to FTFY.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    9. 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.

  46. 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.
    1. Re:Or a management failure by Opportunist · · Score: 1

      AKA "paying coders by volume created".

      I was in a similar situation once. Early in my career I got into a team where one of the coders was praised by management as a lightning fast developer who could work miracles if he wasn't "slowed down" too much, a real role model I should cling to learn a thing or two.

      I took a look at his code and it was bad. Really bad. He was invariably picking out the "easy" parts of a project, do them in the worst possibly way yet document them like he is trying to explain the world formula in a few for loops. Yet he was praised and rewarded for his "great work".

      After a while I realized what's the deal. Management had no idea what code is about, they only noticed that they can't tell how far a project really is or how much anyone really works on it, except one thing: They can measure the amount of text written by every code members. So what they did is to judge us by the amount of junk we checked in.

      --
      We used to have a Bill of Rights. Now, with the rights gone, all we have left is the bill.
    2. Re:Or a management failure by Anonymous Coward · · Score: 0

      Wading into a multithreaded C++ nightmare at a new place of employment, I stumbled across the following line:

      using namespace std; // using namespace standard

    3. Re:Or a management failure by RAMMS+EIN · · Score: 1

      The Real WTF is the managers holding up this guy as an example to aspire to, without knowing _how_ what he did benefited the project. If they had done even something as basic as setting goals for the project (e.g. features that need to be implemented, issue tracker tickets resolved, ...) and measured by that, they would have gotten a better metric. Or they could have asked another coder. But no, they went and invented a metric, evaluated team members by it, and went to sing the praises of the member who came out on top ... without ever stopping to wonder if their metric was any good. Brillant.

      --
      Please correct me if I got my facts wrong.
    4. Re:Or a management failure by Opportunist · · Score: 1

      It was a big company that isn't necessarily known for great qualification in middle management. They were number deliverery boys. "I fill paper with numbers, thus I exist" was the creed. We had a few metrics that made no sense. Or maybe made some sense some time ago but didn't anymore. A lot of what we did was legacy bullshit that was kept even though it was no longer necessary, simply because nobody who could change it knew it was obsolete (and frankly, didn't care more often than not, especially if the cost associated with it occured in another profit center) and those who knew couldn't change it.

      It was a self perpetuating spiral downwards. You were measured to metrics that make no sense, so you had the choice, either to fight the system and be sacked or to adjust to the system and comply with a nonsensical system. Soon you spend more time figuring out how you're measured and how to play the stats instead of doing any work. For the single person, this is the logical move. You stop playing the game, you start playing the rules. Instead of completing sensible work, you try to fulfill what's necessary to look good.

      Such a system works because everyone is looking for short term goals, personal goals, it's a game of minmaxing, minimizing your effort to maximize the effect. The desired effect is not to deliver a good product, the desired effect is to look good to your superiors. So the programmers fulfill harebrained metrics instead of doing sensible work. The middle managers who created those metrics won't change those metrics without any good reason because they can deliver numbers that satisfy their superiors. Their superiors know even less that those numbers mean nothing, but they're some sort of metric and we have bigger numbers than last quarter, so we're on the right track. And when the product fails, we'll sack a few of those lousy slacking coders. Which isn't too bad an idea since you already sacked all the coders that actually did meaningful work, thus didn't product a lot of numbers along the faulty metric and were sacked for a lack of performance.

      It's up to the reader to decide who should be sacked or at least rethink his strategy.

      --
      We used to have a Bill of Rights. Now, with the rights gone, all we have left is the bill.
    5. Re:Or a management failure by stephanruby · · Score: 1

      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.

      Your writing sucks. Your statement implies that the "really helpful girl" was a figment of your imagination. Instead, you should have written: "Pretty quickly I found out that whenever I checked something into CVS, it got re-checked by..." It's not that you used the wrong grammar in this case, it's just that you dumped your stream of consciousness into a comment and you probably didn't even bother to proofread it afterward -- to see if it still made sense once it was on paper. Please next time, proofread your comments a little more.

    6. Re:Or a management failure by The_mad_linguist · · Score: 1

      Nah, turns out "she" was just a regex.

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

  48. 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.
    1. Re:OT on long comments by GeckoAddict · · Score: 1

      accuracy of the comments (do they actually describe what the code does)

      I'm of the belief that if you properly named your functions/variables, you shouldn't have to explain WHAT the code does, just WHY. The What can be provided at a very high level, and certainly the HOW should never be part of the comment. Proper naming/hierarchies/abstractions and the need for long-winded, complicated comments are gone, because the code makes it apparent what is being done (even if you're not sure why without the comments).

    2. Re:OT on long comments by Anonymous Coward · · Score: 0

      Gah, your comment was too long to read.

    3. Re:OT on long comments by FrankSchwab · · Score: 1

      I'm of the belief that if you properly named your functions/variables, you shouldn't have to explain WHAT the code does, just WHY.

      And I'm of the belief that the FSM touched me at a young age with his noodly appendage, and changed my life forever. Of course, beliefs are a dime a dozen, and very seldom backed up even by something as tenuous as an anecdote.

      In the real world, your belief is an excellent goal, one that every quality professional programmer strives towards. However, in the real world, it is an unobtainable goal for 100% of functions. You very quickly find that a name that is perfectly descriptive to you is not as descriptive to the next programmer, or even to you revisiting the program 6 months later. An 8 to 16 character English (OK, "Native language" ) string is seldom going to capture all the details and nuances of a 50 line function - if it does, you've just invented a remarkably more efficient programming language, and you should be suitably rewarded by the market for your insight.

      Comments, especially header comments, help to capture the edge cases, the side effects, the algorithms that a readable function name can't possibly impart.

      /frank

      --
      And the worms ate into his brain.
    4. Re:OT on long comments by clone53421 · · Score: 1

      Readability may occasionally take second place to efficiency. As I've said elsewhere in this discussion, if your efficient, streamlined code is so efficient that it's hard to tell what it's doing, a comment explaining just WHAT it does – and yes, even HOW – is wholly appropriate. In extreme cases it might even be worthwhile to include a commented-out block of code that does exactly the same thing, less efficiently but in a more self-documenting fashion.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    5. Re:OT on long comments by Anonymous Coward · · Score: 0

      > As someone with good English skills
      ...
      > and the particular necessray function that implements the solution

      FAIL!

    6. Re:OT on long comments by Cederic · · Score: 1

      all the details and nuances of a 50 line function

      Ah, I see your problem.

  49. Native English Speaker by binaryartist · · Score: 1

    What if the person who wrote grammatically incorrect comments is not a native English speaker? Engligh not fluent, C++ very fluent!

    --
    When a thief sees a saint, all he sees are his pockets!
    1. Re:Native English Speaker by clone53421 · · Score: 1

      He wasn't a native C++ speaker either.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
  50. 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.

  51. Bad Spelling in your comments by smisle · · Score: 1

    I agree that a programmer must be anal about details, as one missing character can break your entire program. But, how you write your code matters, how you spell, does not.

    If you think of your programing language as just that, another language, it doesn't matter how poorly you understand your native tongue, as long as you can 'spell' with the language you are programing with.

    Looking at the tone of the comments is 100% different than looking at their grammar and spelling. It's possible to have disturbing comments in prose... But all that just gives you an idea that there might be something wrong.

    --
    I'm not a bird, I'm a super-advanced flying stealth dinosaur!
    1. Re:Bad Spelling in your comments by funwithBSD · · Score: 1

      You can't have it both ways.

      If you can't spell the common words in a comment, how will you be able to do it in code? This is especially true in JAVA and other "verbose" languages.

      (following code is totally made up to illustrate a point, not to be compiled or used)

      #This fixes an acess issue in BUG 12345.

      org.apache.bcel.classfile.AcessFlags = NULL;

      --
      Never answer an anonymous letter. - Yogi Berra
    2. Re:Bad Spelling in your comments by smisle · · Score: 1

      In modern English, there are about one million words. In JAVA, there are at most around a thousand. It's possible to have learned to spell all the words used in JAVA and yet still not be able to spell *very well* in English.

      I will admit that there are some people who can't spell for crap, and they have the same problem with their code - I wasn't inferring that the bad spelling coder who screws up his code doesn't exist! Just that it isn't always the same thing *points to myself*

      --
      I'm not a bird, I'm a super-advanced flying stealth dinosaur!
  52. Thats a big relief by Bai+jie · · Score: 1

    I don't comment on my code, so I guess that if the comments are non-existent then the errors are non-existent too!

  53. All code is crap by lawman508 · · Score: 1

    Comments don't matter. I've been coding for 25 years as a consultant for hundreds of companies. All code is crap. The best you can hope for is to get home by 5:00 on Friday and do something that should really matter to you. Can I create effecient, nicely structured code? Sure - and then some minimum wage programmer from 'Elbnonia' comes along the next day and mucks it up - with no accountability. Do yourself a favor and accept these facts now - and you'll save yourself a lifetime of pain and disapointment. If you want to create something of quality, which will last - become a musician or an artist or a poet - or better yet - go and volunteer at a homeless shelter or food bank.

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

  55. Re:Tästä voit hakea sanan kategorian (av by gestalt_n_pepper · · Score: 1

    Are you *sure* that's not Estonian?

    --
    Please do not read this sig. Thank you.
  56. 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

    1. Re:Comments are for future maintainers by TheGreatOrangePeel · · Score: 1

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

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

      i += 4; /* Ignore the first 4 billing fields preceding payment info. */ Better - describes what is ignored.

      i += 4; /* Ignore the first 4 billPayChk() billing fields preceding payment info. */ Best

      Having been the last step in a 4 tier support team for years, I've seen my fair share of bad comments in code (oh, the number of times I've wanted to utter, "no $%!7, Sherlock" while debugging). The most helpful comments skipped entirely the WHAT the code was doing and went straight to the why and pointed me to more info. Info is sometimes an old support log, a technical document or another place in the code. Generally speaking, comments like this can save hours of debugging/troubleshooting an issue found by users in the field.

    2. Re:Comments are for future maintainers by tieTYT · · Score: 1

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

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

      ignoreFirst4Fields(); /* even better than that? */

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

  58. Good code should coment itself. by Anonymous Coward · · Score: 0

    Good code should comment itself and when that is not possible clear and concise code comments should be entered. If the comments are difficult to read then it follows that the code is probably worse.

    Its not hard for me to believe that someone who didn't take the time to explain themselves clearly probably didn't take the time to think the code through clearly either.

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

  60. Comments... by CFBMoo1 · · Score: 1

    I write my comments in my code for the person coming in and having no clue about anything but has to fix something. It can happen and I've had to deal with situations like that for code that had no comments or documentation. Comments are there not only to remind me months or years down the road what I did back then but also to help the poor soul who gets thrown in to the project because maybe something happened to me and I want as much info as possible not only in the documentation but also the code. For all I know something may have happened to the documentation as well.

    --
    ~~ Behold the flying cow with a rail gun! ~~
  61. 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.

    2. Re:if you are coding in microsoft land by plague3106 · · Score: 1

      Of course the whole point of using a black box is that you're not supposed to know how it works in order to use it. And if you're spending time debugging someone ELSES code, you're probably not doing your job (at least until you can show it is in fact the other code).

      Of course I've been .Net for a while, and haven't really had such problems, except the documentation not being detailed enough.

    3. Re:if you are coding in microsoft land by nschubach · · Score: 1

      That's a problem unless he used system calls to obtain values. There is very little code that's entirely self contained... especially today. Even dealing with strings you are assuming that the compiler does things proper. It could possibly have been fixed by the compiler. We wouldn't know unless we had the code. All we have is a story. (One side at that...)

      I understand your position though and I'm not defending him. Don't get me wrong. I'm just interjecting.

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
  62. 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
  63. 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".

    2. Re:Blame Game by MozeeToby · · Score: 1

      At well run companies, they understand up to the highest levels that long run, maintainable and understandble code is faster and cheaper. They may be few and far between, but to just accept manager and executive incompetence is how companies go down the toilet. And yes, not understanding the costs and benifits associated with your business domain is incompetence regardless of how common it is.

    3. Re:Blame Game by mpapet · · Score: 1

      understanding your own code is in the category of "basic competency".

      I agree 100%. I don't use 'magic code' because it's a bear to do anything with much later.

      But, there's a stronger current to the grandparent's bridge building comment that you are not factoring into my reply.

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

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

      You were the guy who brought up "formalized discipline" as the goal, so the guy made a fair comment in response. You can't just use extreme examples when it suits you and then fault the other guy for carrying on your own analogy.

    5. Re:Blame Game by mpapet · · Score: 1

      At well run companies, they understand up to the highest levels that long run, maintainable and understandble code is faster and cheaper.

      Agreed. I work for one of those now. The parent's comments about bridge building suggest there's more going on for him though.

      --
      http://www.maxineudall.com/2010/02/should-economists-be-sued-for-malpractice.html
    6. Re:Blame Game by Anonymous Coward · · Score: 0

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

      I disagree. 10 minutes with a pencil and paper, formalizing your specification and making design and architectural decisions, and another five to jot down some notes regarding your formalized spec and design beats 10 hours of test writing. If you want maintainable code, that is.

      If you are not capable of formalizing a specification, you are not ready to write the code.

      At my last job, I would get in at 10AM, get assigned multiple "hard" tasks per day, and finish them by 2PM. My coworkers would do 1 or 2 "hard" tasks in a week. I'd do that many in a few hours. Why? Because I would take a sheet of paper, break the problem down, solve it on paper (that is, mathematically), and write a checklist of steps necessary to implement a solution in my language of choice. Once you have done that much, coding is brain dead simple. My manager didn't like me coming and going as I pleased, but he always called my code "bulletproof". I was getting paid $55,000 for a "full time" 20 hour a week job.

      Functional programming makes this even easier, since you can use argument by induction in lieu of tests. Moreover, if you use mathematical concepts to create your formalization (functions, sets, products, predicates) a functional language makes translating your formalized specification extremely straightforward.

    7. Re:Blame Game by nschubach · · Score: 1

      I know I'm going to regret saying this for some reason, but could this be an affect of "faith"?

      I mean... We don't know how the world works. We kind of have a basic idea but there are holes to our understanding. If he somehow created code so complex that works, but he doesn't understand how it works there are two sides of the discussion that quickly falls into the right vs. wrong or good vs. bad debate. One may also argue the idea that invention and discovery is partly random or by chance. He could have come up with an algorithm that someone has been slaving over for years strictly by accident. You can debate this for hours, but the act is committed.

      Arguably, he should analyze said code as a self initiative to answer all the questions. Not doing so lends me to believe he chose the career for the wrong reason, but it also gets the job done. This to me is just like people who go through life accepting a "creator" is taking care of things. Ignorance of detail doesn't mean it's wrong, it just means they think on a different scale.

      I'm a bare bones detail person. I want to know how every little bolt works and it frustrates me to know end when I'm coding in an environment like .NET when something is handled by the underlying code and I don't see how. Yes, I can dig into the shared source and reflect the code to see it, but that's the extra step most programmers today don't do. Now, there is a limit to my madness. I accept that a String will be handled properly without verifying every little bit... but there's a fine line of complication and ease of development that I think we are teetering on.

      --
      Every time I start to have faith in humanity, I ruin it by driving to work between 7 and 8 am.
  64. Anonymous Coward by Anonymous Coward · · Score: 0

    Any kind of comments...even poor ones are better than nothing. There is nothing more frustrating than having to pick through 2000 lines of code in a single method (inherited from someone) and try to decipher their "logic". Even having poorly written comments can help lead you through their though process, and assist in identifying the problem.

    However, not everyone who produces software is a grammatcial genius. This is especially true of international developers having to put their comments in English for the American coroprations they work for. I've known brilliant developers from all over the world whose code was solid, but whose comments left a lot to be desired...understandably. I've never faulted anyone for attempting to make sense out of sometimes non-sensical processes.

    This also doesn't take into account the frequent illogic steps "the business" want to put into software that developers have to compensate for. How do you comment an exception to a rule that, itself, is an exception to another rule that is an addendum to a clarification?

    Shennanigans I tells ya!

  65. Favorite Comments by digitalPhant0m · · Score: 1

    My two favorites are: /* I'm better that you are */ /* If you can read this, you're too close */

  66. How could the grammar be wrong? by Anonymous Coward · · Score: 0

    I don't get it, if the grammar is wrong, how does the program compile?

  67. Here's an idea by xtrafe · · Score: 1

    Let's invent a machine that is based on mathematical logic, that can only interpret simple instructions, but executes those instructions precisely and with no ambiguity. Then, since human language is fuzzy and full of ambiguity (like human minds), lets invent languages that are extremely specific, so that it will be easy for us to tell our new machines what to do. Finally lets go through the laborious task of translating our fuzzy ambiguous thoughts into these rigid, well qualified languages...

    ...now we've accomplished all that, lets take all our hard work and undo it. Lets back-work a bunch of fuzzy ambiguous language over the well-specified one, creating a mish-mosh of two languages: logical human and illogical human. That sounds like a good idea, because what we really need is to say everything, and then say it again badly.

    Commenting is highly overrated, and a lot of people have been indoctrinated by teachers that have little work experience. The adherence to code commenting stems partially from it being a first-pass attempt to avoid the shortcomings of a waterfall development process. Now we can do better. We prefer functionality over documentation. Well written code should be transparent to a seasoned developer. If it is not, see the two qualifications in the previous sentence. Commenting usually just mis-specifies what's going on, lets people get away with writing sloppy code, and encourages people to not read code that they ought to.

    The main exception to the above is the documentation of API interfaces, which is really an extension of the concept of encapsulation. In this case, the developer really shouldn't have to read the code in question (though in practice one always winds up having to read a little).

    1. Re:Here's an idea by jjohnson · · Score: 1

      At a Java con I went to a talk by Dave Thomas, one of the authors of The Pragmatic Programmer. The line that stuck with me was "A comment is a lie waiting to be believed."

      --
      Anyone who loves or hates any language, platform, or manufacturer, doesn't know what they're talking about.
    2. Re:Here's an idea by rgviza · · Score: 1

      another problem with comments is the functionality changes and nobody updates the comments, so a developer coming in later will get the wrong idea and be even more confused than if the comments weren't there leading to more head-scratching.

      Sometimes comments are worse than useless.

      --
      Don't kid yourself. It's the size of the regexp AND how you use it that counts.
  68. Tell the tramp to shut up. by tjstork · · Score: 1

    I have no idea who this self proclaimed expert is, and as far as I'm concerned, her sweeping statements suggest that nobody else should either.

    Go away!

    --
    This is my sig.
  69. Only if you pay for it. by tjstork · · Score: 1

    You can get all of that, if you pay for it. Most people would rather have features now, and never touch the code.

    --
    This is my sig.
  70. 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
    1. Re:Roman Bridges by Anonymous Coward · · Score: 0

      The same is true of the Brooklyn Bridge, which was by some estimates engineered to be 10 times stronger than it needed to be. And even though the rivets supplied (by a corrupt contractor) had half the strength planned for, the bridge was still more than strong enough not only for the horse-and-buggy traffic of the era but now for modern cars and buses.

    2. Re:Roman Bridges by Anonymous Coward · · Score: 0

      This statement is just incorrect. Give ANY engineer the ability to "over-engineer" their design and they will. The recent changes in the way things work has forced engineers to design things "at the optimal" because the bean-counters somehow gained more power over them. In this day and age, cost is more important than a robust design.

    3. Re:Roman Bridges by Anonymous Coward · · Score: 0

      Well, also, the Romans genuinely wanted and expected the things they built to last forever. I don't suppose the people who designed the Bay Bridge asked themselves, "Will this structure still work five hundred years from now? A thousand years from now?" But Roman builders did.

    4. Re:Roman Bridges by OrigamiMarie · · Score: 1

      Also, San Francisco has earthquakes. Earthquakes are much better than floods at destroying bridges.

    5. Re:Roman Bridges by Krokus · · Score: 1

      Bit off-topic here, but over-engineering structures has been commonplace until around the 19th century when engineers started actually understanding what Hook and Young were saying. With no understanding of stress concentrations and, consequently, why ships kept breaking in two while at sea, people of the day would ensure that the forces acting on their structures were well below the breaking stress of the materials, sometimes by as high as a factor of eight or nine times the breaking stress. This was called the "factor of safety" and often referred to as the "factor of ignorance." Not surprisingly, this puts up the weight and cost of the structure considerably.

      This is why early aircraft designers spent more time increasing the power of their engines than trying to deal with reducing the weight of their contraptions; if you throw enough power into it, you can get just about anything to fly. :)

      I suspect it's also why people have historically considered heavy structures to be safer than those that are "light and flimsy."

    6. Re:Roman Bridges by ACorrosionOfDeviants · · Score: 1

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

      "If in doubt, make it stout,
      for things you don't know much about"

      - A pearl of design wisdom shared with me early in my career from a seasoned mechanical design engineer. Very memorable.

    7. Re:Roman Bridges by deoxyribonucleose · · Score: 1

      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.

      The Romans built plenty of bridges that collapsed. The ones we have left are exactly those that were over-engineered. The Romans were no less short-sighted than we are: they just didn't know as well how close to the edge they could get, so the outer extremes of the Bell curve are still around. We're better engineers, so I'd deem it likely that nothing we've built during the last century is gonna be around in a couple of millennia.

    8. Re:Roman Bridges by deoxyribonucleose · · Score: 1

      Well, also, the Romans genuinely wanted and expected the things they built to last forever. I don't suppose the people who designed the Bay Bridge asked themselves, "Will this structure still work five hundred years from now? A thousand years from now?" But Roman builders did.

      No, they didn't. They were just as pragmatic then as we are now. Most Roman buildings aren't around anymore, except for those that were ridiculously over-engineered and didn't tick off some passing barbarian too much.

    9. Re:Roman Bridges by sensei+moreh · · Score: 1

      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.

      Hey, I crossed that bridge when I came to it.

      --
      Geology - it's not rocket science; it's rock science
    10. Re:Roman Bridges by Anonymous Coward · · Score: 0

      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.

      No, that would be because the Romans had just as good of an understanding of what they needed to engineer, but since the actual manufacture of the stone, metal, morter, etc. was much less precise they had to engineer in a large enough margin of error to make up for inconsistencies in their actual manufacturing processes, natural variation in stone, etc. AND they built stuff with the intention of having it stand up for as long as possible within reason. These days we don't build stuff to last nearly as long, and have much more precise manufacturing tolerances, so it's much easier to be exact.

    11. Re:Roman Bridges by Anonymous Coward · · Score: 0

      The George Washington Bridge across the Hudson River was also over-engineered

      It is only over-engineered if you don't believe a bridge lasting that long should exist. It still works for its intended purpose, plus some. I'd say NY got a heck of a deal out of it, which is much less than can be said for the I35 bridge in MN.

    12. Re:Roman Bridges by Le+Marteau · · Score: 1

      > I don't suppose the people who designed the Bay Bridge asked themselves, "Will this structure still work five hundred years from now?

      Actually, they built it expecting it to last 150 years. Which ain't too shabby.

      http://www.dot.ca.gov/dist4/eastspans/index.html

      --
      Mod down people who tell people how to mod in their sigs
    13. Re:Roman Bridges by Anonymous Coward · · Score: 0

      Not to mention the fact that the Romans never attempted to build a bridge that spans several miles and would carry the types of loads modern bridges do.

  71. So you are a good coder if you write short comment by roguegramma · · Score: 1

    So you are a good coder if you write short comments, like (?): //HACK !RG: code must work with decimals although it was never planned to.
    hack();

    --
    Hey don't blame me, IANAB
  72. Real Programmers... by BrokenHalo · · Score: 0

    Real Programmers don't need comments - the code is obvious.

    1. Re:Real Programmers... by BrentH · · Score: 1

      Real tits don't need nipples, the fatbulge says enough.

    2. 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.
    3. 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"
    4. Re:Real Programmers... by the_lesser_gatsby · · Score: 1

      Your code should be a narrative. How about checkParamaters(...); setupConnection(...); submitQueries(...); checkReturnValues(...);

    5. 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.
    6. Re:Real Programmers... by Anonymous Coward · · Score: 1, Informative

      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"

      A lot of times, I have comments like that, because I wrote the comments before I wrote the code (i.e. pseudocoding in advance).

    7. Re:Real Programmers... by TheCarp · · Score: 1

      You know, now that you mention it, thats why I write stuff like that too. Often its with a: // XXX: Should take other conditions into account!

      --
      "I opened my eyes, and everything went dark again"
    8. Re:Real Programmers... by mwvdlee · · Score: 1

      Yes, the million lines of code are completely obvious and easy to understand.
      The ten line comment just explains it a bit quicker.

      --
      Slashdot social media options: AIM, ICQ, Yahoo, Jabber and Mobile Text. Why no MySpace?
    9. Re:Real Programmers... by mwvdlee · · Score: 1

      doEverything(...);

      --
      Slashdot social media options: AIM, ICQ, Yahoo, Jabber and Mobile Text. Why no MySpace?
    10. Re:Real Programmers... by BrokenHalo · · Score: 1

      Yes, the million lines of code are completely obvious and easy to understand. The ten line comment just explains it a bit quicker.

      Sorry guys, I didn't mean anyone to take me seriously. Just to spell it out:

      Whoosh.

    11. Re:Real Programmers... by xQx · · Score: 1

      Real Programmers don't comment code. If it was hard to write, it should be hard to read.

    12. Re:Real Programmers... by Anonymous Coward · · Score: 0

      True. This is why caressing a nice set of nalgas is every bit as enjoyable as caressing a nice set of tits.

    13. Re:Real Programmers... by not_a_product_id · · Score: 1

      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"

      For me that's the main reason I comment. I started off as a maintenance programmer and quick often I was looking through the codebase trying to find the procedure (or section of some 600 line behemoth) that I needed to fix. In a case like that I don't want to read 100s of lines of code I have no damn interest in.
      The key to these is to keep the comments quite vague.

      The other times I comment is to clarify code (quite often you are only allowed to make a specific fix on code that is a clusterf*ck) or to explain why I didn't do something in what seems like the 'obvious' way.

      --

      ---
      We spoke for about a half an hour. I don't recall a thing we said. - Colorblind James Experience

  73. Re:Tästä voit hakea sanan kategorian (av by TeknoHog · · Score: 1

    "Here you can find the category of the word"

    I'm sure somebody will try to correct me in that "hakea" actually means "fetch" or "search", but in this case I find "find" more appropriate. The word "avain" means "key" and it is probably related to explaining the idea of "category".

    --
    Escher was the first MC and Giger invented the HR department.
  74. I don't understand by PPH · · Score: 1

    What are these things you people call comments?

    --
    Have gnu, will travel.
  75. I can't code worth anything by Anonymous Coward · · Score: 0

    ...but my comments are awesome.

    Seriously, just look at all the +5 A.C. comments I post.

  76. I agree... by Chris.Nelson · · Score: 1

    I've also heard (I can't remember where), "If the code and the comments disagree, they are both wrong."

  77. Long comments - simply by Anonymous Coward · · Score: 0

    The simple thing is a comment should be meaningful. A simple statement or a long explanation it should MEAN something to those who see it. If you write a long comment and it needs to be long fine, but if you write a 500 word essay that boils down to nothing (we all remember the school English assignment about the book we never read...) the get it out of there. No comments make a mess but so do long winded nothings. On that note I'll shut up.

  78. Rubish by mce · · Score: 0, Redundant

    One simple question regarding spelling/grammar mistakes: What about non-native speakers? Is their code bad just because he or she tends to write "recieve" instead of "receive" (just one example mistake that is quite common for native Dutch speakers due to bias by his/her mother tongue)? I would hope not... TFA goes as far as to claim that non-natives actually tend to have better English language skills. First of all, I'm not convinced of that as a general rule. But even if it were true, there will always be traps for even those people to fall into unknowingly. What's more, I myself most certainly know about "receive", but even so I get it wrong at least 75% of the time. I also know that due to "selective blindness" reading the comment afterwards is not enough to catch all of those.

    At the other extreme: Back when I was still writing code on a daily basis, I tended to spell check it every so often and fix any mistakes found. Talk about bitf*cking... :-) But I fail to see why wasting time on doing that would be a guarantee of proper design.

    1. Re:Rubish by kenrro · · Score: 1

      and, what about native speakers? I was always good on math but terrible on spanish, And I mean, choosing the right letter between s/c/z, knowing where to put the damn 'h', Using "Accents" was beyond my capacity/interest, doing cojugations of weird words related only to those who needs the program, and... I really never understood where to use the ";" puntuation... So what? I dont care, most of the time they dont care either, If they understand the text, thats enough to me.

    2. Re:Rubish by clone53421 · · Score: 1

      "Rubish" made me chuckle.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    3. Re:Rubish by clone53421 · · Score: 1

      The semicolon (;) is used to join two related sentences, to indicate their relation to each other. The colon (:) and ellipsis (...) are similar in this respect. The hyphen (–) can vary; it can be used to set off parentheticals – like this – but it can also separate two complete sentences.

      The two must be complete sentences; if they can't stand on their own, they are grammatically incorrect.
      –> The two must be complete sentences. If they can't stand on their own, they are grammatically incorrect.
      Thus, this was an example of correctly using the semicolon.

      The comma, on the other hand, joins phrases, not sentences. None of the comma-delimited segments of that sentence would be a grammatically complete sentence in its own right.

      You'll often see the ellipsis used in the place of a comma... but I am pretty sure this is incorrect. (As "but I am pretty sure this is incorrect" is not a sentence, this was a grammatically incorrect use of the ellipsis.)

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
  79. Nit picking by EmperorOfCanada · · Score: 1

    I agree that coders should not be sloppy. "Ah the user will never hit return more than once" but outside of a mission critical application nit picking is a great way to never get anything done. The most successful companies generally have the approach of "Let's put some lipstick on this pig and get it out of here." While not being the statement of a careful craftsman it is what gets the bills paid.

  80. 20 GOTO 10 by Anonymous Coward · · Score: 0

    Nothing sloppy about GOTO, it makes my code work :)

    1. Re:20 GOTO 10 by clone53421 · · Score: 1

      I'd love to come to GOTO's defense – for nostalgia alone – but I really can't bring myself to do it. Yeah, everything's a GOTO in assembly language (and I have done a bit of tinkering with assembly language, so I'd know), but I really can't think of any situation where GOTO would be better than higher-level flow constructs.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
  81. Try Wordpress by danielpkern · · Score: 0, Offtopic

    Why not just use wordpress & download some of their comment plugins like the Spell Checker plugin? We are looking to make the switch to this CMS for a number of sites (Cup of Comfort is one, which offers story review services, a cool ongoing story contest, and writing webinars).

  82. 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
  83. Who needs comments? by thetoadwarrior · · Score: 0, Troll

    All my variables are single digits too. I try to keep method names no longer than 4 digits and I get a wood over cryptic package names. When you write perfect code you don't need comments or dumbed down names. It's just so obvious what is happening in the code.

  84. Show me the code because I don't buy it. by tomhudson · · Score: 1

    FTFA:

    Surely, you don't need me to cite the number of famous programming failures that were the result of a developer using a comma instead of a period

    If it's c++, it probably wouldn't compile, so it would get fixed, so yes, I need you to cite famous programming errors where that happened, because I don't buy it. Links or it didn't happen.

    Remember - famous. Not trivial "example code".

  85. Ugly code and ugly comments by Anonymous Coward · · Score: 0

    When I get board and go looking for bugs the first thing I do is look at comments. Writing styles or signatures of the clueless developers on our team serve as beacons bugs are hopelessly beckoned to. Its not the quality of the comment itself but the person behind it that is most interesting.

    Comments starting with "This fixes" sometimes have a tendancy of breaking other things or still failing to cover the entire problem space. Its mostly I believe those who waste space bragging about what they fixed tend to be noobies who to quote yoda still have much to learn.

    Comments "blaiming the compiler" bring up imagary of smart little critters laughing at the dumb humans who can't squish them and always contain bugs.

    Comments with profanity and insults are written by people who couldn't think their way out of an open window. They are also at risk of going postal at some point in the future. When you fix their code do yourself a favor and don't tell them about it. Use an alias when submitting changes to their work in your revision control system.

    Comments with funny jokes are always written by genius talent. You should not waste your time and just assume the problem is elsewhere.

    Comments with apologies (sorry..et al) are often a reflection of a bad form of laziness OR developers who have accepted that everything anyone will ever do is crap and persistantly strive to produce less smellier crap. Its a mixed bag - the bug load and realitve quality of such code depends on who wrote it.

    Use of bad english, mispellings..etc I have never really found a usable signal in. It could be that english is not the native language of some or people rightfully want to get crap done and invest no time in spell checking comments.

  86. Commenting Practices by PerfectionLost · · Score: 1

    A short description never hurt anyone.

    I also find that if I am writing complicated code I like to write all the comments beforehand, and then fill in the specific jargon afterwords.

    //Loop over every item.

    //Preform some menial data manipulation if this is an existing item

    //Do a nested loop if necessary

    //Finish looping over items.

    //Commit data.

    It's like writing an outline before you write the story, which I find really useful in fiction as well. That way you know where you are going in the end.

  87. I don't understand? by Murdoch5 · · Score: 0

    Wait so because I write comments my code is there for broke. That's the most ridiculous thing I've ever heard. If the code has spelling errors in it could it be the the programming has bad spelling, or maybe bad grammer, which is turn would have nothing at all to do with there programming skill. for instance.

    int main(void) { //Prints helo world printf("\nHello World"); }

    I put a spelling error in there on purpose, well the code would work fine. What about being forced to leave comments for a prof to help explain the code. I really can never see how ugly comments lead to ugly code. Comments are a helpful feature of code if the programmer wants to put them in, they have no need to put them in and if the programmer doesn't want to they don't.put them in.

    Complaining about the comments is like complaining about the indenting. So because the Identing is done using space not tab the code is broken? Of course not, Any one who's going to complain about people not writing comments of anything outside of the code are just covering up for there own lack of programming skill. Any real programmer will agree that comments are there for the programmer them selves to help them remember in a year or two if they go back to the code what they were thinking.

    Weather the code is ugly or not has nothing to do with the code working, the code works or doesn't. Past that the code is only rated based on memory and CPU use, thats it, not comments, not identing or anything else.

    1. Re:I don't understand? by nick_urbanik · · Score: 1

      The article raises valid points.

      I rest my case based on the evidence above.

    2. Re:I don't understand? by Murdoch5 · · Score: 0

      No it doesn't, explain how an ugly comment = ugly code. In fact just read the GNU coding standard if you want to be a good coder.

    3. Re:I don't understand? by Anonymous Coward · · Score: 0

      Weather the code is ugly or not has nothing to do with the code working, the code works or doesn't. Past that the code is only rated based on memory and CPU use, thats it, not comments, not identing or anything else.

      Code serves two purposes: 1) to build an algorithmic software "machine" that solves a problem, and 2) to document that machine for programmers who need to modify or fix it.

      You're right that "ugly" code with missing or poor comments doesn't affect purpose #1; unfortunately, it fails utterly at purpose #2. Does that help?

  88. Two skills involved: Mathematics vrs English by GasparGMSwordsman · · Score: 1

    Source code is a English (or human readable) language copy of a mathematical formulation. I have met a fair amount of very good programmers who had a very strong mathematical background but had very little strength when it came to writing.

    Because of the mathematical background many comments were bad because they simply stated the equation (a + b = c as an example). Other times the author simply wrote a lackluster or bad English comment. In those example the CODE in question was superb.

    My point, in summary, is that writing coherent and precise statements in any language is a skill. That skill is NOT needed to understand engineering or mathematics. Likewise, it is not needed to write good code.



    Having said that point. Most people who write bad comments are usually not interested in the larger picture involved and seem to "cut corners" a bit to often. In my experience this leads to either bugs or a maintenance nightmare.

    There is also something to be said about being a well rounded person.

  89. Here is a sample of comment from my code : by unity100 · · Score: 1

    ###############
    ######## fUkc graNMar
    ###############

  90. I write mine in swahili by SmallFurryCreature · · Score: 1

    I write my comments in swahili, if the comment was hard to write, it should be hard to read.

    --

    MMO Quests are like orgasms:

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

    1. Re:I write mine in swahili by Anonymous Coward · · Score: 0

      If Swahili is hard to write for you, then why would you go out of your way to make it hard to read for everyone else?

      Other than to be a jerk ofc...

      Also, MMO Quests are nothing like orgasms.

    2. Re:I write mine in swahili by Cederic · · Score: 1

      Code should always be in English. Comments should always be in the language of the development team.

      I just hope your colleagues are all from Africa ;)

  91. /* You are not expected to understand this */ by lbalbalba · · Score: 0, Redundant
  92. comments are mostly automatic by anonymousNR · · Score: 1

    I don't know if this is the right thing, but my experience is that I don't comment in general, no matter how complex problem the code solves, but when I recall my code, or go to debug something most of the time I find that I automatically commented something while coding if I was not sure or thought I should at that time to leave a comment there, so in that ratio I have very few comments on my overall code, but also I have had co-workers who ask "what the f**** is this ?" if something I wrote is not clear.

    --
    -- It is the mark of an educated mind to be able to entertain a thought without accepting it. -- Aristotle
  93. had to put down my cheetos to reply to this! by Anonymous Coward · · Score: 0

    // If it was hard to write, it should be hard to read.

  94. Not In India... by Anonymous Coward · · Score: 0

    where Caucasian niggers code stuff that works and for cheap. If it works they just move to next stage.

  95. Real-world materials are inexact; software isn't by billstewart · · Score: 1

    There are exceptions; timing-related software or analog inputs may be dealing with inexact bits, but basically everything you're doing with software is precise. Real-world building materials aren't. I once helped a crew of retired construction workers build a church, and not only did they use a lot less effort than us young guys (because they could hit something once, in just the right place, instead of waling away at it like we did), but they also had a lot of insights like "this board's a bit green, so as it dries it'll twist a bit _that_ way, so we should put it in this way up and nail it there so it stays in compression when it does that instead of going into tension.

    --

    Bill Stewart
    New Fast-Compression-only CPR http://preview.tinyurl.com/dy575ks
  96. Comments? by pak9rabid · · Score: 1

    The code you have to deal with actually has comments in it? That must be nice. The only time I ever encounter comments at work when having to deal with someone else's code is when it says something along the lines of /* I'm really sorry about this... */

  97. 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)
  98. 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.
    1. Re:You've got it backwards. by Anonymous Coward · · Score: 0

      So true for my former bosses!
      Boss is likely more like an entepreneur who has now moved on.
      Commenting and documenting? That was not what sold the initial versions.. But NOW that you are the programmer, all this is required! (oh yeah)

    2. Re:You've got it backwards. by smellotron · · Score: 1

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

      Find a new boss in a company that values skilled employees. I am in a fairly good position specifically due to being meticulous, but correct (and something of a snob, I'll admit). Any time my higher-ups have written code, it has always been clean and simple (and warning-free, even after upgrading our build software).

  99. 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?
  100. What utter poppycock by wb8wsf · · Score: 1

    Comments are a skill in and of themselves, which a whole lot of people never master.

          I remember two people who worked at a place where I was programming. The first
    was a woman, freshly out of school who was taught that comments made the code.
    So she dutifully wrote beautiful comments on the theory of what the function was
    going to do, but also inline, especially for arcane things going on in an algorithm. All
    nicely spaced, neat. A marvel to behold. Problem was, the code this person did
    had some form of overflow condition (this was C) about every five lines, such that
    I knew if I poked at the code from a higher layer I could cause problems. And did,
    because I was trying to force the issue and have some kind of review go on.

          The other person in the larger group was a 20ish male, who saw human interaction
    largely through the eyes of TV, and gaming / nerd get-togethers. Hardly a bad person,
    he just didn't seem to have humans around him when growing up (more than a trifle
    odd, even now--I met him again for the first time in 20 years; the only change was
    gray hair). He was one of the people I'd go to for help when I botched things, or
    wanted comments on an idea I had. His code often worked the first time run, and
    I'm not talking of little 10 line routines, but larger complex functions. His comments
    were about the opposite of the code, both in terms of spelling, grammar, and that
    ephemeral concept of how to communicate in general. Some sentences were
    better read thinking of them as RPN, and others simply defied standard logic.
    Comments that did survive that minimal test of English were often spelled in
    novel ways, causing euqal parts of head scratching and laughter. But the code
    was great!

    I offer these two examples which while extremes, are examples that poke holes
    in the idea that there is a common relationship between comments and code.
    Certainly some people will fit that mold, but I think that more random than not.

  101. Re:The comment may have an imaginary component by Tetsujin · · Score: 1

    Comments are a sign of bad code. That's because the more comments you have, the more errors you have in your comments. Uncommented programs have zero errors in comments, which points to excellent code.

    Naw, you've got it backwards...

    See, any given block of code is bound to have a certain number of errors - say, at a rate of 2 errors per thousand characters. The comments don't really impact the number of errors you'll get in the code itself. If the odds of any given program byte being in error is "r", and the length of the program code is given by "s", then the number of errors is "r*s" - so the only way to minimize the number of errors in your program is to make it as small as possible!

    --
    Bow-ties are cool.
  102. I thought code was syntax by Anonymous Coward · · Score: 0

    Syntax is like English grammar. The vocab of a computer language is much smaller than that of English.

    That you need comments to read syntax is like saying you need comments to explain the english in a book--which are typically footnotes and sparsely used. And that's the way it should be--write comments only if the code is unexplainable.

    The only time I see lots of footnotes in a book/article are in scientific papers--which are typically explaining someone's crazy spin on how the world works.

  103. Depends on the situation by Lonewolf666 · · Score: 1

    When the deadlines get near enough, you may be faced with a choice of using the somehow-not-broken code or miss the deadline. Been there, done that.

    But at the same time, I recognize the dangers and I'd rather not work that way. In short, unless I got a manager breathing down my neck who jacks up the pressure, I take the time to do it the right way. And in the long term, it usually pays off. Because intransparent and poorly understood code will pile up to the point that no one understands it anymore.

    --
    C - the footgun of programming languages
    1. Re:Depends on the situation by Anonymous Coward · · Score: 0

      Because intransparent and poorly understood code will pile up to the point that no one understands it anymore.

      The word is 'opaque'.

  104. Re:On bridges and traffic by Tetsujin · · Score: 1

    The real reason who those bridges are standing while the Bay Bridge keeps going down is called "cars". The Bay Bridge is under much greater load than any Roman bridge ever was. Tectonic activity in the Bay Area probably doesn't help either...

    Wait... I'm confused... Is this a car analogy or not?

    --
    Bow-ties are cool.
  105. Cody Ugly by carrier+lost · · Score: 1

    I sometimes comment my code in excruciating detail. But that's when what I've done was so hard to figure out in the first place, I want to make sure that whoever comes after me or if I have to revisit it again, there's some explanation as to what the hell's going on.

  106. It's just another indicator of how good you are by Anonymous Coward · · Score: 0

    The range of views aren't exactly shocking, somewhat upsetting at times though.

    Comments should explain the intent in clear language, in my career I can't count how many times that helped someone else fix a bug in a domain that they knew very little about. Yes, the code does what the code does and comments may not be consistent with that but they should and those inconsistencies are defects. Really good code doesn't need a lot of comments but what about the domain knowledge? Is there any chance you'll bring someone new to the team that doesn't know the domain yet and want them to work on bugs? Is there any chance that the domain might shift?

    As to the correctness and the effort put in to comments, it's just another indicator, is the author of the code a hack or a craftsman? Shit, modern IDEs even have spell checkers builtin for comments, it's not that hard. I've struggled with it at parts of my career, we have this pressure to work fast to get things done quickly and especially in American start-ups we want to skip the bullshit and get to work on the real problems we're trying to solve. It's this hacker culture thing that has been created, you hear legends about guys that coded all night and how they wrote xyz in a month of 7 day work weeks and so we think that the LoC count is what matters. As a result, I've seen giant complicated programs with minimal comments, I've seen labs with just complete messes of wiring, tons of other things ignored, install and upgrade processes completely ignored because "that's not coding"... all these roadblocks that are created that eventually prevent a team from being really agile and quick. Basically, if you do a half-assed job at some things, you'll probably do a half-assed job at others and it's just a matter of time before that affects the product. As a software engineer, doing a half-assed job at things that touch the code is terrible, at that includes comments. It's better to have good comments and not need them than it is to not have them and need them. It's funny, everyone who has written code has spent time fixing some small one line defect, you know an off by one or something like that, and it's stupid and easy once you see it but that didn't prevent it from being written in the first place. You cna't be a perfectionist and do everything perfect but what things do you want to half ass and who do you want it to affect?

    It reminds me of another saying someone told me a long while back. Cars don't have brakes so they can go slowly, they have brakes so they can go fast. It strikes me that if you don't have time to write a few lines about what some method or class or function intends to accomplish in plain English, you've got some other problems. You need to pump the brakes a little. You can code as fast as you want and cut out keystrokes and, clearly a bracket is much less time consuming that "BEGIN" but at the end of it all, can you speed up the thought process of architecting good software? I'll do them one better, coders that don't comment usually aren't architects and usually aren't nearly as senior as they like to think they are. I don't think it's universal but I've seen at least a couple cases where they were difficult people to have on teams, they simply didn't like to work with others and probably spent more time defending their turf or jobs than building killer products. Sure they can code, but I usually want something else on my team, there are a whole lot of guys in China and India that can code...

  107. I don't buy it by ajs · · Score: 1

    Some of the finest code I've ever worked on was uncommented. Some of the worst code I've ever worked on had terse, but informative and readable comments.

    This smells to me like someone who didn't work with very good code becoming aware of the fact that their initial assumptions about comments were incorrect. Sadly, they have yet to discover that their second round of assumptions is just as invalid.

    If you ever want to browse through some solid code in order to get an understanding of what good code looks like, I suggest GCC. Just one example file (gcc/alias.c) starts with a comment on line 50 which continues to line 129, and I assure you that it's not there because the person who wrote it didn't understand what was going on.

  108. Some documentation guidelines by Anonymous Coward · · Score: 0

    I just recently wrote some API documentation guidelines for our developers. You might want to check them out (click "downloading" link) if you are interested.

    Feel free to comment, I'm sure some points in the guidelines may be questionable. There's also a handy reference card (click "downloading" link).

  109. I usually write a code comment and then .. by roguegramma · · Score: 1

    I usually write a code comment and then discover that I should move the code under the comment into a separate function anyway, either for readability (e.g. of page-long loop) or re-use, so then I can shorten the comment to a function name and live without the comment.

    Long or copy-and-paste generated comments often suck, because like code, they tend to rot when not maintained properly.

    Comments describing method "contracts" are usually the most useful, while comments of the kind "parameter: Integer result - the result" are not very helpful, even when they cover every method.

    --
    Hey don't blame me, IANAB
  110. Flogger by BadBlood · · Score: 1

    I once mis-spelled the word "fogger" by typing "flogger." I hadn't realized it until a co-worker need to port my code to another application. We left it as flogger simply for amusement. The code worked properly though.

    --


    Praying for the end of your wide-awake nightmare.
    1. Re:Flogger by Anonymous Coward · · Score: 0

      I once mistyped "bigger" as "nigger". Not surprisingly, it didn't work.

  111. Re:The comment may have an imaginary component by clone53421 · · Score: 1

    You wouldn't happen to code in Perl, by any chance?

    --
    Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
  112. Re:The comment may have an imaginary component by Tetsujin · · Score: 1

    You wouldn't happen to code in Perl, by any chance?

    Hey, the math speaks for itself... What can I say?

    --
    Bow-ties are cool.
  113. Re:Comment bugs and lack of comments a worse probl by Anonymous Coward · · Score: 0

    I have a bunch of witty and spiffy comments to make on this, but you summed it up quite nicely. I should just move to the next article - haha.

  114. I comment, therefore I code? by Sterculius · · Score: 1

    I don't comment my code at all ... does that mean it doesn't really exist?

  115. Doesn't matter whose "fault" it is by Gorimek · · Score: 1

    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.

    If the practice doesn't work in reality, it is not a good practice, regardless of whose "fault" it is. Fortunately there are better ways to achieve readable and maintainable code.

    The usual way comments are used is to write crappy code, and then add comments to explain it.

    This is analogous to using perfume to cover a bad smell. It kinda works, but it is much better to get rid of the stench in the first place. Translated to programming, that means that you should work hard to make your actual code readable. That means good naming, but also good general design. If you can't find a good name for a class or function, that is a clear sign it should be redesigned, probably broken up.

    If you do this well, there some things will still need comments, and for those you should by all means do so. But it is probably 1-5% of the typical "well commented" code base. In code like this, when you see a comment, you will actually be interested to read it!

    This way you also have no need to apply the strict discipline that you talk about of always updating both the code and the comments, and there is no risk that they get out of sync. All that energy and effort you have to spend doing that can then be redirected to more productive efforts.

  116. Hope you are being ironic... by Anonymous Coward · · Score: 0

    10 PRIN "WTF"
    SYNTAX ERROR ...obvuous...
    SYNTAX ERROR ...or runs is an unexpected way...
    SYNTAX ERROR ...There are a lot of times I'll see slashdot comments...
    SYNTAX ERROR

  117. Pheew by CptPicard · · Score: 1

    Glad I don't comment.

    --
    I want to play Free Market with a drowning Libertarian.
  118. Re:Real-world materials are inexact; software isn' by plover · · Score: 1

    Real-world architecture, engineering and construction is designed around those measures of imprecision. There's a reason the architect specifies a dimension to be 3' 0" and not 3.000 +.000 / -.005. Saws aren't that precise. Tape measures aren't that precise. Carpenters aren't that precise. So the architect leaves trade practices to make up the difference. Instead of trusting the lengths of the boards are exact and will make the walls perfectly plumb, he uses a level. Or since finished wall boards never actually touch the floor, he covers the gap with trim boards. That permits expansion and flexing without cracking the walls. As a result, your house is nice and straight, and yet it isn't "brittle". The trim boards at the interfaces better look nice and fit nice, even though the ragged edges they cover are certainly rough.

    Software can be designed and built the same way. Typeless languages are one method, and exception handling is another. Encapsulation is all about hiding ugly details behind a precise interface. Design by Contract is one way to ensure the interface itself is precise, regardless of the code behind it.

    They still have to be "pretty close" to be acceptable. A 2x4 can't be completely twisted like a corkscrew, nor can a floor be a bubble off from level. You can't use a 2x8 when a 2x10 is specified. Likewise, your calculations still have to work. But if your calculation is almost instant 99% of the time, and marginally slow but still OK the other 1% of the time, it might be good enough for your application.

    At the end of the day, software interfaces better look nice and fit nice and do their jobs. But the internal workings of the tasks can be ragged and yet still function effectively (most of the time.)

    --
    John
  119. WTF comments by Anonymous Coward · · Score: 1, Funny

    You should at least comment your code, such that the next time (3 am) someone (you) is looking at your code you can make some sense of it.

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

    1. Re:I can't believe the OP is even possible by murcon · · Score: 1

      I mostly agree -- comments are not proof that the coder understood the problem (although it may be evidence he or she did NOT); instead, comments are an effort by the coder to lift up the next coder who has to maintain, fix, extend or test the code. I think of comments as time-saving work: you are doing a few minutes (or hours) work now, to save Future You (who may wear a different face) from spending hours (or days) and costing your company a lot of money.

      However, when you are faced with a block of code you don't understand (whether you wrote it or not), and a block of comments, it's going to be hard to trust that block of comments if it's filled with grammatical or spelling errors.

  121. Real men by halcyon1234 · · Score: 1

    Real men don't comment their code. They put it on ftp and let others create a wiki for it.

  122. Your code must be logic-free by syousef · · Score: 1

    Yeah its funny but the more someone doesn't agree with my point usually the worse their own code is.

    Are you listening to yourself? "If you disagree with me I'm going to assume you're a lousy coder". How am I suppose to argue with that exactly? Submit code to you for a code review? Clearly this is a comment from someone who'd prefer character assassination of someone they'd never met to actually refuting or counter-arguing.

    I guess yours must be pretty bad, not that you would ever see it yourself.

    Your argument style is the height of irrationality, and it's pretty clear you have zero inter-personal skills. With such a poor command of logic as you've demonstrated with that, I'm not convinced I'd want to use anything you wrote either, but at least I'd have the common courtesy of LOOKING at and evaluating your damn code before making such a rude obnoxious comment.

    FYI I have had some fantastic feedback on my code, and I make a pretty decent living at it. So what do you think I'm going to care about? The ramblings of a stranger who's never seen my code here on slashdot or my performance review and pay cheque.

    It would have been much more concise if you'd just said I had cooties.

    --
    These posts express my own personal views, not those of my employer
  123. Let me see if I understand... by Anonymous Coward · · Score: 0

    So what your saying is if I don't comment my code at all, then by definition it must be genius?

  124. Roman Aquaducts? by gbutler69 · · Score: 1

    They've stood for greater than 1,000 years. Do you think they fully understood all the physics? HINT: No, they didn't.

    --
    Over-the-top Response Guy! Giving "Over-the-Top Responses" since 1970.
  125. Survivorship Bias. by gbutler69 · · Score: 1

    Hmmm.....that sounds a lot like "Evolution". Maybe the I.D. folks should take note.

    --
    Over-the-top Response Guy! Giving "Over-the-Top Responses" since 1970.
  126. Re:The comment may have an imaginary component by xQx · · Score: 1

    _script_ in Perl. ... Perl is as much a programming language as is html.

    And Perl coders are as much programmers as MCSE's are engineers.

  127. My beautiful code snippet by InfiniteLoopCounter · · Score: 1

    public static publicstatic(int main) {
    label:
    long long long_number = 0;
    for (int inti=0; inti>0; ++i) { };
    long int integer = 0;int sky_is_green = sky_is_blue= 0;
    if (long_numer!=80) {
    if ((long int) long_number==integer && sky_is_green!=~long_number) printf ("hell");
    if (!sky_is_blue) printc('o');
    else print ("my god!");
    printc(" "); }
    else if (!sky_is_green!=sky_is_blue)
    goto label;
    else
    printf("there");
    printf("world!"); }

    /* This beautiful code snippet above outputs the phrase "hello world!" to the display. */

  128. Golden Rule by jumpfroggy · · Score: 1

    I think the golden rule applies here; do unto your code what you wish your predecessor's had done to their code. If you write your own code, maintain it yourself, and never have anyone else work on it, then do whatever you want. Heck, use no punctuation, indentation*, or even carriage returns if you can help it.

    However, there seem to be two camps; those who see the value in comments, and those who don't. Comments wont detract from those who don't like them (besides more trivial annoyances like wasted screen space), while the lack of comments may significantly hamper those who would appreciate it. It seems safer & more efficient to comment and make understandable code accessible to all, instead of saying that "good programmers" shouldn't need it, and raise the requirements unnecessarily for the maintainability of your code.

    Used properly, comments can help. So just find a helpful way to do it. My mindset is that I write for the next guy, assuming that someone's going to hand him the code with an explanation of what he should be doing, and the comments will help guide him. They help the same way as chapter titles. Chapter titles are unnecessary and often can be completely removed without altering the story. But try to skim through a book and find what you're looking for w/o titles, and it's a pain.

    I just jumped into an existing project that a genius (really) friend of mine started. He's very smart, but not as experienced a programmer. And the #1 pain point right now is lack of comments. Some of the code is plain spaghetti. That's fine, I'll just refactor it. But since there's no comments describing *why* it's doing what it's doing, I can't yet refactor.

    Other things work just fine. But again, lack of comments prevents me from understanding what it's doing without understanding the entire context of the entire system. This is bad design, but that's the point - perfect code may not need comments, but none of us need worry about that (since we wont be working on perfect code anytime soon). It's not a crime to have rough code because the system is still organically growing. It is to have tons of uncommented stuff jumbled together.

    Help me to help you. Help your successors maintain your crap. Comment your code. Make things easier on people (I'll put a 1 liner describing this section, since it's a little tricky), rather than harder (Really smart people will understand this, and I don't care about the others).

    * Python users: find another way to obfuscate.

  129. Utter, utter nonsense by dugeen · · Score: 1

    Natural language runs on human brains. Programming languages run on processors. The structure of the two different kinds of hardware differs so greatly that the only similarities are at the level of analogy. So you cannot draw useful conclusions about a person's use of a programming language from the way they use a natural language. In any case, someone who uses the term 'grammatical error' in the sense used in the blog post doesn't have a sufficiently sophisticated understanding of natural language to issue pronouncements on any related matter.

  130. I hate this line of thinking by jabjoe · · Score: 1

    As a dyslexic I resent the idea my spelling is related to the quality of my code. Maybe because of my dyslexia, I have feelings about over commenting. If you want to write a book, write a book, but don't write it in your code! What I can't stand is when I can't read the code for the comments, or when the comments are wrong or pointless, i.e. the variable/function name tells you already or code and comment don't match. You end up with two sources in the same file, one real one, one for humans, why not aim for one for both? Two is asking for trouble. If you must write a lot of comments, please put it above the function so it's out the way. I feel software is organic, it evolves, it's farmed as much as designed. It quickly gets beyond what we can design. By trying to formalize it, you're sucking all the joy out and slowing down development and removing the creativity. There is a balance, you go one way it's crazy bat shit, you go the other and is slow and everyone leaves for something more fun because life is too short for such drudgery. Write as clearly as you can, comment where it's needed, automate what testing you can (without slowing everything to a point both users and developers get frustrated), then test it on as many users as you can. We all use programs written like this. I've never even seen this perfectly commented code ivory tower types rant about. If there is an open source example please point to it so I can see it. What I see if that when people first start programming, or start in a new language, they comment a lot, but that dies off as reading the code becomes easier. The other group who comment a lot are ivory tower types, and some are good, some are bad, so I don't think it helps them. I would rather good code without comments, then bad code with lots of comments.

  131. The biggest problem with FOSS by Shaiku · · Score: 1

    I tend to document my algorithms in the code. Even if the code is fairly straight forward, the comments explain what the code is *supposed* to do which simplifies the process of development and debugging. I tend to briefly describe the purpose of functions and document their inputs and outputs. It saves a lot of time when I revisit old code or share my code. It takes a lot of effort to fully comment the code and I think programmers who don't do it are just lazy. I've downloaded a ton of open source software in the hops of helping to debug or enhance it. Virtually without fail, every project I have ever seen is completely without documentation or helpful comments. It's as if somebody wrote a script to strip the comments out of every piece of code checked into the repository. I find that extremely frustrating. Even if the code is obvious and as simple as can be, there are still dozens of files to examine and commit to memory. "Was that the print function in m_system1.c or a_systemb.c ? Who the fuck named these files? " A person's code is sort of like the county's 10 volume book of codes and regulations, or the legalese on the bottom of a contract, or my health insurance provider's explanation of my benefits. Sure the words and sentences are clear enough to the person who wrote them, but the rest of us need judges, lawyers, and agents to give us the Cliff's Notes version. Code needs comments. I do believe that the effort that goes into commenting (or lack there of) is a reflection of the programmer's professionalism. And in the case of FOSS, I think it would be a lot easier for the public to contribute and for the project to change hands if the original programmers could swallow their elitist pride or crawl out of their own heads for a second and actually write some comments at all.

  132. You are correct by PMBjornerud · · Score: 1

    Seems nobody else is getting this. Sad to see that nobody made this comment already, and sadder still to see you only at +3.

    Good comments documents WHY.

    --
    I lost my sig.
  133. Meta comments by Anonymous Coward · · Score: 0

    Which is why I prefer reading Meta comments over comments that tell what said code is doing. I can tell what the code is doing just by reading it. In any case a quick comment at the beginning is enough. What really comes in handy later when fixing bugs or adding features is Meta comments. These are the "Why" did I do it that way comments. These comments explain why I'm using a certain structure, variable, etc. They explain what I was thinking at the time. Why did I do it a particular way. That reasoning may or may not be wrong later, may be able to be improved, but it gives me a real reason to re-write said code or leave it alone. i.e. It explains why if change this particular bit of code, I need to plan on changing a lot of other code as well.

  134. Mark this guy as a twit by Anonymous Coward · · Score: 0

    An idiots argument.
    I feel dumber having read this.
    If its false for one case its false for all...hey look below a false case.
    Yeah OP marked as a twit. /* This is a for loop */
    if (a == b)
          {
          DoSomething();
          } /* This here fer loop calls DoSomething MAX_INDEX */ /* times to init all linked elements to array dependents. */
    for (int i=0; i MAX_INDEX; i++)
          {
          DoSomething();
          }

  135. Python comments/docstrings need a lot more by verdante · · Score: 1

    In Python, long comments are necessary in any public-facing code.
    1) Due to the dynamic duck-typing, the docstring is the only place where you can explain to the world the exact structure and conditions of each parameter and the return value, especially if you are returning a dict that maps pairs of records to vectors.

    2) The docstrings are where you put the doctests, which form an executable mini-unit-test and mini-tutorial for every public API. doctests also mean you have to write the code with few explicit dependencies (or spend most of the test lines mocking them out).

    A 4-parameter public API function easily needs:

    1 line (maybe 2) for description, followed by 1 blank line
    +4*2 lines for the :type: and :param: descriptions
    +2 lines for :rtype: and :return: descriptions
    +5 lines or more for the >>> doctest lines
    >=17 lines of comment per such function

  136. Comments often indicate poor performers by Anonymous Coward · · Score: 0

    My experience and its fairly vast as I have seen millions upon millions of lines of source code is that well written code requires almost no comments. If you have to write very many comments then one of the below is true:

    a.) You don't have a requirements/design document and your comments are the design.
    b.) You don't understand the problem well.
    c.) Your using a overly complicated piece of code.
    d.) Your code needs to be broken down into smaller functions/procedures.
    e.) You are magical and create numbers that you insert directly into your code.
    f.) You like to write comments like "This is a for loop"

    My baby birds often start out writing massive amounts of comments when right out of school, but then they work on their own code 6 months later and come to the realization that the big comment blocks explain the obvious mostly and hide the context of the code. At the same time they work on code I have written with only small amounts of comments and find they actually understand my foreign code better than code they wrote themselves.

    People who insist on allot of comments usually are destined to be managers as they are poor coders. Think of it this way. THEY are the ones having a hard time understanding the code, so THEY want more comments. Problem is...you add the comments and they still do not understand. Meanwhile nobody else is having a problem other than the self appointed comment czar.

  137. Re:The comment may have an imaginary component by clone53421 · · Score: 1

    Still code, in a general sense. Non-literal representation of what you're creating. Anything that isn't WYSIWYG is some form of a code.

    --
    Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
  138. For what it is worth by iaamoac · · Score: 1

    For what it is worth (especially this late in the game) the quality and type of comments added to the code is a combination of several factors.

    1. Number of expected eyes. The more people that I expect to see it, the better the comments need to be.
    2. Length of development time. The longer the code takes to write, the better the comments need to be. For some of my personal/hobby projects that have lasted for months or years, I was lucky to find 20 minutes a day to work on it. Adding comments to the code was absolutely necessary so that I could get stuff done.
    3. Code complexity. The trickier the code, or the more modules/files that impact the code, the better the comments have to be.
    4. Prep-work time. The longer it took me to figure out what I needed to do (and why), the better the comments need to be.

    Re-reading through this, the longer I expect the code to be around, the better I expect it to be written and commented. I don't want to waste time trying figure out both the intent AND what the code is actually doing. Nor do I want others go through that as well. The better the comments in the code, the faster someone else can get up to speed on the code I have written, which means that it costs the company I work for less $$$ down the road.

    When writing comments, I try to include ...the 'why' where applicable, and what it is supposed to do, and on the complex code I state
          1. The INTENT.
          2. The 'WHY' where applicable.
          3. Expected state information at various locations for more complex code.

    Readability is a must. If it is not readable, then from my position it is flat out wrong. If it is not readable, you (or someone else) can not know if it is right.

  139. Sometime the "excuse" comment is actually OK. by Anonymous Coward · · Score: 0

    Except of course if you are coding in an MS environment where the work often IS the work-around. Try writing some code to replace template items in a word document using search-and-replace and you'll find yourself writing a long comment about why all the cases are required to deal with the anomalies of what is considered a "word".

  140. Kneejerk Response by pugugly · · Score: 1

    This reminds me far too much of a Major I had in the Air Force that would spout off statements like "Shiny shoes make the missiles fly better!". Sadly the First Shirt was a political climber already known for citing technical definitions like "May means Will" in maintenance procedures to enforce completely unrelated things like "Posters in barracks may have a trim applied", and was happy to accommodate this imbecile.

    Within six months we went from one of the Air Forces best flightlines to being concerned with BS stuff *all* *the* *time*. Maintenance didn't get done as fast, or as well - but hey, we had wonderful 'Team Building' Exercises among the newly promoted people with shiny shoes while morale circled around the drain.

    None of which is to say that neatness isn't a valid skill to develop doing maintenance, or that good commenting isn't a good skill to develop in coding. But there is a style of failure I associate with over-emphasis on either.

    Pug

    --
    An Invisible Entity of Vast Power whose existence must be taken on faith alone: Liberal Media
    1. Re:Kneejerk Response by pugugly · · Score: 1

      And btw, who the hell hears a sentence like 'Fractal Attention to Detail" and their reaction is not "WTF does that mean?" but "Oh, how quotable!".

      Just sayin' - Pug

      --
      An Invisible Entity of Vast Power whose existence must be taken on faith alone: Liberal Media
  141. Non onoonoeoro by DanielSmedegaardBuus · · Score: 1

    Well, they're recognizing the symptoms, but missing the point completely.

    It's the typical IT professional's misconception: "I'm using computers, therefore my skills are based on mathematics."

    No, no, no, no, no. A programmer is a linguistic being. Mathematical skills are most definitely a plus, but in my experience, the most gifted developers are the ones who are also able to express themselves verbally and in writing, and who understand the difference between the thing and "the thing".

    Mastering a programming LANGUAGE is different to mastering a human language only in that when programming, you're actually CREATING a language. The levels of abstraction are immense when you know what you're doing, as is the power, and really - if non-geeks like Heidegger, Foucault, Berger and Luckmann had the tools back then that we have know, they'd been friggin' ecstatic!

    You want a good developer? Look at how the resumé and application are written and constructed. You can sort out the first 90% of crud right there. Find someone who knows how to express himself or herself concisively and correctly and you have a starting point.

    (Btw, I'm Danish, so I know my English is crap ;) )