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. Other Discussions
  3. The Weird and The Wonderful
  4. Over-documentation

Over-documentation

Scheduled Pinned Locked Moved The Weird and The Wonderful
performance
25 Posts 16 Posters 0 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.
  • P PIEBALDconsult

    You'd think they'd spell check it. :rolleyes:

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

    I see not speelign errors! :laugh: Mind you, I like the quotes round "compiler" - as if they aren't quite sure it is a compiler, it might be a fridge or something like that... I do rely on spell checkers a lot - I even have a VS extension for string and comment checking - but I like the Chrome one, especially when it picks up grammar problems! :-D

    The only instant messaging I do involves my middle finger. English doesn't borrow from other languages. English follows other languages down dark alleys, knocks them over and goes through their pockets for loose grammar.

    "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

    P 1 Reply Last reply
    0
    • R Ron Beyer

      This is from another forum I visit once in a while, somebody posting a code snippet:

      void loop(){
      byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
      byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
      rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte

      if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
      {
      switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
      // 'switches' based on that byte
      {

      And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)

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

      The real question is where should commenting stop? I have some coworkers who comment .NET functions and classes that we don't use a lot. Especially when it's more complex and intellisense alone won't help you a lot. Just assume we don't use strings a lot. It would be something like:

      // A string is used to store some text.
      string s = "Hello!";

      Someone at our company might not know what a string is (after all, we rarely use it (in this example)), so this will save them a quick Google lookup. At the other hand, is it really our job to document .NET classes? Your example is clearly a little too much though! :laugh::thumbsup:

      It's an OO world.

      public class Sander : Lazy<Person>{
      public void DoWork(){ throw new NotImplementedException(); }
      }

      R 1 Reply Last reply
      0
      • Sander RosselS Sander Rossel

        The real question is where should commenting stop? I have some coworkers who comment .NET functions and classes that we don't use a lot. Especially when it's more complex and intellisense alone won't help you a lot. Just assume we don't use strings a lot. It would be something like:

        // A string is used to store some text.
        string s = "Hello!";

        Someone at our company might not know what a string is (after all, we rarely use it (in this example)), so this will save them a quick Google lookup. At the other hand, is it really our job to document .NET classes? Your example is clearly a little too much though! :laugh::thumbsup:

        It's an OO world.

        public class Sander : Lazy<Person>{
        public void DoWork(){ throw new NotImplementedException(); }
        }

        R Offline
        R Offline
        Ron Beyer
        wrote on last edited by
        #5

        I would say if the people working on your code can't put the caret in the middle of "string" (or whatever you are using) and hit F1 to read the MSDN documentation, they probably shouldn't be messing around in the code base. There are a lot of theories about how to document code, and here's mine: 1. Classes, methods, and properties (public especially, but all really), should be documented using the built-in /// method, with at least the summary and parameter explanations, remarks should be added if there is more, and document the exceptions that the method throws. This makes the other developers life easier (in Intellisense and later when you generate API documentation) to understand what a class/method/property is for. 2. Internal documentation (inside methods), generally skip it. There are three (main) reasons why somebody would document inside a function, (a) its complicated or (b) its long. If either of these are the case, it should be refactored. If the purpose of the function is sufficiently documented and the developer is qualified to work on it, the interior doesn't need to be documented. (There are of course rare exceptions, such as documenting bug work-arounds which if the developer didn't have knowledge of the bug, the code wouldn't make sense). The other reason (c) why people put comments in functions is generally white-noise. They are documenting the thought process which is unnecessary. A proper description of the input/output of the function and it being correctly "factored" shouldn't require knowing the developers thought process as they wrote it. When you see that they are probably doing "design by code", or "code-first", I won't get into that... I used to be in the school of "every line should be documented", but I learned that really the comments where only there for the sake of writing the code, when I was debugging it I never looked at the comments again. It was more of "thinking out loud" than anything. Since adopting my method, I write cleaner, less cluttered code...

        Sander RosselS E 2 Replies Last reply
        0
        • OriginalGriffO OriginalGriff

          I see not speelign errors! :laugh: Mind you, I like the quotes round "compiler" - as if they aren't quite sure it is a compiler, it might be a fridge or something like that... I do rely on spell checkers a lot - I even have a VS extension for string and comment checking - but I like the Chrome one, especially when it picks up grammar problems! :-D

          The only instant messaging I do involves my middle finger. English doesn't borrow from other languages. English follows other languages down dark alleys, knocks them over and goes through their pockets for loose grammar.

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

          "the the code"

          OriginalGriffO M 2 Replies Last reply
          0
          • P PIEBALDconsult

            "the the code"

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

            A pure spelling checker wouldn't spot that - you need a grammar checker as each word is correctly spelled. And yes, I missed it completely! :laugh:

            The only instant messaging I do involves my middle finger. English doesn't borrow from other languages. English follows other languages down dark alleys, knocks them over and goes through their pockets for loose grammar.

            "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

            1 Reply Last reply
            0
            • R Ron Beyer

              This is from another forum I visit once in a while, somebody posting a code snippet:

              void loop(){
              byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
              byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
              rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte

              if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
              {
              switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
              // 'switches' based on that byte
              {

              And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)

              D Offline
              D Offline
              dan sh
              wrote on last edited by
              #8

              Are there incentives based on code file size wherever this guy works? I can write brilliant stories and make insane money then. Seriously, this is painful. If one needs this much commenting to understand what the code does, he should rather stay away from it.

              "Bastards encourage idiots to use Oracle Forms, Web Forms, Access and a number of other dinky web publishing tolls.", Mycroft Holmes[^]

              R 1 Reply Last reply
              0
              • R Ron Beyer

                I would say if the people working on your code can't put the caret in the middle of "string" (or whatever you are using) and hit F1 to read the MSDN documentation, they probably shouldn't be messing around in the code base. There are a lot of theories about how to document code, and here's mine: 1. Classes, methods, and properties (public especially, but all really), should be documented using the built-in /// method, with at least the summary and parameter explanations, remarks should be added if there is more, and document the exceptions that the method throws. This makes the other developers life easier (in Intellisense and later when you generate API documentation) to understand what a class/method/property is for. 2. Internal documentation (inside methods), generally skip it. There are three (main) reasons why somebody would document inside a function, (a) its complicated or (b) its long. If either of these are the case, it should be refactored. If the purpose of the function is sufficiently documented and the developer is qualified to work on it, the interior doesn't need to be documented. (There are of course rare exceptions, such as documenting bug work-arounds which if the developer didn't have knowledge of the bug, the code wouldn't make sense). The other reason (c) why people put comments in functions is generally white-noise. They are documenting the thought process which is unnecessary. A proper description of the input/output of the function and it being correctly "factored" shouldn't require knowing the developers thought process as they wrote it. When you see that they are probably doing "design by code", or "code-first", I won't get into that... I used to be in the school of "every line should be documented", but I learned that really the comments where only there for the sake of writing the code, when I was debugging it I never looked at the comments again. It was more of "thinking out loud" than anything. Since adopting my method, I write cleaner, less cluttered code...

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

                I have some thoughts on commenting as well. I even wrote a tip about it. Write comments that matter[^], you might like it :)

                It's an OO world.

                public class Sander : Lazy<Person>{
                public void DoWork(){ throw new NotImplementedException(); }
                }

                1 Reply Last reply
                0
                • D dan sh

                  Are there incentives based on code file size wherever this guy works? I can write brilliant stories and make insane money then. Seriously, this is painful. If one needs this much commenting to understand what the code does, he should rather stay away from it.

                  "Bastards encourage idiots to use Oracle Forms, Web Forms, Access and a number of other dinky web publishing tolls.", Mycroft Holmes[^]

                  R Offline
                  R Offline
                  Ron Beyer
                  wrote on last edited by
                  #10

                  Fortunately (and this probably explains a lot), the site is for hobbyist coding (this particular code is for running on an Arduino). I'm hoping that the guy who wrote it has a day job as a technical writer or something :)

                  1 Reply Last reply
                  0
                  • R Ron Beyer

                    This is from another forum I visit once in a while, somebody posting a code snippet:

                    void loop(){
                    byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
                    byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
                    rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte

                    if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
                    {
                    switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
                    // 'switches' based on that byte
                    {

                    And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)

                    B Offline
                    B Offline
                    Bernhard Hiller
                    wrote on last edited by
                    #11

                    I've read about paying developers for the number of lines in their code files. But he does not use an extra line for the comment. Does he get paid by character?

                    1 Reply Last reply
                    0
                    • R Ron Beyer

                      This is from another forum I visit once in a while, somebody posting a code snippet:

                      void loop(){
                      byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
                      byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
                      rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte

                      if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
                      {
                      switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
                      // 'switches' based on that byte
                      {

                      And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)

                      E Offline
                      E Offline
                      ENOTTY
                      wrote on last edited by
                      #12

                      What's with the scare quotes?

                      1 Reply Last reply
                      0
                      • R Ron Beyer

                        I would say if the people working on your code can't put the caret in the middle of "string" (or whatever you are using) and hit F1 to read the MSDN documentation, they probably shouldn't be messing around in the code base. There are a lot of theories about how to document code, and here's mine: 1. Classes, methods, and properties (public especially, but all really), should be documented using the built-in /// method, with at least the summary and parameter explanations, remarks should be added if there is more, and document the exceptions that the method throws. This makes the other developers life easier (in Intellisense and later when you generate API documentation) to understand what a class/method/property is for. 2. Internal documentation (inside methods), generally skip it. There are three (main) reasons why somebody would document inside a function, (a) its complicated or (b) its long. If either of these are the case, it should be refactored. If the purpose of the function is sufficiently documented and the developer is qualified to work on it, the interior doesn't need to be documented. (There are of course rare exceptions, such as documenting bug work-arounds which if the developer didn't have knowledge of the bug, the code wouldn't make sense). The other reason (c) why people put comments in functions is generally white-noise. They are documenting the thought process which is unnecessary. A proper description of the input/output of the function and it being correctly "factored" shouldn't require knowing the developers thought process as they wrote it. When you see that they are probably doing "design by code", or "code-first", I won't get into that... I used to be in the school of "every line should be documented", but I learned that really the comments where only there for the sake of writing the code, when I was debugging it I never looked at the comments again. It was more of "thinking out loud" than anything. Since adopting my method, I write cleaner, less cluttered code...

                        E Offline
                        E Offline
                        ENOTTY
                        wrote on last edited by
                        #13

                        In general, I agree with you, the exception being concise^Wtoo clever for their own good LINQ expressions like these:

                        ' enumerate Future Queries (go to DB in one request), put resulting KatalogIds into HashSets
                        Dim katalogErrorResults As Dictionary(Of KatalogErrorType, HashSet(Of Int32?))
                        katalogErrorResults = katalogErrorFutures _
                        .AsEnumerable() _
                        .Select(Function(katErr) _
                        New KeyValuePair(Of KatalogErrorType, HashSet(Of Int32?)) _
                        (katErr.Key, katErr.Value.ToHashSet)) _
                        .ToDictionary(Of KatalogErrorType, HashSet(Of Int32?)) _
                        (Function(kvp) kvp.Key, Function(kvp) kvp.Value, katalogErrorTypeComparer)

                        ' transform results to Dictionary(Of Int32?, KatalogErrorDTO)
                        Return katalogeIds.ToDictionary(
                        Function(sourceKatId) sourceKatId,
                        Function(sourceKatId) New KatalogErrorDTO() With { _
                        .ArtikelNummerPrefix = artikelNummerPrefix,
                        .SearchQuery = searchquery,
                        .Errors = [Enum].GetValues(GetType(KatalogErrorType)) _
                        .Cast(Of KatalogErrorType) _
                        .ToDictionary(Function(kErrorType) kErrorType, _
                        Function(kErrorType) katalogErrorResults(kErrorType) _
                        .Contains(sourceKatId)) _
                        })

                        R 1 Reply Last reply
                        0
                        • E ENOTTY

                          In general, I agree with you, the exception being concise^Wtoo clever for their own good LINQ expressions like these:

                          ' enumerate Future Queries (go to DB in one request), put resulting KatalogIds into HashSets
                          Dim katalogErrorResults As Dictionary(Of KatalogErrorType, HashSet(Of Int32?))
                          katalogErrorResults = katalogErrorFutures _
                          .AsEnumerable() _
                          .Select(Function(katErr) _
                          New KeyValuePair(Of KatalogErrorType, HashSet(Of Int32?)) _
                          (katErr.Key, katErr.Value.ToHashSet)) _
                          .ToDictionary(Of KatalogErrorType, HashSet(Of Int32?)) _
                          (Function(kvp) kvp.Key, Function(kvp) kvp.Value, katalogErrorTypeComparer)

                          ' transform results to Dictionary(Of Int32?, KatalogErrorDTO)
                          Return katalogeIds.ToDictionary(
                          Function(sourceKatId) sourceKatId,
                          Function(sourceKatId) New KatalogErrorDTO() With { _
                          .ArtikelNummerPrefix = artikelNummerPrefix,
                          .SearchQuery = searchquery,
                          .Errors = [Enum].GetValues(GetType(KatalogErrorType)) _
                          .Cast(Of KatalogErrorType) _
                          .ToDictionary(Function(kErrorType) kErrorType, _
                          Function(kErrorType) katalogErrorResults(kErrorType) _
                          .Contains(sourceKatId)) _
                          })

                          R Offline
                          R Offline
                          Ron Beyer
                          wrote on last edited by
                          #14

                          Some LINQ queries are more like when people first discover the ? : conditional operator and you start seeing nested inline conditionals like firstvar == somevalue ? ((myvalue1 + 10) <= 4 ? : false : true) : false Or something worse than that. Your query above could be refactored to be much more clear, therefore removing the need for concise comments. If the above were broken down into individual lines (instead of using a new line and the "."), along with not inline defining the function, it would be easy to understand, and even easier to debug. This is where my problem with "fluent" language extensions come in, while fluent reads more like English, the formatting/extras required to get it to look that way generally obscures the intent.

                          1 Reply Last reply
                          0
                          • R Ron Beyer

                            This is from another forum I visit once in a while, somebody posting a code snippet:

                            void loop(){
                            byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
                            byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
                            rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte

                            if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
                            {
                            switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
                            // 'switches' based on that byte
                            {

                            And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)

                            C Offline
                            C Offline
                            CPallini
                            wrote on last edited by
                            #15

                            Ron Beyer wrote:

                            At least we know what the 'compiler' is doing when you declare a variable

                            Sure, we need certainties, after all! :laugh:

                            Veni, vidi, vici.

                            1 Reply Last reply
                            0
                            • R Ron Beyer

                              This is from another forum I visit once in a while, somebody posting a code snippet:

                              void loop(){
                              byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
                              byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
                              rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte

                              if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
                              {
                              switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
                              // 'switches' based on that byte
                              {

                              And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)

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

                              Ron Beyer wrote:

                              At least we know what the 'compiler' is doing when you declare a variable

                              Actually, it's not even accurate, technically. The compiler doesn't allocate "some memory", it reserves space on the stack when the function is called. Yes, the stack is of course memory, but it's not the same kind of memory one uses when allocating / deallocating. Marc

                              Day 1: Spider Database Navigator Unit Testing Succinctly

                              1 Reply Last reply
                              0
                              • R Ron Beyer

                                This is from another forum I visit once in a while, somebody posting a code snippet:

                                void loop(){
                                byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
                                byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
                                rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte

                                if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
                                {
                                switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
                                // 'switches' based on that byte
                                {

                                And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)

                                W Offline
                                W Offline
                                Worried Brown Eyes
                                wrote on last edited by
                                #17

                                Lovely Not only way over the top, but where comments would be useful, those comments aren't. I would only put 1 comment in there - //254 means we are about to process a command, so read one & process it. Plus a comment to add a description of each entry in the switch statement to translate the number into something sensible. This removes clutter, and also the need to look up op-codes in the event of brain-fade. Regards, Stewart

                                R 1 Reply Last reply
                                0
                                • W Worried Brown Eyes

                                  Lovely Not only way over the top, but where comments would be useful, those comments aren't. I would only put 1 comment in there - //254 means we are about to process a command, so read one & process it. Plus a comment to add a description of each entry in the switch statement to translate the number into something sensible. This removes clutter, and also the need to look up op-codes in the event of brain-fade. Regards, Stewart

                                  R Offline
                                  R Offline
                                  Ron Beyer
                                  wrote on last edited by
                                  #18

                                  All of those can be solved with compiler constants, for example: #define CMDSTART 254 #define READCMD 1 #define WRITECMD 2 etc... Which also eliminates "magic numbers" and makes the program more maintainable.

                                  1 Reply Last reply
                                  0
                                  • R Ron Beyer

                                    This is from another forum I visit once in a while, somebody posting a code snippet:

                                    void loop(){
                                    byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
                                    byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
                                    rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte

                                    if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
                                    {
                                    switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
                                    // 'switches' based on that byte
                                    {

                                    And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)

                                    S Offline
                                    S Offline
                                    StM0n
                                    wrote on last edited by
                                    #19

                                    So... I guess, there's a comment like

                                    //Captain Obvious was here. Obviously.

                                    (yes|no|maybe)*

                                    1 Reply Last reply
                                    0
                                    • P PIEBALDconsult

                                      "the the code"

                                      M Offline
                                      M Offline
                                      Max Methot
                                      wrote on last edited by
                                      #20

                                      Reminds me of this! [^]

                                      P 1 Reply Last reply
                                      0
                                      • M Max Methot

                                        Reminds me of this! [^]

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

                                        The first time I saw something like that said "Paris in the / the spring". I saw this[^] sign a couple of weeks ago at http://en.wikipedia.org/wiki/Painted_Rocks_(Arizona)[^]

                                        1 Reply Last reply
                                        0
                                        • R Ron Beyer

                                          This is from another forum I visit once in a while, somebody posting a code snippet:

                                          void loop(){
                                          byte rxbyte; //this tells the 'compiler' to allocate some memory for a variable called rxbyte
                                          byte temp; //this tells the 'compiler' to allocate some memory for a variable called temp
                                          rxbyte = serial_getch(); //this calls the 'function' serial_getch(), stores result in rxbyte

                                          if (rxbyte == 254) //Matrix uses 254 for commands, if rxbyte = 254 the the code below runs
                                          {
                                          switch (serial_getch()) //calls serial_getch() to get the next byte from the PC
                                          // 'switches' based on that byte
                                          {

                                          And it continues on like that. At least we know what the 'compiler' is doing when you declare a variable :)

                                          R Offline
                                          R Offline
                                          Rob Grainger
                                          wrote on last edited by
                                          #22

                                          Amusingly, that doesn't really tell us much - the compiler doesn't "allocate" memory, the stack is allocated when the program starts - this simply updates stack pointers.

                                          "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                                          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