Slashdot Mirror


Successful Strategies for Commenting Your Code

LilG writes "Over at Particletree, Ryan Campbell writes about Successful Strategies for Commenting Your Code. His essay gives advice and examples on proper commenting, and details some different strategies."

62 of 500 comments (clear)

  1. Huh? by tntguy · · Score: 5, Funny

    These comments you speak of, they seem foreign and strange to me.

    1. Re:Huh? by bluelip · · Score: 3, Funny

      "The code was hard to write. The code should be hard to read."

      Was that some form of early DMCA or IP lockdown?

      --

      Yep, I never spell check.
      More incorrect spellings can be found he
    2. Re:Huh? by TommydCat · · Score: 2, Funny

      /* Please phrase your reply in the form of a comment. */ /* Thank you */

      --
      This comment does not necessarily represent the views and opinions of the author.
    3. Re:Huh? by torpor · · Score: 2, Funny

      /*
        * slashdot comment comment
        * 1.0.0 - torpor - init.
          */

      #pragma KARMA_HACK // technically, also a comment. /* comments are fun. */ //code goes here..

      --
      ; -- the corruption of government starts with its secrets. a truly free people keep no secrets. --
    4. Re:Huh? by MHobbit · · Score: 4, Funny

      A TRUE Klingon warrior does not comment his code!

      *ducks*

      --
      Debugging? Klingons do not debug. Bugs are good for building character in the user.
    5. Re:Huh? by Kehvarl · · Score: 2, Funny

      *ducks*

      A true Klingon warrior does not duck.

      A true Klingon warrior would have nothing to do with such a weak waterfowl.

    6. Re:Huh? by not-enough-info · · Score: 2, Funny

      The user catalog is a perl database and we need to localize for how many countries? Then, today is a good day to die!

      --
      ---k--
      </stupid>
    7. Re:Huh? by hhlost · · Score: 2, Funny

      // TODO: add comments

  2. My favorite code comment not written by me by dcarey · · Score: 4, Funny

    I was doing some maintenance on someone else's code and came across this nasty set of like 8 nested if/elses. It was a bloody horrible hack. But the best part of all was the comment right at the top: /* Oh, fuck */

    --

    -- (Score:i , Imaginary)

    1. Re:My favorite code comment not written by me by lukewarmfusion · · Score: 4, Funny

      So you found that, eh? *evil chuckle*

      I was in a similar spot a month or two ago and found some other company's comments - unhelpful as always - in the form of typed out sound effects.

      # This function goes vroooooooommm-pop!

      I have no idea why the developers put such comments there other than to entertain themselves as they sifted through their horribly written Perl.

    2. Re:My favorite code comment not written by me by Abcd1234 · · Score: 4, Interesting

      Well, there's nothing wrong with entertaining comments, as long as that's not *all* you have. In my experience, useful comments interspersed with a bit of humour can make code analysis and maintenence at least a little less boring.

  3. Gotta say it by modi123 · · Score: 2, Funny

    /* no */

  4. Example by dduardo · · Score: 3, Funny

    /*This loop starts at x is equal to 1 and continues while x is less then 5. x is incremented by 1 each time.*/ for( int x=1; x5; x++ ) { printf("Hello World\n");/*Prints "Hello World"*/ }

  5. var names by rockytriton · · Score: 3, Insightful

    My best strategy is intelligent variable names and clean simple code. -- http://www.dreamsyssoft.com

  6. Practice what you preach by ChrisF79 · · Score: 5, Funny

    I viewed the source on the site and nothing was commented :)

    --
    Finance tutorials and more! Understandfinance
  7. Comments are more important than Code? by jetkust · · Score: 4, Funny

    Comments are more important than Code?

    I once tried writing code that was completely made up of comments. It was easy to write and all, but didn't work very well.

    1. Re:Comments are more important than Code? by NialScorva · · Score: 4, Funny

      At least you had no compile errors or core dumps, and I bet you didn't have any exploitable vulnerabilities either.

    2. Re:Comments are more important than Code? by Not_Wiggins · · Score: 4, Interesting

      Actually, I start my programming projects by writing all the comments first; in this way, I get the pseudo-code ideas down and write the associated code under each comment. It helps me track where I am in a class/function, what I'm trying to accomplish (what parts still need to be written), and it nicely leaves an understandable trail without having to back-fill the code with comments once the project is "done."

      By front-loading the process with comments, I find it really helps not just the maintainability but it also keeps my programming tasks on track.

      --
      Diplomacy is the art of saying, "Nice doggie!" until you can find a rock.
  8. Don't comment by i.r.id10t · · Score: 5, Funny

    Don't comment at all, and just run it thru The Commentator!

    http://www.cenqua.com/commentator/

    --
    Don't blame me, I voted for Kodos
  9. I was skeptical at first regarding the topic by Anonymous Coward · · Score: 5, Insightful

    But when reading the article I was glad that the very first item was SELF DESCRIBING CODE. The most important part of code documentation is the code iteself IMHO.

    I think it was Fowler who once went as far as to state that when you find yourself needing to document code in order for it to be understood (vs. thoroughness, completness, or document generation) you probably need to refactor your code.

    How many times have we come across code like this?

    public void bigFunction1()...

    public void bigFunction2()...

    1. Re:I was skeptical at first regarding the topic by lgw · · Score: 2, Insightful

      Self describing code is great for explaining what the algorithm is, but sometimes it's just not going to be clear how a function fits into the big picture (because the problem you're solving is a mess), and sometimes you need a clever algorithm that solves the problem in a non-obvious way. The mapping of code to algorithm may be self-describing, but that doesn't mean the mapping of algorithm to problem space is (or that it can be made so - in many cases it's the problem being solved that needs the all the documentation it can get).

      --
      Socialism: a lie told by totalitarians and believed by fools.
  10. Commenting by Hamster+Of+Death · · Score: 4, Insightful

    Write the comments first, then add the code. That way you'll get a better grasp on the problem you're solving. If your comments don't explain the problem or someone else can't solve the problem using your comments then you'll probably need to rethink your approach.
    And for crying out loud update the comments when you change code!
    *grumbles about 10 year old code and 15 year old comments*

    1. Re:Commenting by bmwm3nut · · Score: 3, Insightful

      exactly! in fact, this was taught to me by a senior programmer who said: "you should never document your code, your should code your document." in projects where i've followed that rule, i've had many fewer problems than ones where i jumped into the code quickly.

    2. Re:Commenting by truckaxle · · Score: 2, Insightful

      Oh hey I have maintained code written with this technique

      Sure and when you get around to actually writing your code and you find out that it doesn't quite work as easily as you thought it should and you deviate from your comments then rarely does the comments get updated. After a few rounds of revision and testing the comments are a mere artifact and document how you original thought it should work.

  11. really being stressed in schools by StarvingSE · · Score: 3, Informative

    The next generation of professional coders will most likely be good commenters as well. I know from experience in my computer science classes, professors will mark programming assignments down significantly if comments are not included, or if they are hard to read. Most of the time they want all functions to be commented to explain what their parameters mean, how the function works, and the format of the output.

    --
    I got nothin'
    1. Re:really being stressed in schools by j-tull · · Score: 2, Informative

      As one who has graded many undergraduate programming assignments I can tell you that professors very seldom actually read, let alone provide feedback on, comments. Comments on assignments tend to be scored as, "Are they there? If yes, good! If not, -10 pts for being a dumb ass."

      Summary: Though the next generation of coders may be more diligent about including comments (at least initially -- though I'm not sure I'm even convinced on this point), there is nothing that leads me to believe the content and appropriateness of their comments will be any better than what we see today.

  12. No by rbarreira · · Score: 5, Funny

    No, that first one should be something like:

    This loop starts at 1, and to 5 it counts. It doesn't count to 6, nor it does count to 8. It does not count to 3 or 4, except in passage to 5. When it reaches number 5, the fifth number...

    --

    The AACS key is NOT 0xF606EEFD628B1CA427BEA93A9CA9773F
    1. Re:No by lboxman · · Score: 2, Funny

      That's only appropriate if you're documenting python code...

      --
      Regexes are like cocaine. The first hit is pretty good, but afterwards you try to use them to solve all your problems.
    2. Re:No by legirons · · Score: 3, Funny
      Not in the real world... more like:
      //----------
      // ReadSalaryData - reads table of salary values from database
      // Parameters:
      // - DB, database handle
      // - Data, pointer to list
      // Returns: Success
      //---------
      void DeleteUsername(char *Name)
      {
      ...
  13. What's So Hard About Comments... by __aaclcg7560 · · Score: 2, Interesting

    When I was learning Java in college, the instructor would give your failing grade if you don't have comments and the HTML output of the javadoc utility. The C++ instructors, on the other hand, only wanted your name, class and date in the comments. You would think that all programmers would comment their code.

  14. A comment on comments by Jeffrey+Baker · · Score: 5, Insightful
    Dear Doxygen and JavaDoc users,

    The following is an example of useless documentation:

    frobWoggleFfloofMoing

    public void frobWoggleFfloofMoing(String, String, String)

    Frobs the Woggle

    ...

    You see, running Doxygen over your header files may produce some output in HTML format, but it doesn't produce what I like to call "documentation." For instance, documentation would explain what is a Woggle, and when should it be Frobbed?

    Thank you, and have a nice life.

  15. My commenting habits by TildeMan · · Score: 2, Interesting

    I know the value of comments, so I always try to use them except in the smallest of personal utility programs. But I don't comment as I'm writing code. Instead, I write significant chunks of code, then go back and comment each piece of the chunk. In doing so, I have to think, "Okay, what is this code supposed to do?" and in the process, since I hadn't just finished writing the code, I tend to catch more typos and bugs. Seriously, I've saved myself a lot of time debugging by commenting this way.

  16. Why I comment code... by Saeed+al-Sahaf · · Score: 4, Interesting

    I don't know why people (in general) don't like to comment code. I comment mostly for me, so a year or two down the line I'll know why I did something (I've found over the years of writing code, I may think I'll remember, but that often does not end up the case). In the end this selfish purpose ends up helping when other people need to maintain my code (other people fucking around with my code? Never).

    --
    "Who are in control, they are not in control of anything - they don't even control themselves!" - Glen Beck
  17. Things to always remember when commenting by WillAffleckUW · · Score: 4, Funny

    1. Never spelchezk.
    2. Use randomly chosen variable names, or objects that resemble your favorite Orcs and Trolls from LotR - after all, everyone knows that a Lothlorien object will have farseeing ability, so it's obvious.
    3. When instantiating something for the first time, never explain it - real programmers read the original object source.
    4. If you do something complex, write a short pithy comment like /* magic occurs */
    5. If you do something easy but you were drinking too much hot cocoa, write a long verbose description, and also mention how good the hot cocoa was.
    6. Always include song lyrics to what you're listening to while you wrote the code.
    7. Object inheritence means never having to explain the code.
    8. Repetition is the best way to reinforce obvious things - so repeat the obvious thing since it's the best way to reinforce it.
    9. If you break up with your girl/boyfriend, write about it in the comments - people really want to know.
    10. If you're updating or modifying code, write your opinion about the original code in the comments. Use nasty words if you can.

    --
    -- Tigger warning: This post may contain tiggers! --
    1. Re:Things to always remember when commenting by Reverend528 · · Score: 2, Funny
      haikus or other poems are also useful comments:

      // nested switch statments
      // with some inefficient code
      // and memory leaks

  18. All Depends... by eno2001 · · Score: 3, Funny
    ...on who is going to be reading the code after you are gone. Sadly, due to differing levels of expertise, there is no optimum method of commenting code. For some, this is a very useful comment (I'm using pound sign comment designation as an example):

    # The main function starts here

    or...

    # This is a loop and it will run while a certain
    # condition exists.

    or...

    # Don't forget to remove this section after
    # I'm gone - Dan - 04/25/1995

    Think about the children! ;P

    --
    -"...bad old ideas look confusingly fresh when they are packaged as technology" - Jaron Lanier (Digital Maoism on Edge.o
  19. How & Whys by Anonymous Coward · · Score: 4, Insightful

    It's been said before, but I find the best advice I've ever gotten on commenting code is very simple -

    Comment the why, not the how.

    Hopefully the code should be clear enough to pick out the how, but *why* you are doing something is never going to be apparent from the code itself - at best someone might be able to infer it, but that becomes especially tricky when time passes or a new person signs on.

  20. Re:indeed by CowboyBob500 · · Score: 2, Interesting

    I agree (I think) with you.

    Comments should be common sense and used where the developer thinks it is appropriate and where they will aid future developers/maintainers understand a particular block of code. Nothing more, nothing less. The article is just typical PHB management bullshit and I feel dumber after reading it.

    The scenario that is the ultimate end product to "comment standardisation" is what happened at a company that a friend of mine works for. They had a developer sit there for 3 days, go through the entire code base, and format the comments to the "company standard". No shit.

    Bob

  21. What makes a good Comment? by vivin · · Score: 4, Interesting

    Good comments should explain these areas:

    a) What you're doing.
    b) Why you're doing it.
    c) How you're doing it.

    I took three assembly programming classes in College. The last one was on the 68k, where we wrote an embedded OS.

    Assembly code isn't all that intuitive, and writing comments is especially important. Our professor allocated 20% of our grade on each lab to comments. In addition to accurately describing what we were doing, he checked our grammar. One thing he always stressed is that too many engineers these days don't know how to write comments. Grammar is important in getting the message across unambiguously.

    In general, if a person can read your comment and then figure out how to translate what you said into code, then your comment is pretty good. It should give an idea of what you're trying to do, why you're doing it, and how you're doing it.

    One of my professor's grad students translated a program from MACRO32 into C++, and all without even knowing MACRO32. He looked through the comments to figure out what they were doing. They were so specific that he could easily translate blocks of code over to C++.

    Comments are very important - and I should definitely comment MY code. I can't remember the number of times I've come back to code that I've written and thought "WTF am I doing here? WTF was I smoking when I wrote this?!"

    --
    Vivin Suresh Paliath
    http://vivin.net

    I like
    1. Re:What makes a good Comment? by mOdQuArK! · · Score: 5, Insightful
      You really should comment every line of assembly, even when you just increment a register,

      As long as you're commenting the _real_ effect of the instruction, and not just mindlessly repeating what the mnemonic already tells the reader. I've seen lots of stupid assembly-language comments like "increments the A register". Gee, thanks - I couldn't have figured that out from the "INC A" mnemonic.

    2. Re:What makes a good Comment? by lgw · · Score: 2, Insightful

      I couldn't agree more. Some people just need not to program.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    3. Re:What makes a good Comment? by Fujisawa+Sensei · · Score: 2, Interesting
      One thing he always stressed is that too many engineers these days don't know how to write comments.

      I call B.S. ALL Engineers KNOW how to write comments. If they don't know how to comment they're code they aren't an Engineer. In fact I will lay odds the 60% of the "Software Engineers" out there aren't really Engineers. Just because you have a degree in Computer Science doesn't make you an Engineer. I know plenty of "Software Engineers" who don't know what an ABET accredited engineering program is.

      All that aside, knowing how to write good comments, and actually taking the time to write the comments are 2 different matters entirely. In many cases by the time programmer gets around to coding they are frequently tired of documenting what they're doing. Because they're had to write Analysis Documents, Design Documents, and Test Plans. They code doesn't need documentation because "they've already documented the hell out of the project". And guess what, that code may be thrown away in 5 years or so anyway because there's a better way of doing things. Anybody maintaing EJB 1.0 or JSP 1.0 apps these days? (I know there are a few left, but those are the exception.)

      --
      If someone is passing you on the right, you are an asshole for driving in the wrong lane.
    4. Re:What makes a good Comment? by idontgno · · Score: 3, Informative
      As long as you're commenting the _real_ effect of the instruction, and not just mindlessly repeating what the mnemonic already tells the reader.

      Or worse yet, lying.

      One pre-paleolithic piece of mainframe assembler I (and my colleagues) once worked with was an intricate sequence of shift operations designed to isolate a 5-bit segment in the middle of a 36-bit word in one of the accumulators. It was documented with a breathtakingly detailed block of comments, complete with little pictures of the contents of the register at each step in the process (composed of dashes and vertical bars and everything--ASCII documentation art).

      The code wasn't working, but there was absolutely no way that it was the code's fault. It was just FM (F'ing Magic) that it was broke. We were convinced of this. That is, until one of my supervisors, a crusty old communications sergeant, actually studied the instruction string of the segement of code in question and noticed that in the last step, the actual answer was being shifted the wrong direction--right out of the register and into the bit bucket.

      If only we could have compiled the comments...

      This, then, is Johnson's Postulate on Documentation: "Read the source code, too."

      --
      Welcome to the Panopticon. Used to be a prison, now it's your home.
    5. Re:What makes a good Comment? by Zaiff+Urgulbunger · · Score: 2, Insightful

      Or worse yet, lying.

      Not specifically regarding assembler, but you've just reminded me of the thing I absolutely hate the most which is people taking a chunk of existing code, comments an' all, tweaking the code to do something similar but different, but not updating the comments. Any typically the people (they ain't programmers!) who do this also use the existing function name but suffix it with a "2" or something -- I mean, why bother with a meaningful name? Someone might be able to understand the code!!

    6. Re:What makes a good Comment? by lebow · · Score: 2, Informative
      Ok well there is sometimes a reason I've found to do this. I come in in the middle of a project where some one wrote a bunch of poorly designed functions, that don't take arguments ( data is passed through global vars ) and they produce a extremely specific result that should be more general. for example fetchdata() a highly specific function with a generic name. I want to write a real fetchdata() that is generic and I can use in other parts of the code but the good name is already taken, and I don't have the patience ( or time ) to go through and fix it every where in the whole project. ( I guess I could do a global search and replace but.. )

      So I make fetchdata2() ( or fetchdata_good() and use that from now on and when I can try to replace the old fetchdata()s to use the better version.

  22. Re:Don't do it! by treerex · · Score: 2, Insightful

    Don't EVER comment your code if you work for a company. That's a sure fire way to lose your job! If you don't comment your code then you are the only person who can understand it, making you indispensible.

    Great idea! The myth of indispensibility is a great reason. May your next job be as a maintenance programmer in a Perl shop where the previous "indispensible" developer had his ass fired for threatening the boss and you get 50,000 lines of Perl dumped in your lap.

  23. My take by lawpoop · · Score: 2, Interesting
    I'm a self-taught PHP hacker. I've fooled around with VB for MS Access and I hate it -- way too crufty with ADO and DAO, but I digress...

    Anyway, this is the strategy I've come up with after having to go over my old code.

    • Every 'flow control' statement (if, while, else, etc) gets a comment in plain English about what conditions it's checking for.
    • Every logical block of code gets a 'mission statement' saying what large-scale, abstract task about what they are supposed to accomplish. When I say 'logical block', I'm not talking about something the computer will understand, but an abstract grouping of lines of code meant to accomplish a high-level task.
    • For some obscure functions or arguments, they will get a comment at the end, just to help myself with parts of PHP that I'm not familiar with. This is just to keep me from looking up things, and other PHP hackers may not need this commentary to understand the code and its function.
    --
    Computers are useless. They can only give you answers.
    -- Pablo Picasso
  24. zerg by Lord+Omlette · · Score: 5, Insightful

    Ask someone else to look at your code. Every time they pause while scrolling, touch their chin, squint their eyes, furrow their brows, etc., it means you need a comment.

    --
    [o]_O
  25. Next on his list of things to write about by deblau · · Score: 2, Funny

    Successful Strategies for Crashing Your Website

    --
    This post expresses my opinion, not that of my employer. And yes, IAAL.
  26. Re:Don't do it! by 1nt3lx · · Score: 3, Informative

    This works quite well, but there are some consequences for this action:

    1. You are likely to be passed by on promotions because self inflicted developer dependence for this application.
    2. You will have to figure it out later, after you've forgotten what all that magic gobly-gook does.

    magic gobly-gook: effective, efficient, and incredibly dense code produced wilst 'in the zone'

  27. Literate Programming by bsd4me · · Score: 2, Interesting
    --

    (S(SKK)(SKK))(S(SKK)(SKK))

  28. Obfucksucated code contest by jurt1235 · · Score: 2, Funny

    This kind of reviews are really destructive for my goal of winning the obfuscated code contest (http://www.ioccc.org/ can not read any further.

    --

    My wife's sketchblog Blob[p]: Gastrono-me
  29. Comments: Why, Sometimes What, Never How by Bob9113 · · Score: 2, Interesting

    Three rules of thumb that work fairly well:

    1. Use comments liberally to explain why. Why would I want to call this method? Why did you choose this particular algorithm? Why are you ignoring this exception? Source code has very little support for explaining why without comments - and why is often both the most important point and the most easily forgotten.

    2. Use comments occasionally to explain what. Your method names, parameter names, and logic should strive to be clear enough that explaining what is happening is unnecessary. But that is in a perfect world. If you can't make it clear in a reasonable amount of time, add a comment explaining what is happening.

    3. Never use comments to explain how. The real how diverges from the comment too quickly. If someone needs to see how, they should look at the source code, which is the only reliable resource for explaining how.

    There are exceptions to all of these I'm sure, and this doesn't cover everything (for example, the above says nothing parameter definition comments or copyright comments), but they're decent rules of thumb for most cases.

  30. Re:indeed by B'Trey · · Score: 2, Informative

    There are two problems with this.

    The first is that common sense isn't. There are lots of coders who seem not to have any.

    Second, what seems clear and obvious when you're writing the code is anything but to someone else who's approaching the code fresh. That "someone else" may very well be you six months or a year down the road. Every function over one line (and most of those) should have a comment indicating what it does. Any variable that isn't a throwaway loop counter or similar should either be so clearly named that your grandmother could tell you what it's used for or be commented. Etc.

    It takes seconds or minutes to write comments. One comment can save you hours of time and loads of frustration. Common sense says to write the comments, even if you don't think you'll need them. You only need to be wrong once or twice to come out ahead.

    --

    "The legitimate powers of government extend only to such acts as are injurious to others." Thomas Jefferson.

  31. Re:Don't do it! by halber_mensch · · Score: 2, Interesting
    Great idea! The myth of indispensibility is a great reason. May your next job be as a maintenance programmer in a Perl shop where the previous "indispensible" developer had his ass fired for threatening the boss and you get 50,000 lines of Perl dumped in your lap.

    Indispensibility is what keeps your job when the company for which you have produced code is purchased explicitly for the ownership of said code and someone must know how to use it.

    I can speak from experience, having witnessed such a purchase firsthand. The entity which did the purchasing stated outright that in order to use the code they bought the company for, they would need to keep the select few coders that knew it intimately. The source and build processes had little to no commenting or documentation, so without the programmers, the source for the products was useless. Thus 2 coders that were heavily involved in those projects and 2 other employees in other departments were given the power to negotiate a salary and keep their jobs while the rest of the company got shitcanned. Had the code been well documented and the purchaser not needed its authors to interpret it, those people would have at best been given below average compensatory salary offerings at best, or more likely notices of immediate employment termination.

    In a perfect world, we'd all have well documented code. But unfortunately in the real capitalist faux-utopia that we live in, if you aren't necessary for the operation of your own code, you become worthless in comparison to it.

    --
    perl -e "eval pack(q{H*},join q{},qw{70 72696e74207061636b28717b482a7d2c717b343 637323635363534323533343430617d293b})"
  32. doxygen by Wescotte · · Score: 2, Informative

    You still need to know how to write good comments but I find using doxygen is a great tool for generating useful documentation directly from comments in your code. If you haven't heard of it give it a shot.

    http://www.stack.nl/~dimitri/doxygen/ Doxygen homepage.

  33. Flip the Script by Doc+Ruby · · Score: 2, Interesting

    The best basic strategy for commenting code is to flip the script: code your comments. Start writing the program by writing, in English (or your other human language in which you design programs), what the program will do. I start the file with a comment stating what the program will do, with any input and/or output to expect. Then I start writing complete sentences, punctuated, of the steps of processing. Wnen the action is obvious (already described in a comment), I sometimes label code with just a noun clarifying what its operating on. When I've got the comments written, I add code to each section, telling the computer how to do what I said it would in the comment.

    This discipline is tied to my code layout style. I put braces ('{' and '}') each on their own line, in languages which use them to delimit blocks of code (most of the languages I use). After the opening brace, I put a single space, then a comment, like:

    # Use list if it has items.
    if($numEntries = $#list)
    { # Get personal info from people in the list.

    Then I indent the block with 4 spaces, starting with a comment, like:
            # Use local storage.
            my(@names, @addresses, @jobTitles, $name, $address, $jobTitle);

    Loops get described as a single operation, but their block describes each iteration's operation:
            # Get columns into separate lists.
            foreach $row (@list)
            { # Add fields to their columns.
                    # Get fields from row.
                    ($name, $address, $jobTitle) =
                            ($row =~ /^(.+)\s+(.+)\s+(.+)$/);

                    # Store fields in their columns.
                    push(@names, $name);
                    push(@addresses, $address);
                    push(@jobTitles, $jobTitle);
            } # each row
    } # Used list of people.

    The comments, layout and variable names make it easy to understand what's happening. So easy that it's useful to read them first, then write the code :). While this clarity is useful when collaborating with other people, it's useful to consider that you are different when time passes. So reading your own code later is easier. Even if it's Perl, and you're cramming lots of "elegance" into some data structures and regexps - the comments can be clear.

    --

    --
    make install -not war

    1. Re:Flip the Script by William+Tanksley · · Score: 2, Interesting

      This was (is) standard in the project I worked for. They went a little further, and used a comment extractor to use the comments to generate the pseudocode, which was reviewed separately from the code. You had to turn in the formatted pseudocode at the end of the design phase.

      It wasn't terrible, but the result was a lot of comments that were echos of the code, and an unknowable amount of code that should have been broken out into discrete functions, but was instead kept nearby its comment because the comment made sense where it was. And don't forget the old code that had comments that no longer matched what the code did!!!

      All in all, I prefer the "code smells" approach to comments -- when you see a comment, think carefully about whether it's a good thing in itself, or whether it's actually being used to hide bad code. For an example of a question I might ask, with your comment "# Store fields in their columns", might it possibly be better to have a function named StoreFieldsInTheirColumns()?

      -Billy

  34. If you see bad code don't comment, refactor please by BlueYoshi · · Score: 2, Insightful

    OK, it s not always possible and/or desirable. If it is not broken don't fix it. When I see comment in code because the developer don't understand what happening in 8 level deep statement or in the little function of 10000 lines of code, please fix the code.

    there is basic rules to follow; not all exposed here it would be tooooo easy and me way too lazy :) :

    • Think before coding
    • good variable and function names
    • short function is desirable
    • don't do more than 4 level-deep statement
    • use javadoc for describing function and their parameters
    • Think before coding
    • use metrics to analyze code
    • use junit or other technique to have simple example of use of the code.
    • Think about the children^W maintainer
    • Think before coding (did I mention it?)

    Comments are there to

    • javadoc standard formal description for procedure paremeter,...
    • tell Why not How
    • explain code to avoid bugs in a library or third party code (if (UserAgent == NETSCAPE4) heightOfBox = heightOfBox * 10 /7) // to go around "feature" in netscape about the calculation of (...) see [browser bug workaround 3.2.5]
    • place inside method that need to be implemented or overrided
    • to explain very particular code for specific constraint like optimization or obscure technique but that need to be avoided and maybe the comment could be a reference to some more advance documentation

    NB: I know javadoc, junit and metrics is for java but...

    --
    "Use cases are fairy tales..." I. S. 2005
  35. CSS by t_allardyce · · Score: 2, Interesting

    would this be a good time for someone to explain to me why CSS doesn't support // comments, only /* ?

    --
    This comment does not represent the views or opinions of the user.
  36. more than 60% by lebow · · Score: 2, Insightful

    I recently took a contract somewhere as an 'engineer' where I was probably the only one who had an engineering degree. Also the work I was doing was far from engineering (web programing). Also I've been on interviews where the client sets me up to talk with their "engineer" who probably doesn't even have a college degree. The problem I've run into is that many times the ones doing the hiring have no idea what they are talking about. To them the engineer is the guy who can use the terminal, or can write HTML by hand.
    Another problem ( I think I'm on a rant here ) is that some people say they want an engineer when what they want is a designer, they want someone to make their site look pretty, and they really don't care about functionality. They just figure "Its too technical for me so I must need an engineer."
    (The situation isn't helped by people who use flash and call them selves an engineer)

  37. Re:Klingons and code documentation by tomhudson · · Score: 2, Funny
    1. Our users will know fear and cower before our software. Ship it! Ship it, and let them flee like the dogs they are!
    Bill Gates is a Klingon? I thought he was a Borg?