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

    L Offline
    L Offline
    leppie
    wrote on last edited by
    #11

    **

    How xacc.ide transforms text to colored words on the screen
    Intel PentuimM (aka Centrino) undervolting

    **

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

      T Offline
      T Offline
      Tarakeshwar Reddy
      wrote on last edited by
      #12

      Weiye Chen wrote:

      that writing "greenie sentences"(a.k.a Comments) in codes are only for amateurs? It

      Most of my code is like un-greened. After I am done with the project or a screen, I add comments for the functions and a comment here and there for some logic which may not be understandable for a 3rd person. But I just hate it when people make the whole screen green by adding comments to every single line(some cases you may need, but not all).


      Tarakeshwar MCP, CCIE Q(R&S) Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes. !sgub evah t'nseod margorP sihT ?sgub naem ayaddahW

      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
        Christopher Duncan
        wrote on last edited by
        #13

        Hey, if it was hard to write, it should be hard to understand! :-D Author of The Career Programmer and Unite the Tribes Know someone who desperately needs to get a clue? Visit www.DownloadAClue.com and send them one!

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

          S Offline
          S Offline
          Shog9 0
          wrote on last edited by
          #14

          I can read most of the languages i work with well enough - it's nothing but an annoyance to find that someone has documented the obvious stuff ("loop on each member of aObArray"). What i like to see are a) documentation prior to each method, describing both the reason for its existence and how it should be used, and b) documentation for bits of non-obvious code (not necessarily complex code, just code that doesn't exist for any internal reason - the sort of stuff we kindly refer to as "business logic").

          ---- Scripts i’ve known... CPhog 1.0.0.0 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.2 - printer-friendly forums Expand all 1.0 - Expand all messages In-place Delete 1.0 - AJAX-style post delete Syntax 0.1 - Syntax highlighting for code blocks in the forums

          1 Reply Last reply
          0
          • S shreekar

            I prefer the middle path - short description of the function/procedure at the top with desdription of parameters and then add comments inline ONLY IF (a)the code implements some weird business logic OR (b) is convulated to understand by a first time reader. Shreekar http://shreekarishere.blogspot.com

            S Offline
            S Offline
            Shog9 0
            wrote on last edited by
            #15

            Heh, right on. I should have read your comment before replying. :)

            ---- Scripts i’ve known... CPhog 1.0.0.0 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.2 - printer-friendly forums Expand all 1.0 - Expand all messages In-place Delete 1.0 - AJAX-style post delete Syntax 0.1 - Syntax highlighting for code blocks in the forums

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

              E Offline
              E Offline
              El Corazon
              wrote on last edited by
              #16

              I am a big one on documenting function intent. Sure the programmer can read the code and find out what it "is" doing eventually. But what did the programmer intend it to do? In a perfect world, the two always match. But what if there is a sideaffect because the function shared an input object in write form. It might work fine until someone else tries to manipulate the same variable, thus are bugs born. But if you didn't know that the programmer originally "intended" that parameter to be read-only, you wouldn't realize there is a bug lying and waiting. I guess programmers tend to look at comments with different intent. Some are using comments so their managers (non-programmers) can read the program. Others are using line comments to match an approved psuedo-code that is part of the design documents. Then there are those who look at header comments as the be-all-end-all of documentation, you don't even need to pull up the code, it's all laid out in the header along with flow-chart symbols, mathematical formulas, sample code sections, help desk numbers, and the date and time in 10 languages. Intent is the reason. Are your comments your published documentation extracted via doxygen? I have seen some pretty fancy doxygen comments! whew! My intent in comments is to put down my initial intent in the logic of the code, what is its purpose, what is its input and output functionality. Admitedly I come from the military IPO documentation standard days, so I have a bias. Still, I find the logic of documenting purpose worthwhile. Line logic comments are only for state oddities // Transmission loss detected // bad packet, estimate position for max xx seconds // this is a panic condition: initiate self-destruct But again, it comes down to intent. Why is he calling the self-destruct here? The programmer considered that a panic condition. _________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)

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

                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