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

code comments

Scheduled Pinned Locked Moved The Lounge
question
65 Posts 27 Posters 2 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.
  • C charlieg

    Here we go :). After so many years of coding, I've learned to cull back on the wordiness of the code. Still, I have a few wonder brothers who "read code so fluently" that things get opaque pretty quick. I try to stay away from the "//declare variables" nonsense and lean toward higher level explanations of code blocks. One thing that *will* set me off is when people don't use version control. So, you'll get interspersed lines of code that are commented out with new lines of code that fix a problem. One leaves this in the source in case if you need to remember what you changed. FFS, use "show changes".

    Charlie Gilley Do not forget Jacques Hamel "Where liberty dwells, there is my country." B. Franklin, 1783 “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759

    D Offline
    D Offline
    Dan Neely
    wrote on last edited by
    #24

    There're times when the sort of commented old code crap can be useful. Like when you were given a source dump for an ancient MFC app that the customer wants an update to and find yourself going "WTF this pile of code looks like it was obsolete even when MFC was new. C with classes every once in a while is a revolting way to write C++." for weeks on end, finding that one file that never got cleaned up and is full of commented code to create X-Windows GUI components can be enlightening in an "OH. The original version of this dinosaur was apparently a C/Slowlaris application before being ported to the then new and shiny NT4 and MFC in the late 90s." sort of way. :sigh:

    Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

    1 Reply Last reply
    0
    • R realJSOP

      What's more disturbing is that C# *still* doesn't allow this:

      if (!someObj) {...}

      which would preclude them from having to come up with the bullsh|t "?" operator.

      ".45 ACP - because shooting twice is just silly" - JSOP, 2010
      -----
      You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
      -----
      When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

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

      John Simmons / outlaw programmer wrote:

      bullsh|t "?" operator

      More like boolsh|t in this case.

      The language is JavaScript. that of Mordor, which I will not utter here
      This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
      "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

      1 Reply Last reply
      0
      • R realJSOP

        What's more disturbing is that C# *still* doesn't allow this:

        if (!someObj) {...}

        which would preclude them from having to come up with the bullsh|t "?" operator.

        ".45 ACP - because shooting twice is just silly" - JSOP, 2010
        -----
        You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
        -----
        When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #26

        If you implement the true[^] and false[^] operators, you can do something like:

        if (someObj) { ... }

        but you can't do:

        if (!someObj) { ... }


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        1 Reply Last reply
        0
        • S Slacker007

          IsNotNull? Also, you should not be purposely throwing an error from an extension method, as part of some divine plan. Just check if it is null or not, that is all. Leave the implementation to the calling party - this helps with code reuse (I may not want to do a console.writeline). My 2 unsolicited cents on your post. :-D

          B Offline
          B Offline
          BillWoodruff
          wrote on last edited by
          #27

          Well, I am afraid someone took me off the "divine plan" update service some years ago. Please note: 1. the code will throw an error in the Extension method only when the 'throwerror parameter is 'true, and, of course, the instance of the generic parameter T (constrained to Type 'Class) is null. 2. the code will only call Console.WriteLine when the compiler directive '#define ErrorsToConsole is included at the start of the file. One would expect this to be present only in the developer's code who is using the source. Again, keep in mind this is only an experiment. I gladly accept your 2 cents ! cheers, Bill

          «There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008

          1 Reply Last reply
          0
          • Z ZurdoDev

            Sander Rossel wrote:

            Currently, I have a coworker who writes comments like:

            Perhaps he used to teach first level coding in high school. :-\

            There are only 10 types of people in the world, those who understand binary and those who don't.

            Sander RosselS Offline
            Sander RosselS Offline
            Sander Rossel
            wrote on last edited by
            #28

            He never did coding in school, maybe he's trying to make up for it? :sigh:

            Read my (free) ebook Object-Oriented Programming in C# Succinctly. Visit my blog at Sander's bits - Writing the code you need. Or read my articles here on CodeProject.

            Simplicity is prerequisite for reliability. — Edsger W. Dijkstra

            Regards, Sander

            1 Reply Last reply
            0
            • R realJSOP

              What's more disturbing is that C# *still* doesn't allow this:

              if (!someObj) {...}

              which would preclude them from having to come up with the bullsh|t "?" operator.

              ".45 ACP - because shooting twice is just silly" - JSOP, 2010
              -----
              You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
              -----
              When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

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

              The new approach (v6.0) is the null conditional operator, so you don't need to check for null.

              someObj?.DoStuff();

              Regards, Nish


              Website: www.voidnish.com Blog: voidnish.wordpress.com

              T K 2 Replies Last reply
              0
              • M Member 12345678

                I am one of the other poor b*st*rd now. The original developers think their code is so beautiful and wonderful that no comment is needed to explain. They think I should ask if I do not understand. It will take longer than my lifetime to finish project this way.

                F Offline
                F Offline
                Frank Alviani
                wrote on last edited by
                #30

                You have my deepest sympathy. X|

                'PLAN' is NOT one of those four-letter words.
                'When money talks, nobody listens to the customer anymore.'

                1 Reply Last reply
                0
                • Sander RosselS Sander Rossel

                  I really dislike code comments in general[^] X| Currently, I have a coworker who writes comments like:

                  // Declare a variable.
                  int i;
                  // Assign the variable.
                  i = 42;

                  He doesn't do it all the time, but such comments are common practice. Learn to friggin code so you don't have to remind yourself of how to declare and assign a friggin variable! :mad:

                  Read my (free) ebook Object-Oriented Programming in C# Succinctly. Visit my blog at Sander's bits - Writing the code you need. Or read my articles here on CodeProject.

                  Simplicity is prerequisite for reliability. — Edsger W. Dijkstra

                  Regards, Sander

                  S Offline
                  S Offline
                  Slacker007
                  wrote on last edited by
                  #31

                  I was always taught that code comments are to describe a process your code is doing, if it is complex and not easily understood from the existing code base - otherwise, don't comment. It has served me well, all these years, so I stick with it...very minimal commenting in my code.

                  K 1 Reply Last reply
                  0
                  • T TheGreatAndPowerfulOz

                    I hate code comments that say what the code is doing but not why.

                    /* check for null */
                    if (someObj != null) {...}

                    Really? Argh!

                    #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                    C Offline
                    C Offline
                    Clifford Nelson
                    wrote on last edited by
                    #32

                    I have found that "50 Specific Ways to Improve Your C#" is really good, and one of the things that the author Bill Wagner points out is that your code should be self explanatory, and not require much in comments. Good variable names helps a lot.

                    T 1 Reply Last reply
                    0
                    • C Clifford Nelson

                      I have found that "50 Specific Ways to Improve Your C#" is really good, and one of the things that the author Bill Wagner points out is that your code should be self explanatory, and not require much in comments. Good variable names helps a lot.

                      T Offline
                      T Offline
                      TheGreatAndPowerfulOz
                      wrote on last edited by
                      #33

                      :thumbsup: And good function names/class names. And a alear breakdown of code into bitesized pieces. Aptly named.

                      #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                      C K 2 Replies Last reply
                      0
                      • T TheGreatAndPowerfulOz

                        I hate code comments that say what the code is doing but not why.

                        /* check for null */
                        if (someObj != null) {...}

                        Really? Argh!

                        #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                        Richard DeemingR Offline
                        Richard DeemingR Offline
                        Richard Deeming
                        wrote on last edited by
                        #34

                        This seems like suspiciously good timing: Documentation just before vacation | CommitStrip[^] :D


                        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                        T 1 Reply Last reply
                        0
                        • N Nish Nishant

                          The new approach (v6.0) is the null conditional operator, so you don't need to check for null.

                          someObj?.DoStuff();

                          Regards, Nish


                          Website: www.voidnish.com Blog: voidnish.wordpress.com

                          T Offline
                          T Offline
                          TheGreatAndPowerfulOz
                          wrote on last edited by
                          #35

                          I think that's what JSOP was referring to as the "bullsh|t operator".

                          #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                          N 1 Reply Last reply
                          0
                          • Richard DeemingR Richard Deeming

                            This seems like suspiciously good timing: Documentation just before vacation | CommitStrip[^] :D


                            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                            T Offline
                            T Offline
                            Tom Deketelaere
                            wrote on last edited by
                            #36

                            Damn you beat me to it by 15 min :)

                            Tom

                            1 Reply Last reply
                            0
                            • T TheGreatAndPowerfulOz

                              I think that's what JSOP was referring to as the "bullsh|t operator".

                              #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

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

                              Oops, I missed that. Sorry.

                              Regards, Nish


                              Website: www.voidnish.com Blog: voidnish.wordpress.com

                              1 Reply Last reply
                              0
                              • M Member 12345678

                                I am one of the other poor b*st*rd now. The original developers think their code is so beautiful and wonderful that no comment is needed to explain. They think I should ask if I do not understand. It will take longer than my lifetime to finish project this way.

                                M Offline
                                M Offline
                                Mark_Wallace
                                wrote on last edited by
                                #38

                                My sympathies. Been there, hated it. Look at the bright side, though: if the job were too easy, you'd get bored. Mind you, the jury's still out on which of bored and tearing-your-hair-out-in-frustration is worse.

                                I wanna be a eunuchs developer! Pass me a bread knife!

                                1 Reply Last reply
                                0
                                • T TheGreatAndPowerfulOz

                                  :thumbsup: And good function names/class names. And a alear breakdown of code into bitesized pieces. Aptly named.

                                  #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                                  C Offline
                                  C Offline
                                  Clifford Nelson
                                  wrote on last edited by
                                  #39

                                  Yes. That and using good encapsulation. On one project they passed all 3-d point vectors as separate arguments. They also had 1000+ line methods.

                                  K 1 Reply Last reply
                                  0
                                  • T TheGreatAndPowerfulOz

                                    I hate code comments that say what the code is doing but not why.

                                    /* check for null */
                                    if (someObj != null) {...}

                                    Really? Argh!

                                    #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                                    E Offline
                                    E Offline
                                    Eric Whitmore
                                    wrote on last edited by
                                    #40

                                    Documentation just before vacation | CommitStrip[^]

                                    Eric

                                    1 Reply Last reply
                                    0
                                    • N Nish Nishant

                                      The new approach (v6.0) is the null conditional operator, so you don't need to check for null.

                                      someObj?.DoStuff();

                                      Regards, Nish


                                      Website: www.voidnish.com Blog: voidnish.wordpress.com

                                      K Offline
                                      K Offline
                                      kalberts
                                      wrote on last edited by
                                      #41

                                      Often, in cases like that, you could very well add a comment indicating why the ojbect reference would be null (or non-null). Not always, but often. When studying code written by others, one of the questions I frequently as myself is of the kind "OK, so I understand that you can't Do Stuff on a null object, but in which cases is the object null?? A short end-of-line comment such as 'null if child hasn't been named yet' or 'null if cleanup actions are already performed' can be worth their weight in gold.

                                      1 Reply Last reply
                                      0
                                      • T TheGreatAndPowerfulOz

                                        I hate code comments that say what the code is doing but not why.

                                        /* check for null */
                                        if (someObj != null) {...}

                                        Really? Argh!

                                        #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                                        C Offline
                                        C Offline
                                        Cloud William
                                        wrote on last edited by
                                        #42

                                        Back in the Dark Ages, I worked with DEC's RT-11 operating system. It was written in PDP-11 assembler. I had the opportunity to look at the commented source code, and I remember the following line:

                                        NOP    # We don't know why it's here, but it doesn't work without it.
                                        

                                        In a proprietary OS. From the manufacturer of the CPU. Sometimes commentary will reveal far more than you ever wanted to know.

                                        Freedom? That is a worship word. -- Cloud William The only thing a free man can be forced to do is die.

                                        K 1 Reply Last reply
                                        0
                                        • T TheGreatAndPowerfulOz

                                          :thumbsup: And good function names/class names. And a alear breakdown of code into bitesized pieces. Aptly named.

                                          #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

                                          K Offline
                                          K Offline
                                          kalberts
                                          wrote on last edited by
                                          #43

                                          Reminding me of a fellow student (long, long time ago!) writing his programs using variable names like I001, I002,... F001, F002 (for floating point values). Before handing in the exercise he would to a global replacement of, say, I001 with 'NumberOfEggsPerBox' or someting like that. Writing those long names while developing the program would require too much typing, he argued. Also it served as a limited 'copy protection'. It was too easy in those days to access the work of fellow students, to use as a basis for your own exercise solution. Martin never had his half-finished work 'stolen' - understanding it (before the last-minute variable name replacement) required as much effort as developing your own solution.

                                          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