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 127 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.
  • S Schmuli

    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 Offline
    R Offline
    RichardM1
    wrote on last edited by
    #61

    Yes, commenting if/else statements is a pain. I comment if (without else) before the test, and if/else after the contained curly bracket. I don't like it, I just have not found a better way.

    Silver member by constant and unflinching longevity.

    1 Reply Last reply
    0
    • C Chris Maunder

      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 Offline
      R Offline
      RichardM1
      wrote on last edited by
      #62

      Chris - say it with me now: "Change" Change, it's not just for good, it's for its own sake.

      Silver member by constant and unflinching longevity.

      1 Reply Last reply
      0
      • D Dalek Dave

        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 Offline
        K Offline
        kirankss
        wrote on last edited by
        #63

        The comment should alway be either above or to the right of 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

          P Offline
          P Offline
          patbob
          wrote on last edited by
          #64

          Above the code that implements it is best. That allows the reader to go from generalitites to specifics by reading top to bottom, just like an outline, or a story, or any other type of explanatory writing. I think you should your the entire class to turn in an assignment with the comments below the code they comment. They can't mark down for it since the professor provides examples comemnted that way. If they actually read your source code, they'll probably try to mark it down though.

          patbob

          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