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 45 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.
  • 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
                      • P Pete OHanlon

                        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 Offline
                        R Offline
                        Rob Graham
                        wrote on last edited by
                        #21

                        There is, however, a need for plain english in comments...especially if the comments are in Plain English.

                        1 Reply Last reply
                        0
                        • P Pete OHanlon

                          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

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

                          Pete O'Hanlon wrote:

                          In Plain English there is no need for comments.

                          My gf claims to speak to me in Plain English, but I still can't figure out what she's saying. ;) 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

                          P P 2 Replies Last reply
                          0
                          • P PIEBALDconsult

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

                            J Offline
                            J Offline
                            Joe Woodbury
                            wrote on last edited by
                            #23

                            Except you can't enclose a block of code with C (/* */) style comments with a C style comment. One of the dumbest things ever.

                            P 1 Reply Last reply
                            0
                            • M Marc Clifton

                              Pete O'Hanlon wrote:

                              In Plain English there is no need for comments.

                              My gf claims to speak to me in Plain English, but I still can't figure out what she's saying. ;) 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

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

                              "You botched it", basically, for different values of "it".

                              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

                              R 1 Reply Last reply
                              0
                              • J Joe Woodbury

                                Except you can't enclose a block of code with C (/* */) style comments with a C style comment. One of the dumbest things ever.

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

                                That depends on the compiler; you can select it on some:

                                Borland C++ 5.5 for Win32 Copyright (c) 1993, 2000 Borland
                                Syntax is: BCC32 [ options ] file[s] * = default; -x- = turn switch x off
                                -3 * 80386 Instructions -4 80486 Instructions
                                -5 Pentium Instructions -6 Pentium Pro Instructions
                                -Ax Disable extensions -B Compile via assembly
                                -C Allow nested comments -Dxxx Define macro

                                And anyway, how would the other style help with that?

                                J 1 Reply Last reply
                                0
                                • P PIEBALDconsult

                                  That depends on the compiler; you can select it on some:

                                  Borland C++ 5.5 for Win32 Copyright (c) 1993, 2000 Borland
                                  Syntax is: BCC32 [ options ] file[s] * = default; -x- = turn switch x off
                                  -3 * 80386 Instructions -4 80486 Instructions
                                  -5 Pentium Instructions -6 Pentium Pro Instructions
                                  -Ax Disable extensions -B Compile via assembly
                                  -C Allow nested comments -Dxxx Define macro

                                  And anyway, how would the other style help with that?

                                  J Offline
                                  J Offline
                                  Joe Woodbury
                                  wrote on last edited by
                                  #26

                                  I remembered Borland well and used nested comments. VC++ doesn't currently support them (to my knowledge.)

                                  PIEBALDconsult wrote:

                                  And anyway, how would the other style help with that?

                                  Because they can be nested by a /* */ when you want to temporarily block out some code (and with code highlighting, it becomes really obvious what you did.

                                  N 1 Reply Last reply
                                  0
                                  • M Marc Clifton

                                    Pete O'Hanlon wrote:

                                    In Plain English there is no need for comments.

                                    My gf claims to speak to me in Plain English, but I still can't figure out what she's saying. ;) 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

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

                                    She's speaking Plain English, and we're listening in Penis.

                                    "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

                                    M 1 Reply Last reply
                                    0
                                    • P Pete OHanlon

                                      She's speaking Plain English, and we're listening in Penis.

                                      "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

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

                                      Pete O'Hanlon wrote:

                                      She's speaking Plain English, and we're listening in Penis.

                                      :laugh: :-O 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

                                        C Offline
                                        C Offline
                                        Chris Maunder
                                        wrote on last edited by
                                        #29

                                        Everyone, for ever, has placed it above. Let's just stick to the accepted pattern and move along.

                                        cheers, Chris Maunder The Code Project Co-founder Microsoft C++ MVP

                                        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

                                          I Offline
                                          I Offline
                                          ian dennis 0
                                          wrote on last edited by
                                          #30

                                          I used to comment my procedures after the procedure name, like: Function DoIt(thingie as string) as Boolean '*======== '* Purpose: Do it '* Mod1 : and do it now '* Accepts: Thingie (What you're going to do it to) '* Returns: True if did it, else False '* Author : Ian Dennis based on code provided by Steve Smith '* Date : 01/02/2009 '* Mod1 : 02/10/2009 ... but I've noticed that both VB.Net and C# make use of XML comments, which happen before the procedure name, like: ''' <summary> ''' Do It and do it now ''' </summary> ''' <param name="thingie">What you're going to do it to</param> ''' <returns>True if done, else False</returns> Function DoIt(thingie as string) as Boolean As the XML helps with intellisense, I've started switching to that format

                                          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