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. Commentaries - above or below the code?

Commentaries - above or below the code?

Scheduled Pinned Locked Moved The Lounge
questiondata-structures
64 Posts 46 Posters 41 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.
  • L Offline
    L Offline
    Lutoslaw
    wrote on last edited by
    #1

    A programmingcommenting question. I have been writing commentaries above a related line of code, like this:

    // The Init() method we call here initializes an array of points
    Init();

    However, I have seen a big sample of code written by one of my professors recently. The commentaries was placed below a line.

    Init();
    // The Init() method we call here initializes an array of points

    Sincerely, I have found it very clear and understable. Did anybody encounter such approach to commenting code? Is it recommended?

    Greetings - Jacek

    N D R 1 V 31 Replies Last reply
    0
    • L Lutoslaw

      A programmingcommenting question. I have been writing commentaries above a related line of code, like this:

      // The Init() method we call here initializes an array of points
      Init();

      However, I have seen a big sample of code written by one of my professors recently. The commentaries was placed below a line.

      Init();
      // The Init() method we call here initializes an array of points

      Sincerely, I have found it very clear and understable. Did anybody encounter such approach to commenting code? Is it recommended?

      Greetings - Jacek

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      If it's a small comment, you could even do this:

      Init(); // The Init() method we call here initializes an array of points

      Regards, Nish


      Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
      My latest book : C++/CLI in Action / Amazon.com link

      N E 2 Replies Last reply
      0
      • L Lutoslaw

        A programmingcommenting question. I have been writing commentaries above a related line of code, like this:

        // The Init() method we call here initializes an array of points
        Init();

        However, I have seen a big sample of code written by one of my professors recently. The commentaries was placed below a line.

        Init();
        // The Init() method we call here initializes an array of points

        Sincerely, I have found it very clear and understable. Did anybody encounter such approach to commenting code? Is it recommended?

        Greetings - Jacek

        D Offline
        D Offline
        Duncan Edwards Jones
        wrote on last edited by
        #3

        above Humans read downwards and we want to know what you intend to do (comment) before we read what you are doing (code).

        '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd

        1 Reply Last reply
        0
        • L Lutoslaw

          A programmingcommenting question. I have been writing commentaries above a related line of code, like this:

          // The Init() method we call here initializes an array of points
          Init();

          However, I have seen a big sample of code written by one of my professors recently. The commentaries was placed below a line.

          Init();
          // The Init() method we call here initializes an array of points

          Sincerely, I have found it very clear and understable. Did anybody encounter such approach to commenting code? Is it recommended?

          Greetings - Jacek

          R Offline
          R Offline
          Rajesh R Subramanian
          wrote on last edited by
          #4

          Above or on the same line, but never below.

          “Follow your bliss.” – Joseph Campbell

          1 Reply Last reply
          0
          • L Lutoslaw

            A programmingcommenting question. I have been writing commentaries above a related line of code, like this:

            // The Init() method we call here initializes an array of points
            Init();

            However, I have seen a big sample of code written by one of my professors recently. The commentaries was placed below a line.

            Init();
            // The Init() method we call here initializes an array of points

            Sincerely, I have found it very clear and understable. Did anybody encounter such approach to commenting code? Is it recommended?

            Greetings - Jacek

            1 Offline
            1 Offline
            1 21 Gigawatts
            wrote on last edited by
            #5

            Comments below the line of code? Sure, if you're the sort of person who wears their underpants on top of their trousers.

            "People who don't like their beliefs being laughed at shouldn't have such funny beliefs." ~ Anon "If you can't explain it simply, you don't understand it well enough" ~ Albert Einstein Currently reading: 'The Greatest Show on Earth', by Richard Dawkins.

            M R 2 Replies Last reply
            0
            • L Lutoslaw

              A programmingcommenting question. I have been writing commentaries above a related line of code, like this:

              // The Init() method we call here initializes an array of points
              Init();

              However, I have seen a big sample of code written by one of my professors recently. The commentaries was placed below a line.

              Init();
              // The Init() method we call here initializes an array of points

              Sincerely, I have found it very clear and understable. Did anybody encounter such approach to commenting code? Is it recommended?

              Greetings - Jacek

              V Offline
              V Offline
              vaghelabhavesh
              wrote on last edited by
              #6

              Above. When reading code it helps you to understand what the following line does.

              If you fail to plan, you plan to fail! Books are as useful to a stupid person as a mirror is useful to a blind person. - Chanakya

              1 Reply Last reply
              0
              • 1 1 21 Gigawatts

                Comments below the line of code? Sure, if you're the sort of person who wears their underpants on top of their trousers.

                "People who don't like their beliefs being laughed at shouldn't have such funny beliefs." ~ Anon "If you can't explain it simply, you don't understand it well enough" ~ Albert Einstein Currently reading: 'The Greatest Show on Earth', by Richard Dawkins.

                M Offline
                M Offline
                Media2r
                wrote on last edited by
                #7

                You think he's Superman? //L

                1 Reply Last reply
                0
                • L Lutoslaw

                  A programmingcommenting question. I have been writing commentaries above a related line of code, like this:

                  // The Init() method we call here initializes an array of points
                  Init();

                  However, I have seen a big sample of code written by one of my professors recently. The commentaries was placed below a line.

                  Init();
                  // The Init() method we call here initializes an array of points

                  Sincerely, I have found it very clear and understable. Did anybody encounter such approach to commenting code? Is it recommended?

                  Greetings - Jacek

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Above are the Comments for human. :) Below may be for the machine. :rolleyes:

                  Regards Aman Bhullar www.arlivesupport.com[^]

                  1 Reply Last reply
                  0
                  • L Lutoslaw

                    A programmingcommenting question. I have been writing commentaries above a related line of code, like this:

                    // The Init() method we call here initializes an array of points
                    Init();

                    However, I have seen a big sample of code written by one of my professors recently. The commentaries was placed below a line.

                    Init();
                    // The Init() method we call here initializes an array of points

                    Sincerely, I have found it very clear and understable. Did anybody encounter such approach to commenting code? Is it recommended?

                    Greetings - Jacek

                    P Offline
                    P Offline
                    peterchen
                    wrote on last edited by
                    #9

                    Above for intention, behind for details. In-Method comments should show the intention of the block they are commenting on (instead of repeating what the code says). A reader of the code should be able to skim over the coments to understand the structure of the code. In virtually all cultures title and abstract go before the actual content. Code should be no different.

                    // Find appropriate file
                    path = GetDefaultPath();
                    if (!path.Exists()) // alternate path (clients < 1.7)
                    path = GetDefaultPathV1();

                    // check for pending transactions
                    ...

                    Personally, I love the idea that Raymond spends his nights posting bad regexs to mailing lists under the pseudonym of Jane Smith. He'd be like a super hero, only more nerdy and less useful. [Trevel]
                    | FoldWithUs! | sighist | µLaunch - program launcher for server core and hyper-v server

                    1 Reply Last reply
                    0
                    • N Nish Nishant

                      If it's a small comment, you could even do this:

                      Init(); // The Init() method we call here initializes an array of points

                      Regards, Nish


                      Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
                      My latest book : C++/CLI in Action / Amazon.com link

                      N Offline
                      N Offline
                      NormDroid
                      wrote on last edited by
                      #10

                      Some people can't see with wood from the trees :)

                      Software Kinetics (requires SL3 beta) - Moving software

                      1 Reply Last reply
                      0
                      • N Nish Nishant

                        If it's a small comment, you could even do this:

                        Init(); // The Init() method we call here initializes an array of points

                        Regards, Nish


                        Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
                        My latest book : C++/CLI in Action / Amazon.com link

                        E Offline
                        E Offline
                        Electron Shepherd
                        wrote on last edited by
                        #11

                        Or even better, rename the function so you don't need the comment.

                        Server and Network Monitoring

                        R 1 Reply Last reply
                        0
                        • L Lutoslaw

                          A programmingcommenting question. I have been writing commentaries above a related line of code, like this:

                          // The Init() method we call here initializes an array of points
                          Init();

                          However, I have seen a big sample of code written by one of my professors recently. The commentaries was placed below a line.

                          Init();
                          // The Init() method we call here initializes an array of points

                          Sincerely, I have found it very clear and understable. Did anybody encounter such approach to commenting code? Is it recommended?

                          Greetings - Jacek

                          OriginalGriffO Offline
                          OriginalGriffO Offline
                          OriginalGriff
                          wrote on last edited by
                          #12

                          Generally, comments have always been written above or on the same line as the code. My objection to having comments below the relevant code is that it would be awkward if it was consistant:

                          Init();
                          // Init blah de blah

                          is fine, but

                          private MyClass[] GetMyClassInstances(int count, bool why, string whathaveyou...)
                          {
                          ... body of long function
                          }
                          /// GetMyClass does whatever it does
                          /// Parameters: whatever they are

                          is just asking for trouble!

                          No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones "Rumour has it that if you play Microsoft CDs backwards you will hear Satanic messages.Worse still, is that if you play them forwards they will install Windows"

                          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                          D 1 Reply Last reply
                          0
                          • L Lutoslaw

                            A programmingcommenting question. I have been writing commentaries above a related line of code, like this:

                            // The Init() method we call here initializes an array of points
                            Init();

                            However, I have seen a big sample of code written by one of my professors recently. The commentaries was placed below a line.

                            Init();
                            // The Init() method we call here initializes an array of points

                            Sincerely, I have found it very clear and understable. Did anybody encounter such approach to commenting code? Is it recommended?

                            Greetings - Jacek

                            D Offline
                            D Offline
                            Dalek Dave
                            wrote on last edited by
                            #13

                            I agree with the consensus, above. It is easier to read, and tells you what to expect.

                            ------------------------------------ In science, 'fact' can only mean 'confirmed to such a degree that it would be perverse to withhold provisional assent.' I suppose that apples might start to rise tomorrow, but the possibility does not merit equal time in physics classrooms. Stephen J Gould

                            K 1 Reply Last reply
                            0
                            • L Lutoslaw

                              A programmingcommenting question. I have been writing commentaries above a related line of code, like this:

                              // The Init() method we call here initializes an array of points
                              Init();

                              However, I have seen a big sample of code written by one of my professors recently. The commentaries was placed below a line.

                              Init();
                              // The Init() method we call here initializes an array of points

                              Sincerely, I have found it very clear and understable. Did anybody encounter such approach to commenting code? Is it recommended?

                              Greetings - Jacek

                              R Offline
                              R Offline
                              Russell Jones
                              wrote on last edited by
                              #14

                              What are these green things in your code ;-) Code should be written in such a way that it is self documenting!

                              R J 2 Replies Last reply
                              0
                              • L Lutoslaw

                                A programmingcommenting question. I have been writing commentaries above a related line of code, like this:

                                // The Init() method we call here initializes an array of points
                                Init();

                                However, I have seen a big sample of code written by one of my professors recently. The commentaries was placed below a line.

                                Init();
                                // The Init() method we call here initializes an array of points

                                Sincerely, I have found it very clear and understable. Did anybody encounter such approach to commenting code? Is it recommended?

                                Greetings - Jacek

                                P Offline
                                P Offline
                                PIEBALDconsult
                                wrote on last edited by
                                #15

                                Above or beside. /* And never with those lazy C++-style comments; only use proper C-style comments. */

                                N J 2 Replies Last reply
                                0
                                • L Lutoslaw

                                  A programmingcommenting question. I have been writing commentaries above a related line of code, like this:

                                  // The Init() method we call here initializes an array of points
                                  Init();

                                  However, I have seen a big sample of code written by one of my professors recently. The commentaries was placed below a line.

                                  Init();
                                  // The Init() method we call here initializes an array of points

                                  Sincerely, I have found it very clear and understable. Did anybody encounter such approach to commenting code? Is it recommended?

                                  Greetings - Jacek

                                  N Offline
                                  N Offline
                                  Nemanja Trifunovic
                                  wrote on last edited by
                                  #16

                                  You may like the Literate Programming[^] approach where the actual code is just a small piece of text embedded into comments.

                                  utf8-cpp

                                  1 Reply Last reply
                                  0
                                  • P PIEBALDconsult

                                    Above or beside. /* And never with those lazy C++-style comments; only use proper C-style comments. */

                                    N Offline
                                    N Offline
                                    Nemanja Trifunovic
                                    wrote on last edited by
                                    #17

                                    PIEBALDconsult wrote:

                                    And never with those lazy C++-style comments

                                    In fairness, they are BCPL[^] comments that were for some reason removed in C but reappeared in C++.

                                    utf8-cpp

                                    P 1 Reply Last reply
                                    0
                                    • N Nemanja Trifunovic

                                      PIEBALDconsult wrote:

                                      And never with those lazy C++-style comments

                                      In fairness, they are BCPL[^] comments that were for some reason removed in C but reappeared in C++.

                                      utf8-cpp

                                      P Offline
                                      P Offline
                                      PIEBALDconsult
                                      wrote on last edited by
                                      #18

                                      Ah, I sit corrected. But B seems to be where it changed. I guess I'll call them B-style comments from now on. Edit: Hmmm... corrected again, the B document says, "Comments are delimited as in PL/I by /* and */." So I guess they're PL/I-style comments.

                                      modified on Wednesday, November 11, 2009 11:36 AM

                                      1 Reply Last reply
                                      0
                                      • L Lutoslaw

                                        A programmingcommenting question. I have been writing commentaries above a related line of code, like this:

                                        // The Init() method we call here initializes an array of points
                                        Init();

                                        However, I have seen a big sample of code written by one of my professors recently. The commentaries was placed below a line.

                                        Init();
                                        // The Init() method we call here initializes an array of points

                                        Sincerely, I have found it very clear and understable. Did anybody encounter such approach to commenting code? Is it recommended?

                                        Greetings - Jacek

                                        M Offline
                                        M Offline
                                        Marc Clifton
                                        wrote on last edited by
                                        #19

                                        Comments are for sissies. ;) Marc

                                        Will work for food. Interacx

                                        I'm not overthinking the problem, I just felt like I needed a small, unimportant, uninteresting rant! - Martin Hart Turner

                                        1 Reply Last reply
                                        0
                                        • L Lutoslaw

                                          A programmingcommenting question. I have been writing commentaries above a related line of code, like this:

                                          // The Init() method we call here initializes an array of points
                                          Init();

                                          However, I have seen a big sample of code written by one of my professors recently. The commentaries was placed below a line.

                                          Init();
                                          // The Init() method we call here initializes an array of points

                                          Sincerely, I have found it very clear and understable. Did anybody encounter such approach to commenting code? Is it recommended?

                                          Greetings - Jacek

                                          P Offline
                                          P Offline
                                          Pete OHanlon
                                          wrote on last edited by
                                          #20

                                          In Plain English there is no need for comments. The longer term residents of the lounge will get this one, while newer members should Google for osmosian.

                                          "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                                          As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                                          My blog | My articles | MoXAML PowerToys | Onyx

                                          R M 2 Replies 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