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

                K Offline
                K Offline
                Kyudos
                wrote on last edited by
                #31

                Doesn't (didn't?) AutoDuck use comments under the line?

                1 Reply Last reply
                0
                • J Joe Woodbury

                  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 Offline
                  N Offline
                  Naruki 0
                  wrote on last edited by
                  #32

                  But if you had malformed comments that included the open or the close trigger as regular text, that could get ugly fast.

                  Narf.

                  J 1 Reply Last reply
                  0
                  • N Naruki 0

                    But if you had malformed comments that included the open or the close trigger as regular text, that could get ugly fast.

                    Narf.

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

                    Never had that.

                    N 1 Reply Last reply
                    0
                    • J Joe Woodbury

                      Never had that.

                      N Offline
                      N Offline
                      Naruki 0
                      wrote on last edited by
                      #34

                      Never is an absolute, so the chances are you are wrong. Eventually. :-)

                      Narf.

                      J 1 Reply Last reply
                      0
                      • N Naruki 0

                        Never is an absolute, so the chances are you are wrong. Eventually. :-)

                        Narf.

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

                        I was speaking past tense. Henceforth, I will never use comments and therefore never see this. :)

                        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

                          S Offline
                          S Offline
                          Schmuli
                          wrote on last edited by
                          #36

                          As almost everyone has replied previously, generally comments appear above the code or inline. In the world of academia, where real-world applications, programming teams and programmers are sparse to non-existent, you may find lots of things that are different to what really goes out in the real-world. That being said, although I may be wrong, there is one time when I will put a comment after the line of code, and that is in the case of 'else'.

                          // This explains what will happen when 'condition' is true
                          if( true )
                          {
                          ...
                          }
                          else
                          {
                          // This explains what happens in other cases
                          }

                          I'm not sure what others do in this case, but then again, it is very specific, only appears inside a function block, and is pretty clear when reading the code.

                          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

                            J Offline
                            J Offline
                            Jakob Olsen
                            wrote on last edited by
                            #37

                            Don't comment that line.... :laugh: Rename the function to InitArrayOfPoints() instead

                            Bitmatic - C# & .NET programming

                            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

                              A Offline
                              A Offline
                              Anton Afanasyev
                              wrote on last edited by
                              #38

                              I can see why things like this may be done - the programemr first writes code, then comments it. This may (theoretically) benefit the original programmer in that the code is fresh in his memory, and writing a comment to reflect what it does may "force" him to spot subtle errors. (Of course, same can be said about the traditional "above"-style commenting, but I think the "below"-style makes sense here). I think the "below" style would also benefit a new programmer trying to understand or debug the code - she reads the code, understands (hopefully) it, and then reads the intention - if they dont match, well, there's clearly a problem with the code. How's that for a possible "why?" ?

                              "Impossible" is just an opinion.

                              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

                                U Offline
                                U Offline
                                User 4483848
                                wrote on last edited by
                                #39

                                At university I was always told that comments should go before the code rather than after. It's the way our brains work, top to bottom, left to right. Comments below the line is just weird, and looks weird. The comment looks far too wordy though. Surely 'initializes points' is enough. If it was me I would do InitPoints(); or maybe just Init(); if it was a small application. The function name is enough to guess what it does.

                                1 Reply Last reply
                                0
                                • OriginalGriffO OriginalGriff

                                  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"

                                  D Offline
                                  D Offline
                                  dmpthekiller
                                  wrote on last edited by
                                  #40

                                  Hahahaha... Totally agree!!! Comments above or on the same line (if it's a very simple comment)... Edit: And what about useless comments???... Have you ever wrote those???... Like: // Check if a > b if (a > b) { (...) } Hahahaha... It seems too stupid, but I must confess I've done it a couple of times...

                                  modified on Thursday, November 12, 2009 6:49 AM

                                  G 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
                                    caposada
                                    wrote on last edited by
                                    #41

                                    Definitely above. The point is that a coder can come along later and read the comment first (understand what to expect) and then read the code. Besides, now it's the convention. To use something else would likely lead to confusion. Chris.

                                    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

                                      T Offline
                                      T Offline
                                      Thomas Vanderhoof
                                      wrote on last edited by
                                      #42

                                      Above...unless you really don't like the person who will be maintaining the code.

                                      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

                                        B Offline
                                        B Offline
                                        BunnyFaber
                                        wrote on last edited by
                                        #43

                                        I have a habit of putting comments to the right of the code.

                                        Init(); // Here we do some thing with other things that do stuff to things

                                        Probably a habit leftover from my assembler days. Which would be just yesterday, in fact.

                                        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

                                          T Offline
                                          T Offline
                                          TrudyH
                                          wrote on last edited by
                                          #44

                                          As someone who has only taken a few programming classes, and learned everything else on my own my opinion may be a bit skewed. :omg: I prefer the comments above the code for two reasons. First I have learned a lot from studying other peoples code and having the comments above the code helps me follow along and figure out what they are doing and then how they are doing it. Second in my own code it helps me to go back later and kind of follow the logic of what I am trying to do so I can go back later to see if I missed something. Kinda of a "Do this, like this, then do that, like this . . ." This probably isn't as important for most of you but as someone who doesn't code for a living, but has to code to make their living it can be such a big help. ;) T

                                          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