Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Greenie sentences

Greenie sentences

Scheduled Pinned Locked Moved The Lounge
question
27 Posts 23 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Weiye Chen

    Is there a mentality among programmers that writing "greenie sentences"(a.k.a Comments) in codes are only for amateurs? It seems like i am the only one making my code as "green" as possible. It feel frustrating trying to understand other person's code that are long and "un-greened". X| Weiye Chen Life is hard, yet we are made of flesh...

    S Offline
    S Offline
    Sailor Jones
    wrote on last edited by
    #17

    I think anyone that has been doing this for awhile recognizes the value of comments. If I have to go back and modify something I wrote a year ago and I can't understand what I was attempting to do, then the job will be more difficult. If I can't understand what I did, then the chances of someone else figuring it out are slim. Comments provide a road map. If I think what I am writing will be difficult to understand the intention of, then I always put in comments. I don't write function headers, but target my comments to the specific areas that I think will need it.

    1 Reply Last reply
    0
    • R R Giskard Reventlov

      Weiye Chen wrote:

      Is there a mentality among programmers that writing "greenie sentences"(a.k.a Comments) in codes are only for amateurs?

      I would hope not! We comment (in a standardised way) everything and then use NDocs to produce .chm files. If anyone tries to sneak code in without reasonably verbose commentary it gets picked up and rejected. If you can't explain what you've done then you probably dodn't understand it. Have always done so and most of the coders I've worked with have always done so as a matter of course. It is sloppy not to. Anyway, that was my tuppence worth. home
      bookmarks You can ignore relatives but the neighbours live next door

      T Offline
      T Offline
      Thomas Eyde
      wrote on last edited by
      #18

      digital man wrote:

      If you can't explain what you've done then you probably dodn't understand it

      I'd say, if you can't read and understand what they wrote (coded), the code is already in a bad state and no comments can save it. I don't know about you, but I have to understand the code, not the comments, before I can do any changes.

      S 1 Reply Last reply
      0
      • W Weiye Chen

        Is there a mentality among programmers that writing "greenie sentences"(a.k.a Comments) in codes are only for amateurs? It seems like i am the only one making my code as "green" as possible. It feel frustrating trying to understand other person's code that are long and "un-greened". X| Weiye Chen Life is hard, yet we are made of flesh...

        C Offline
        C Offline
        cmpenney
        wrote on last edited by
        #19

        I like the short descriptions in code myself. I typically don't have alot of problem following other's code and too much commenting just makes it harder to read IMO.

        1 Reply Last reply
        0
        • W Weiye Chen

          Is there a mentality among programmers that writing "greenie sentences"(a.k.a Comments) in codes are only for amateurs? It seems like i am the only one making my code as "green" as possible. It feel frustrating trying to understand other person's code that are long and "un-greened". X| Weiye Chen Life is hard, yet we are made of flesh...

          V Offline
          V Offline
          Vidhya Narasimhan
          wrote on last edited by
          #20

          Here are my 2 cents on this topic. One method that is very effective is naming the variables and methods to be self descriptive. This, along with necessary comments to describe complicated logic has worked out well for our team. The comments say "why" instead of "how". Examples for naming: Orders.GetDetailedInformation instead of ord.GetDetInfo Employee.IsRetired instead of Emp.Retired

          1 Reply Last reply
          0
          • W Weiye Chen

            Is there a mentality among programmers that writing "greenie sentences"(a.k.a Comments) in codes are only for amateurs? It seems like i am the only one making my code as "green" as possible. It feel frustrating trying to understand other person's code that are long and "un-greened". X| Weiye Chen Life is hard, yet we are made of flesh...

            K Offline
            K Offline
            Kenneth Kasajian
            wrote on last edited by
            #21

            You can always stare at a code long enough to figure out *what* it does. Comment the *why* -- that's harder to discern.

            1 Reply Last reply
            0
            • T Thomas Eyde

              digital man wrote:

              If you can't explain what you've done then you probably dodn't understand it

              I'd say, if you can't read and understand what they wrote (coded), the code is already in a bad state and no comments can save it. I don't know about you, but I have to understand the code, not the comments, before I can do any changes.

              S Offline
              S Offline
              scoy6
              wrote on last edited by
              #22

              Thomas Eyde wrote:

              I'd say, if you can't read and understand what they wrote (coded), the code is already in a bad state and no comments can save it.

              The problem with reading code is what to do when it's wrong. Comments should focus on the intention of the code not the implementation. Hopefully the two will match up.

              T 1 Reply Last reply
              0
              • G Graham Shanks

                We have two levels of greenies: Our library header files are heavily documented (ratio of comment lines to code lines often exceeds 10 to 1). This documentation is used to generate the library manuals (we use doxygen), so needs to be sufficient for an intelligent programmer to be able to understand what the function does and how to use it. Source files (i.e. .c & .cpp) are documented more sparingly. Long functions will be split up with comments telling roughly what (at a high level) the code block does. Tricky bits of code or places where we've had to change code to work around obscure bugs tend to get commented much more heavily (so that it doesn't get changed back). Comments in source code (not header files) should say why the code is structured the way it is. I expect that engineers can understand the syntax of the code without further explanation. In code reviews I automatically fail code if it contains comments such as: // Increment i; i++; Graham -- modified at 7:09 Tuesday 30th May, 2006

                S Offline
                S Offline
                schleprock
                wrote on last edited by
                #23

                i agree with Graham, comments within header files should explain what the method does, how to use the method, the expected output, and (gasp) any side effects. header comments should not ever explain how the method does it's work. within source code, comments should explain the intent of the code as well as any assumptions. i absolutely hate comments such as the one Graham points out and for God's sake, if you change the code and the comments are not relevent or even worse, not correct, REMOVE THEM or CORRECT THEM. it just blows me away when people check in code with obsolete or incorrect comments. i'll get off my soap box now. schleprock :cool: "God only knows, and he ain't talkin'" David Lee Roth

                1 Reply Last reply
                0
                • W Weiye Chen

                  Is there a mentality among programmers that writing "greenie sentences"(a.k.a Comments) in codes are only for amateurs? It seems like i am the only one making my code as "green" as possible. It feel frustrating trying to understand other person's code that are long and "un-greened". X| Weiye Chen Life is hard, yet we are made of flesh...

                  J Offline
                  J Offline
                  JohnMcPherson1
                  wrote on last edited by
                  #24

                  I write comments... The rule of thumb I use is this: If it looks sufficiently 'tricky' then I comment it. If it looks real 'tricky' then I comment every line. Why? Because in 6 months when I have to go back and maintain it I really want to know, in a hurry, what it does... Regards, By the way, by sufficiently tricky I mean code that would take someone an hour to two to figure out. The real tricky stuff is code that the next programmer will wast a couple of days on, cut it out and write their own. Regards, John McPherson "Sufficiently advanced technology is indistinguishable from magic." Arthur C. Clark, inventor of the telecommunications satellite

                  1 Reply Last reply
                  0
                  • S scoy6

                    Thomas Eyde wrote:

                    I'd say, if you can't read and understand what they wrote (coded), the code is already in a bad state and no comments can save it.

                    The problem with reading code is what to do when it's wrong. Comments should focus on the intention of the code not the implementation. Hopefully the two will match up.

                    T Offline
                    T Offline
                    Thomas Eyde
                    wrote on last edited by
                    #25

                    sKoi wrote:

                    Comments should focus on the intention of the code not the implementation

                    I think we both have to search for a very long time to find anyone who disagree. But, how often does this happen? Sooner or later, the code will drift away from the comments. I believe if you are that good, that your code always match your comments, and your comments are right on the spot, then you could drop the comments. Your code would be already be clean and self documenting.

                    1 Reply Last reply
                    0
                    • W Weiye Chen

                      Is there a mentality among programmers that writing "greenie sentences"(a.k.a Comments) in codes are only for amateurs? It seems like i am the only one making my code as "green" as possible. It feel frustrating trying to understand other person's code that are long and "un-greened". X| Weiye Chen Life is hard, yet we are made of flesh...

                      O Offline
                      O Offline
                      Owen Lawrence
                      wrote on last edited by
                      #26

                      I would say that code that does not contain comments was almost certainly written by junior programmers, if not amateurs. It's a clear indication that this programmer hasn't been around the bend enough times yet to know how good his code isn't. Comments explaining what the code does aren't always useful, but I'd rather have them there in case the code doesn't do what the comment says, which clearly indicates a mistake was made. Comments that explain WHY the code is there are more important. Suppose there's a little bit of goofiness in the code, left sitting there by Fred a year before. While Joe programmer was adding a new feature, he spots it and cleans it up. Six months later a client comes back for some repeat business. Three months after that his new system is deployed, and horrors, the abstract problem they spent a week researching two years ago is back! Fred was promoted last Chrismas because of the awesome job he did, pumping out code for all and sundry and he never looked back. He parleyed that promotion into a VP role at CodeMonkeyStartup over in Europe. Joe took TWO weeks to replace that goofiness because he wasn't overly familiar with the code and had to rewrite six modules because they didn't make any sense to him at all the way they were. He got a mark on his performance review and in trouble with his wife for spending his anniversary evening at the office. I quit my first job shortly after my boss told me to remove all my comments from my code because the customer could see them. I never regretted it.

                      1 Reply Last reply
                      0
                      • W Weiye Chen

                        Is there a mentality among programmers that writing "greenie sentences"(a.k.a Comments) in codes are only for amateurs? It seems like i am the only one making my code as "green" as possible. It feel frustrating trying to understand other person's code that are long and "un-greened". X| Weiye Chen Life is hard, yet we are made of flesh...

                        K Offline
                        K Offline
                        kackermann
                        wrote on last edited by
                        #27

                        If you've been programming long enough, you can read anything. That's why only beginners use lots of comments. Plus, comments have to be maintained too.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups