• Eli (unregistered) in reply to Someone You Know

    OK, smartypants, what do you suggest for a neuter singular pronoun in English? "He" is sexist and "he/she" is just awful.

    Singular "they" is clearly going to continue to grow in usage until old farts like you accept it as valid :)

  • nd (unregistered) in reply to adiener
    adiener:
    This isn't about personal preference, it's about software quality and ease of maintenance. Those things are objectively measurable (assuming a reasonable working definition of "quality"). Trivializing it as if it's personal preference only buries the problem deeper and perpetuates an attitude of indifference toward something with real detrimental impact. Yes, in the strictest of terms, comments have no direct effect on the quality of software after it's compiled, but their indirect effect is only one step removed from it. The philosophy of "if it does what it's supposed to when it compiles, it's good code" really isn't applicable in many situations these days.

    I have a bag of crap I would like to try to sell. Sounds like you might be a good salesperson!

  • (cs) in reply to Eli
    Eli:
    OK, smartypants, what do you suggest for a neuter singular pronoun in English? "He" is sexist and "he/she" is just awful.
    It.

    "It puts the bottle in the basket."

  • adiener (unregistered) in reply to nd
    nd:
    I have a bag of crap I would like to try to sell. Sounds like you might be a good salesperson!
    It appears as though you're out of actual argument substance, and have reverted to insinuating personal attacks. Well done.
  • Nodody (unregistered) in reply to tinkerghost
    tinkerghost:
    I have to agree that I like ending functions/subroutines etc with 'end;// function functionName' If you have either long functions or subroutines that cross more than one screen, it's easy to scroll past the end/start and jump into the next function. Sometimes it's easy to tell you did it, sometimes it's not, but putting the function name at the end of the function certainly makes it clear when you've managed to skip from one to the other.
    Which is why you should break the code up into shorter methods. Short methods are easier to read. Long methods are a code smell which should indicate to you that it is time to think about refactoring.
    tinkerghost:
    On the other hand, I've seen too many bits of scripting where the psuedo-code and the code had very little in common.
    Bingo. This is one of many reasons why self-documenting code is infinitely superior to commented code.
  • Anon (unregistered) in reply to nd
    nd:
    Its like arguing over what kind of writing utensil that someone uses to take notes and arguing that anyone who uses a pen instead of a pencil is wrong.

    Pen or pencil I don't have a problem with. But mechanical pencils? Those are just wrong.

  • (cs) in reply to SatanClaus
    SatanClaus:
    Self documenting code is often self documenting, but it is simply true that for every 5 SLOC, there should be atleast one comment.

    I've had code reviewers who mistakenly think like this. It makes for a hellish review process and even worse code. There should be at least one comment everywhere one is necessary.

    Comment data, not code. If it's written worth a shit, it should be obvious what is happening and so you only have to explain what it's happening to. And if the code isn't well written enough to be obvious, then the review should catch that anyway.

    Oh, BTW: "a lot" is two words. Not to be pedantic, just a pet peeve.

  • (cs)

    Intent.

    Intent.

    Intent.

    Go and read chapter 19 of Code Complete. The most common difficulty that developers report when approaching an unfamiliar code base is figuring out the original developer's intent. That's what the comments should say.

    This is a great WTF. The comments precisely echo what the code is doing. But, as others have pointed out, there appear to be bugs with the algorithm itself. Others have been debating about what the code ought to be doing, but because we do not know the intent, we cannot be certain.

    And to those who write comments first, then code between -- that's a valid approach, but only if you start at a slightly higher abstraction level (e.g., "Retrieve the message if in range"). If your code ends up looking like the code here, you've wasted time coding in English.

  • (cs) in reply to Code Dependent
    Code Dependent:
    Eli:
    OK, smartypants, what do you suggest for a neuter singular pronoun in English? "He" is sexist and "he/she" is just awful.
    It.

    "It puts the bottle in the basket."

    "Or else it gets the hose again."

    Nice "Silence of the Lambs" reference.

  • Franz Kafka (unregistered) in reply to JamesQMurphy
    JamesQMurphy:
    Code Dependent:
    Eli:
    OK, smartypants, what do you suggest for a neuter singular pronoun in English? "He" is sexist and "he/she" is just awful.
    It.

    "It puts the bottle in the basket."

    "Or else it gets the hose again."

    Nice "Silence of the Lambs" reference.

    Personally, I read it in a Cartman voice.

  • (cs) in reply to Franz Kafka
    Franz Kafka:
    JamesQMurphy:
    Code Dependent:
    Eli:
    OK, smartypants, what do you suggest for a neuter singular pronoun in English? "He" is sexist and "he/she" is just awful.
    It.

    "It puts the bottle in the basket."

    "Or else it gets the hose again."

    Nice "Silence of the Lambs" reference.

    Personally, I read it in a Cartman voice.

    I heard it in a Stewie Griffin voice.

  • Laie Techie (unregistered) in reply to Crash Magnet
    Doubtless you meant to say "postdecessors".
    How `bout successors?
    Doesn't that imply some sort of success???
  • Scott (unregistered) in reply to Eli
    Eli:
    OK, smartypants, what do you suggest for a neuter singular pronoun in English? "He" is sexist and "he/she" is just awful.

    Sigh. The issue is not choice of neuter singular third-person pronoun, but of changing that pronoun mid-sentence. The sentence in question was: "Often, the way one learns to do something is the way they keep doing it..."

    It should have been "Often, the way one learns to do something is the way one keeps doing it..."

    I have no problem with the use of "they" as long as it's used consistently and correctly.

  • Steve (unregistered) in reply to Jimbobzo

    ^^^^^

    That

  • Buffled (unregistered) in reply to bored
    bored:
    !WTF.

    More comments the better, even if they are "obvious" ones.

    You're an idiot. When comments are not telling you anything immediately apparent from reading the code, theyre just noise. Not to mentioned requiring double the maint work: rev1: // declare X as int and and init to 1 int x = 1;

    rev2: // declare X as int and and init to 1 int x = 10;

  • Robert S. Robbins (unregistered)

    These comments are for the benefit of future code archeologists who may not be fluent in ancient programming languages. They will probably have nothing to go on except for a Rosetta Stone in which someone carved the same progam in COBOL, C#, and PHP.

  • Buffled (unregistered) in reply to Eli
    Eli:
    OK, smartypants, what do you suggest for a neuter singular pronoun in English? "He" is sexist and "he/she" is just awful.

    Singular "they" is clearly going to continue to grow in usage until old farts like you accept it as valid :)

    a) stop using the assumption that "he" is sexist. b) alternate between "he" and "she" if it really bothers you, switching per paragraph or per section c) s/he works if you're really uptight.

  • Crash Magnet (unregistered) in reply to Code Dependent
    Code Dependent:
    J:
    Code Dependent:
    Doubtless you meant to say "postdecessors".
    Otherwise known as successors.
    Okay, you array of posters all saying the same thing about "successors": that is mere pedantry. "Postdecessors" is humor. I was hoping I wouldn't have to point this out, but... (sigh).

    Yea, unfortunatly I got the joke after I pushed the submit button. I always have "ah-ha" momements after I push the send button. I just know that after I push the submit button to this thread I'll get one of those, "Gee, that was stupid" impressions.

  • (cs) in reply to Franz Kafka
    Franz Kafka:
    No, I do the same thing - use comments to delineate sections of a large (50-60 line) method. It's handy to be able to call out the large scale logic.
    I used to do that a long time ago, but when I had to go back and maintain that code, I realized that the comments did not add much more than a simple newline would have added.

    What would have made a difference was more, smaller routines. Obviously there is no hard rule, but a 50-60 line method is probably trying to do too many things. It's rare that you would be unable to split it up into functional parts, and if you are in fact unable, then you're going to be in real trouble when you have to change the semantics of that routine.

    If the code is difficult to understand, refactor, don't comment. Assume that maintenance programmers are intimately familiar with the language/environment and reasonably familiar with the domain. Write comments to explain aspects of the code that can't actually be expressed with code.

  • (cs) in reply to Eli
    Eli:
    OK, smartypants, what do you suggest for a neuter singular pronoun in English? "He" is sexist and "he/she" is just awful.

    Singular "they" is clearly going to continue to grow in usage until old farts like you accept it as valid :)

    I'm not even going to argue with that, since you're not objecting to my comment — you're objecting to the inaccurate image of my comment that you formed in your mind when you read it wrong.

    Read my comment again, slowly, and try to understand it. Then we can argue about it if you like.

  • rumpelstiltskin (unregistered) in reply to MrsPost
    MrsPost:
    Personally I comment my code for purely selfish reasons. I don't know why I did things the way I did when I go back over it months later. I've worked on too many things between the time I wrote it and the time I need to modify it to remember much of anything.

    That is precisely why I don't comment my code. I enjoy coming back to a program a couple of months later, looking at it in bewilderment, and finally realizing "Damn, you are clever!" when the light comes back on.

  • (cs)
    'Make sure the messageID is within the proper range.
      If (intMessageID > 0) AND (intMessageID < 8) Then
                                   
    'Get text for messages from DB.
    msgSQL = "SELECT MessageText FROM Messages WHERE MessageID BETWEEN 1 AND 7"
    

    Strange that the programmer would first use (> 0 and < 8) and then use (between 1 and 7). Kind of a nitpick I guess, but it seems sloppy to me.

  • (cs) in reply to Mr B
    Mr B:
    Tris:
    InsanityCubed:
    That's when you went into your version control software, rolled back to the baseline with the "TODO" comments and emailed your manager about the change?

    Don't be silly - i laughed in his face and handed my notice in.... :D

    So you weren't using version control, nor did you make a note of what was left to do when you were told to remove the TODO notes from the code?

    I'd have resigned at that point too, in order to cover up my incompetence.

    I've never really been bothered about abundant commenting that doesn't add useful information, myself; neither do I really care about unfulfilled TODOs, whether or not they're four years old and/or the original developer has left. So what? TODO should be semantically equivalent to YAGNI. I've got one in my code right now, where I test an input against a regexp but can't be bothered to test the output.

    (Well, actually, it's in Perl, so I found it best to use die(), but the principle is the same.)

    What I really hate is FIXMEs where the code has (quite possibly) been fixed, but there's no source control and hence no way of knowing. This is one of those epic brain-teasers that tends to take around four or five hours of concentrated effort in order to reach a frustratingly indeterminate conclusion. People who do this should, indeed, be "fixed."

    Mind you, I've been guilty of it often enough in the past.

  • (cs) in reply to Code Dependent
    Code Dependent:
    Eli:
    OK, smartypants, what do you suggest for a neuter singular pronoun in English? "He" is sexist and "he/she" is just awful.
    It.

    "It puts the bottle in the basket."

    Man.

    "Man put de lime in de coconut."

    This works well both in German and in Ebonics. I should have thought that Congress would therefore be leaping at the chance to make it mandatory in Yanklish.

  • Scriptease (unregistered) in reply to rofl
    rofl:
    whoever:
    Well, it's better than some of the comments in the xt:Commerce Source:

    create_account.php:201: //don't know why, but this happens sometimes and new user becomes admin

    Thanx, had a good time searching for "don't know why" in Google Code Search!

    http://www.google.com/codesearch?q=don%27t+know+why&hl=en&btnG=Search+Code

    or

    http://www.google.com/codesearch?hl=en&lr=&q=%22don%27t+know+why%22&sbtn=Search

    Made my day :D

  • Anonymous Coward (unregistered) in reply to Whoevar
    Whoevar:
    I often start commenting a method/function/whatever and list the steps that need to be implemented. It may look like this:
    public void doWhatIsNeeded {
      // Step 1: connect
      // Step 2: request data X
      // Step 3: for each X do Y
      // Step 4: finish, clean up
    }
    

    The code inbetween the comments could even be only one method call. The comments usually stay there. Would this be a bad habit?

    No. It shows that you are have been thinking about the process before you have begun writing it. I always find english easier to read than code (concepts over actions), and having a set of simple flow comments can greatly help get the gist of a routine/process across.

    Of course, it doesn't mean that the code is good, but I'd consider it a good signal.

  • (cs) in reply to Julia
    Julia:
    This sounds like something out of a shop I used to work at. To check a file into source control, you first had to run a home-grown automated code checker. This rigorously enforced a rule governing the proportion of comment lines to source lines. You ended up having to do this simply to fill your quota of comments. (Putting silly comments in pointing out the banality of the system was a good way to get disciplined)

    It might have been appropriate in the origins of the company in the sixties, writing really low level stuff, but it was moronic not to change the rules for well-structured object-oriented code.

    Disciplined? I call shenanigans, unless you have photographic proof.

    Of course, if your first name is "Raul," then I retract the shenanigans.

  • (cs) in reply to J
    J:
    Code Dependent:
    Josh:
    Of course, as an engineer, I fully expect half the code I've ever written to be posted here by one of my computer science predecessors, though.
    Doubtless you meant to say "postdecessors".

    Otherwise known as successors.

    What The Successor?

  • Tombo (unregistered)

    Heh. I think people are so bewildered to see any form of comments, they can't help themselves but defend it. I'm in the process of porting a Delphi web site into C# with no functional documents. The old code base has maybe 20 comments in the 150K or so lines. The majority of the functionality requires disperse circumstances to be met, otherwise it's not shown on the browser.

    It takes much longer for me to compile the code in my head than it would to read a line describing what the function is for. It sucks, but I guess no one is arguing against commenting code in a useful manner.

    Also, obvious comments like the example would be useful when a new developer is inheriting the project in a language that he's never used before. That typically happens when an old product is still selling and the original developers got the hell outta Dodge, as did the people who took it over, and the ones who took it over from them, etc. We have some apps written in MUMPS. That language is hideous. I'd be happy to have comments telling me what the hell @()#*$)*D() means (PC Load Letter, WTF does that mean?). I'm sure it was obvious to the dinosaur who wrote it 20 years ago.

    Anyway, yea the comments in the example are pretty useless, but after working on this port, it's nice to see at least something, useless or not. Maybe I just like the color green.

  • (cs) in reply to Josh
    Josh:
    I find it's easier to open a blank program
    If it's blank, it's not a program. Unless you're thinking of the shortest self-replicating program possible.
  • Mr.'; Drop Database -- (unregistered) in reply to Ken B
    Ken B:
    //TODO: Remove this comment
    //TODO: Remove
  • (cs)

    This nicely illustrates why the site shouldn't have been politely renamed. I mean, this plainly isn't a WTF of the original variety, and it's not WTF in the granny-friendly sense. It is, however, a WTF, with a "why" rather than a "hwaet".

  • (cs) in reply to rofl
    rofl:
    http://www.google.com/codesearch?q=don%27t+know+why&hl=en&btnG=Search+Code

    or

    http://www.google.com/codesearch?hl=en&lr=&q=%22don%27t+know+why%22&sbtn=Search

    http://www.google.com/codesearch?hl=en&lr=&q=%22oh+crap%22&sbtn=Search
  • no one (unregistered)

    I'd rather this than no comments. At least you know the code is doing what they though it was !

  • BT (unregistered) in reply to UriGagarin

    Bingo!

  • BT (unregistered) in reply to BT
    BT:
    Bingo!
    Dang, forgot to quote the one that got it right.
  • Franz Kafka (unregistered) in reply to Aaron
    Aaron:
    Franz Kafka:
    No, I do the same thing - use comments to delineate sections of a large (50-60 line) method. It's handy to be able to call out the large scale logic.
    I used to do that a long time ago, but when I had to go back and maintain that code, I realized that the comments did not add much more than a simple newline would have added.

    What would have made a difference was more, smaller routines. Obviously there is no hard rule, but a 50-60 line method is probably trying to do too many things. It's rare that you would be unable to split it up into functional parts, and if you are in fact unable, then you're going to be in real trouble when you have to change the semantics of that routine.

    If the code is difficult to understand, refactor, don't comment. Assume that maintenance programmers are intimately familiar with the language/environment and reasonably familiar with the domain. Write comments to explain aspects of the code that can't actually be expressed with code.

    A 50-60 line function is fine if it's 3 delineated sections of 1: boilerplate to load up some data from some irritating APIs, 2: some logic to validate that the data matches what we expect and 3: a bit of cleanup code. This includes variable declarations and whitespace. It doesn't make sense to make a new method with a bunch of parms or pass data around via instance variables when all you're doing is loading up some data.

    I also write long methods when it's something like a switching method: get message and for each type we support, unpack, do minimal validation, repack, return. This is 10-15 lines per type, but it's highly regular, and any given call only hits about 15-25 lines.

  • (cs) in reply to Mr.'; Drop Database --
    Mr.'; Drop Database --:
    Ken B:
    //TODO: Remove this comment
    //TODO: Remove
    I see what you did there. :)
  • Steve Taylor (unregistered)

    In defense of overcommenting - I often sketch out what I intend to do in the form of a few comments, and then fill in the code later. They serve as a To Do list of sorts.

    As evil things go, it's better than being mean to puppies and kittens.

  • Guy Smiley (unregistered)

    I once worked at a company where we were required to add a comment for every line of code. This was an incredibly well thought out and implemented plan, especially when we had code like:

    if ptr /= null then

    or

    for i in 1..MAX_MESSAGES loop

    We ended up writing another program that would look for uncommented lines and add an appropriate comment, such as "if ptr is not equal to null" or "for 1 to MAX_MESSAGES times".

  • paulains (unregistered)

    Hey guys guess what, if you highlight the text you can see the number

  • Franz Kafka (unregistered) in reply to Steve Taylor
    Steve Taylor:
    In defense of overcommenting - I often sketch out what I intend to do in the form of a few comments, and then fill in the code later. They serve as a To Do list of sorts.

    As evil things go, it's better than being mean to puppies and kittens.

    I do one further - sketch the logic in english in the function body - no comments. That way, it won't even compile if I forget something. As I write, I preserve some of it as comments. This is only for code complex enough that I have to think - boilerplate code gets two sentences at the top of the method saying what the next 100 lines are for (mostly repeating the same pattern 5 times with different types).

  • (cs) in reply to ClutchDude

    This can be worse though

    //make sure message is out of test range (greater than 100)
    if(msg.id < 100)
    {
    ...
    

    ARGGG! Which is correct? The comment or the code?

  • QCumber (unregistered)

    That's not bad at all - quite the contrary: By introducing reduncancy you get a certain amount of error checking.

    For a code reader not too familiar with the code and/or the language, the "redundant" comments can be a help to get a rough picture fast.

    When examining the code, mismatches will get noticed - and there's always a very fair chance that it's the code that is wrong. With the coment redundancy, this might have gone unnoticed much more easily.

  • Matt (unregistered) in reply to JamesQMurphy
    JamesQMurphy:
    Franz Kafka:
    JamesQMurphy:
    Code Dependent:
    Eli:
    OK, smartypants, what do you suggest for a neuter singular pronoun in English? "He" is sexist and "he/she" is just awful.
    It.

    "It puts the bottle in the basket."

    "Or else it gets the hose again."

    Nice "Silence of the Lambs" reference.

    Personally, I read it in a Cartman voice.

    I heard it in a Stewie Griffin voice.

    [image]
  • sum yun gai (unregistered) in reply to Americium
    Americium:
    Anonymous:
    Indeed, this is a common one. Some people just have to document self-documenting code.

    // If the object is null throw a new NullReferenceException if (object is null) throw new NullReferenceException();

    Why? Why would anyone explicitly create a NullReferenceException()? Any code that dereferences a null pointer has a programmer's error. Fix the code!

    Perhaps he meant
    if (object is null) throw new ArgumentNullException();
    which is useful for validating parameters in library methods

  • anon (unregistered)

    the original poster's a fucking idiot. You want to walk a mile in my shoes and you'll soon realise what the real what the fuck is - people like you.

  • Anonymous (unregistered) in reply to Jimbobzo
    Jimbobzo:
    The problem I have with too many comments is that people change the code, but they dont update the comments,. This leads to comments saying one thing, with code doing another, and actually hindering your code.

    I don't buy this argument. For sake of argument, replace the word "comments" with the word "documentation". Even though future maintainers may fail to keep documentation up to date, it should still be written, in my opinion.

    Generally speaking, most code should be readable and understandable without comments.

    Readable and understandable aren't binary flags, and coders vary in strength and domain-specific knowledge. At some point descriptive method and variable names have to give way to brevity, and one's familiarity with the frequently-used abbreviations for a given project can have a big impact on how long it takes one to understand a chunk of code. Furthermore, the coders assigned to do maintenance in the future may not be as strong as those who wrote it. For both reasons, it makes a lot of sense to throw future coders a bone, even if it seems unnecessary at the time.

    That said, there are other factors. Comments are time, and time is money, so it only makes sense to add comments if the expenditure for doing so seems to be less than maintenance costs they save. Ideally, a time value of money would also be factored in, but there probably isn't a good metric for such factors anyway. As such, it remains a seat of the pants decision.

    In some respects, the level of commenting that is appropriate depends on the application. For more business-oriented logic--particularly in a one-off application or customization--I think there is reason for more rather than fewer comments. There, it probably pays for the code to include the terminology familiar to the business users, and the preferred terminology can be insular and non-standard. This is also a domain where it may be easier for weak developers to hang on, which has the potential to place easy maintenance at a premium.

  • jiggster (unregistered) in reply to Code Dependent
    Code Dependent:
    Josh:
    Of course, as an engineer, I fully expect half the code I've ever written to be posted here by one of my computer science predecessors, though.
    Doubtless you meant to say "postdecessors".

    successor? successor to the professor!?

  • Adrian Pavone (unregistered) in reply to Code Dependent
    Code Dependent:
    Eli:
    OK, smartypants, what do you suggest for a neuter singular pronoun in English? "He" is sexist and "he/she" is just awful.
    It.

    "It puts the bottle in the basket."

    "It puts the lotion on it's skin"?

Leave a comment on “The How, Not the Why”

Log In or post as a guest

Replying to comment #:

« Return to Article