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. Legacy Code Documentation

Legacy Code Documentation

Scheduled Pinned Locked Moved The Lounge
question
38 Posts 21 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.
  • K kmoorevs

    MarcusCole6833 wrote:

    Is the code documenting itself good enough?

    I am personally a big fan of using descriptive variables such that the code becomes self-explanatory. I also have a standard set of names for common-use objects that could incriminate identify me as the author. Edit: That said, when the intent is not clear, or you/they are doing something 'clever', then documenting/commenting is encouraged. Comments may or may not get updated, but the code doesn't lie. :laugh:

    "Go forth into the source" - Neal Morse "Hope is contagious"

    J Offline
    J Offline
    Jeremy Falcon
    wrote on last edited by
    #18

    kmoorevs wrote:

    Comments may or may not get updated, but the code doesn't lie. :laugh:

    Unless that code is being refactored and the naming butchered by some other dev. While I do agree good naming is important, it doesn't remove the need for comments completely. Blanket statements is typically the tell tale sign of the inexperienced.

    Jeremy Falcon

    1 Reply Last reply
    0
    • T trønderen

      Most developer document the wrong things. Far too often, they repeat what the code line says, whether like "Here we set i to the value 5" or repeat the parameters of the method heading, "explaining" e.g. "numberOfApples: The number of apples". Or, when asked for more high level, code independent documentation, they present a block chart with Application, Database and Network modules. What other developers need lies in between: A documentation of the purpose of each code module, of its interaction with other modules. Replace 'module' with 'class' as appropriate. The data structures - how they are interlocked, what they represent as a whole - that usually means, across several object classes. To draw a line: I want off line - in the sense: off the code lines - documentation to go down to the deepest level where it is still independent of the programming language. You should be able to build those modules, those data structures, in Python, in C++, even in Visual Basic. You document the interfaces between modules, not only the syntax (name, parameters) but the dynamics as well. That will help the next code maintainer on the right track! And, these interactions are far more stable than the individual code lines; you can make a lot of changes without invalidating the documentation. Every now and then it may need to be extended with new interactions or parameter options, yet all the old stuff remains valid. When you get down to code, you may of course add code comments - but without repeating the off code line documentation; there is no need to. Obviously, you should avoid 'Here we set i to 5' style comments, and you should use descriptive type and variable names. When you delete code lines, you delete the accompanying comments. When you change code lines, you change the accompanying comments. End-of-line comments (lined up at col. 70 or 80 not to blur the code) is a lot better for keeping them up to date than pushing them to the top of the method. But these code comments are far less essential. You read them after you have studied all the off line documentation, and know the interactions, the data structures, the interfaces. What is left is to understand how these interfaces are realized, within a single module/class. That is usually a far simpler task than grokking the structure of the entire program system as a whole. I do like to have (i.e. both make and read) code comments, but if I could have a choice between code comments and a system documentation from immediately

      C Offline
      C Offline
      charlieg
      wrote on last edited by
      #19

      that's pretty religious ;) Seems to me a bit of a pet peeve of yours. Mine as well. I'll swing this in a different direction. There are a few people I've worked with that I term "whiz kids." Their minds work so fast, 5x faster than mine, that everything is intuitively obvious. Not one damn line of comments. No doc to save anyone's lives, nothing. I simply gave up. I completely concur about not documenting loops and i++, but module level comments are necessary. And ffs, tie the code comments back to external documentation. Now, 40 years later, no one gives an elephant. I've worked at (counting....) 9 companies and myself, and there is only one person I can count on to write proper documentation. It's simply pathetic.

      Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

      J 1 Reply Last reply
      0
      • C charlieg

        that's pretty religious ;) Seems to me a bit of a pet peeve of yours. Mine as well. I'll swing this in a different direction. There are a few people I've worked with that I term "whiz kids." Their minds work so fast, 5x faster than mine, that everything is intuitively obvious. Not one damn line of comments. No doc to save anyone's lives, nothing. I simply gave up. I completely concur about not documenting loops and i++, but module level comments are necessary. And ffs, tie the code comments back to external documentation. Now, 40 years later, no one gives an elephant. I've worked at (counting....) 9 companies and myself, and there is only one person I can count on to write proper documentation. It's simply pathetic.

        Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

        J Offline
        J Offline
        jana_hus
        wrote on last edited by
        #20

        Contrary to my last(vastly misunderstood post), this is not apparent, it simply is (for real). I am an OF and have noticed how "newer generations" choose NOT to use (simple) old, proven methods , stuff. My manager did not use AI or RTFM - his "comment or else " was based on "what will happen if you get run over by a bus and your code is not documented / commented?" For those hard of hearing - undocumented / uncommented code was against company interest, period. I am not a wiz kid, but if the code task is to test HARDWARE , CLOSE TO REAL TIME, and if the code is not documented , commented AND is missing ANY time reference - it will not "just " APPARENTLY fail - it will fail for sure. IMHO self documented code is oxymoron

        C 1 Reply Last reply
        0
        • S snorkie

          Never trust documentation. There is no guarantee the last developer updated it when they changed the code. You can read it as a guide. So trust, but verify.

          Hogan

          J Offline
          J Offline
          jmaida
          wrote on last edited by
          #21

          ditto Snorkie

          Going on 40 yrs of reading, writing, editing code, both mine and others. Could not agree more.

          "A little time, a little trouble, your better day" Badfinger

          1 Reply Last reply
          0
          • M MarcusCole6833

            Questions Is it Maintained? Do you look for it or just explore the code? What do you do if it is not there? Is the code documenting itself good enough?

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

            All documentation is out of date as soon as it's written. Code is never out of date.

            1 Reply Last reply
            0
            • S snorkie

              Never trust documentation. There is no guarantee the last developer updated it when they changed the code. You can read it as a guide. So trust, but verify.

              Hogan

              H Offline
              H Offline
              honey the codewitch
              wrote on last edited by
              #23

              I hate that, and it's why I lean toward not commenting, and expressing intent through code, wherever I can. Comments are a curse, even if they're sometimes necessary.

              Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

              S M 2 Replies Last reply
              0
              • M MarcusCole6833

                Questions Is it Maintained? Do you look for it or just explore the code? What do you do if it is not there? Is the code documenting itself good enough?

                P Offline
                P Offline
                Peter Jamieson
                wrote on last edited by
                #24

                Is it really just the code, or a whole system? If a whole system, check and/or create a high-level overview, even if it "should be obvious" and make sure you have the documentation necessary to make a change, rebuild, test, distribute and install. (I.e. you have to go through that process to be sure it works). As for code, depends partly on how much expertise in the coding language(s) you think will be available if a change is necessary, particularly if people have used unusual language features or coded in an unusual way compared to "normal industry practice" - perhaps make a few general remarks noting such stuff.

                C 1 Reply Last reply
                0
                • J jana_hus

                  Contrary to my last(vastly misunderstood post), this is not apparent, it simply is (for real). I am an OF and have noticed how "newer generations" choose NOT to use (simple) old, proven methods , stuff. My manager did not use AI or RTFM - his "comment or else " was based on "what will happen if you get run over by a bus and your code is not documented / commented?" For those hard of hearing - undocumented / uncommented code was against company interest, period. I am not a wiz kid, but if the code task is to test HARDWARE , CLOSE TO REAL TIME, and if the code is not documented , commented AND is missing ANY time reference - it will not "just " APPARENTLY fail - it will fail for sure. IMHO self documented code is oxymoron

                  C Offline
                  C Offline
                  charlieg
                  wrote on last edited by
                  #25

                  What is an OF, and more to the point, what other post? Inquiring minds want to know (I looked at the thread, and this is your first post). But, I completely agree with your comment.

                  Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

                  J 1 Reply Last reply
                  0
                  • P Peter Jamieson

                    Is it really just the code, or a whole system? If a whole system, check and/or create a high-level overview, even if it "should be obvious" and make sure you have the documentation necessary to make a change, rebuild, test, distribute and install. (I.e. you have to go through that process to be sure it works). As for code, depends partly on how much expertise in the coding language(s) you think will be available if a change is necessary, particularly if people have used unusual language features or coded in an unusual way compared to "normal industry practice" - perhaps make a few general remarks noting such stuff.

                    C Offline
                    C Offline
                    charlieg
                    wrote on last edited by
                    #26

                    THIS!!! Code does not exist on it's own. It was written to solve a problem. If you don't tie the code back to the problem, you lose context. Sometimes this is called tribal knowledge. I'm watching an organization bleed to death, but the multinational corp above it is oblivious. As my boss told me, it's not up to you to help a multi-billion dollar company fix their stupidity. 2 weeks later, I jumped out of the plane (with a parachute) and retired. It's been two months now, and I have not received a single email. :)

                    Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

                    1 Reply Last reply
                    0
                    • H honey the codewitch

                      I hate that, and it's why I lean toward not commenting, and expressing intent through code, wherever I can. Comments are a curse, even if they're sometimes necessary.

                      Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                      S Offline
                      S Offline
                      snorkie
                      wrote on last edited by
                      #27

                      There is a reasonable balance between documenting something and the overly detailed documentation that is likely to get out of date. I like the "here is a new thing and here is the general pattern of how it works" type of documentation. Code comments are reserved for "I know this is stupid, but users." And references to Kelly Clarkson to make the other devs laugh when they read my code. We have to have some fun around here.

                      Hogan

                      1 Reply Last reply
                      0
                      • J Jeremy Falcon

                        MarcusCole6833 wrote:

                        Is it Maintained?

                        Legacy code or not, if the code is updated the docs for it should be updated.

                        MarcusCole6833 wrote:

                        Do you look for it or just explore the code?

                        It should be a part of the code. jsdoc or doxygen style comments should be littered all throughout the code. There should also be READMEs in the project. No point in having to hunt down an external resource that would only get stale.

                        MarcusCole6833 wrote:

                        What do you do if it is not there?

                        Ask why it's not there with the original devs. If I'm now responsible for said legacy code and if there is some documentation somewhere then I'll try and add it to the project.

                        MarcusCole6833 wrote:

                        Is the code documenting itself good enough?

                        No. This goes back to the age old "what makes a good comment" issue. People that say code is always self-documenting are just wrong. They've never worked with other humans and certainly was never a professional dev. What makes a good comment? Not stuff like this:

                        // set x to 5
                        let x = 5;

                        Well no duh. That is self-documenting and obvious, but stuff like this always isn't:

                        // keep the raw data for these, also bands should use the population
                        const average = [...simpleMovingAverage(sample, range)].pop()?.actual ?? 0 as Price;
                        const band = standardDeviation(sample.map((x: Market) => x.close), true).actual * deviations;

                        Not everyone maintaining the code may know off the top of their head the note about how something should be implemented. One could argue RTFM, but let's be realistic... people maintaining code do not Google every last line of code. Also, there may be no well-known manual for some things. It's easy for someone to "fix" it and break it and even get past a PR. So, when you do something that may be considered unusual or haphazard or just only known by a select few having a comment should present to make it explicit. As such, I don't consider code always self-documenting in the real world.

                        Jeremy Falcon

                        C Offline
                        C Offline
                        CHill60
                        wrote on last edited by
                        #28

                        Quote:

                        People that say code is always self-documenting are just wrong. They've never worked with other humans and certainly was never a professional dev.

                        Thank you, thank you, thank you! I've lost count of the number of arguments I've had about this. I've also lost count of the number times I've gone into my own code after some time and silently thanked Earlier Me for comments like

                        //Outputs have to match previous provider, so yes, converting this number to text here is correct

                        and

                        'NB loop starting at 1 is deliberate to skip headers

                        I used to often include links to Sharepoint documents in comments. Stopped doing that after a company "rationalised" their document storage (euphemism for moved to different provider and did not migrate all documents)

                        J 1 Reply Last reply
                        0
                        • H honey the codewitch

                          I hate that, and it's why I lean toward not commenting, and expressing intent through code, wherever I can. Comments are a curse, even if they're sometimes necessary.

                          Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                          M Offline
                          M Offline
                          Matt Bond
                          wrote on last edited by
                          #29

                          In code reviews, I tell the developers to remove all comments except ones that explain _why_ we needed to do something. The _what_ should be evident from reading the code. The worse comments are ones that only re-phrase the name of the class or method. I deal with 30 year old code that is still being updated and maintained. You can tell lots of different programmers had their hands in the pot and not all of it is good code. For the first 20 years, no code reviews were done. I'm the last person on the team with more than 3 years experience (I have 24 years) on this codebase. If I leave, then they would be so lost in a lot of areas of the code. There is no way we could document all of it at this point.

                          Bond Keep all things as simple as possible, but no simpler. -said someone, somewhere

                          I 1 Reply Last reply
                          0
                          • M Matt Bond

                            In code reviews, I tell the developers to remove all comments except ones that explain _why_ we needed to do something. The _what_ should be evident from reading the code. The worse comments are ones that only re-phrase the name of the class or method. I deal with 30 year old code that is still being updated and maintained. You can tell lots of different programmers had their hands in the pot and not all of it is good code. For the first 20 years, no code reviews were done. I'm the last person on the team with more than 3 years experience (I have 24 years) on this codebase. If I leave, then they would be so lost in a lot of areas of the code. There is no way we could document all of it at this point.

                            Bond Keep all things as simple as possible, but no simpler. -said someone, somewhere

                            I Offline
                            I Offline
                            iplaykeys
                            wrote on last edited by
                            #30

                            This is my preference as well. Syntax can be googled, internal business process and reasoning cannot.

                            1 Reply Last reply
                            0
                            • C CHill60

                              Quote:

                              People that say code is always self-documenting are just wrong. They've never worked with other humans and certainly was never a professional dev.

                              Thank you, thank you, thank you! I've lost count of the number of arguments I've had about this. I've also lost count of the number times I've gone into my own code after some time and silently thanked Earlier Me for comments like

                              //Outputs have to match previous provider, so yes, converting this number to text here is correct

                              and

                              'NB loop starting at 1 is deliberate to skip headers

                              I used to often include links to Sharepoint documents in comments. Stopped doing that after a company "rationalised" their document storage (euphemism for moved to different provider and did not migrate all documents)

                              J Offline
                              J Offline
                              Jeremy Falcon
                              wrote on last edited by
                              #31

                              CHill60 wrote:

                              I've gone into my own code after some time and silently thanked Earlier Me for comments like

                              Same :laugh: :laugh: :laugh:

                              Jeremy Falcon

                              1 Reply Last reply
                              0
                              • M MarcusCole6833

                                Questions Is it Maintained? Do you look for it or just explore the code? What do you do if it is not there? Is the code documenting itself good enough?

                                D Offline
                                D Offline
                                Dr Walt Fair PE
                                wrote on last edited by
                                #32

                                I just got a copy of some Fortran code I wrote in 1982. Thankfully, I put in a lot of comments. Sadly, I was missing one crucial comment, but I figured it out in about 10 hours. CQ de W5ALT

                                Walt Fair, Jr.PhD P. E. Comport Computing Specializing in Technical Engineering Software

                                T 1 Reply Last reply
                                0
                                • C charlieg

                                  What is an OF, and more to the point, what other post? Inquiring minds want to know (I looked at the thread, and this is your first post). But, I completely agree with your comment.

                                  Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

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

                                  OF = Old Fogey (or some ruder word that starts with F.)

                                  C 1 Reply Last reply
                                  0
                                  • D Dr Walt Fair PE

                                    I just got a copy of some Fortran code I wrote in 1982. Thankfully, I put in a lot of comments. Sadly, I was missing one crucial comment, but I figured it out in about 10 hours. CQ de W5ALT

                                    Walt Fair, Jr.PhD P. E. Comport Computing Specializing in Technical Engineering Software

                                    T Offline
                                    T Offline
                                    trønderen
                                    wrote on last edited by
                                    #34

                                    Old guru Tony Hoare remarked after reviewing the various proposals for Fortran-77 extensions (some of them went quite far, to phrase it in a polite manner): "I don't know what programming languages will look like in the year 2000, but I know that they will be named 'Fortran'." When I first saw code written to the Fortran-2003 standard, my immediate reaction was: Hoare was right! So my curious question is: How did your 1982 vintage Fortran code fare with a 2024 vintage Fortran compiler? (Fortran 77 was so much delayed that the '77' is a misnomer, so I wouldn't be surprised if 1982 vintage code is not even by the F77 standard.)

                                    Religious freedom is the freedom to say that two plus two make five.

                                    D C 2 Replies Last reply
                                    0
                                    • T trønderen

                                      Old guru Tony Hoare remarked after reviewing the various proposals for Fortran-77 extensions (some of them went quite far, to phrase it in a polite manner): "I don't know what programming languages will look like in the year 2000, but I know that they will be named 'Fortran'." When I first saw code written to the Fortran-2003 standard, my immediate reaction was: Hoare was right! So my curious question is: How did your 1982 vintage Fortran code fare with a 2024 vintage Fortran compiler? (Fortran 77 was so much delayed that the '77' is a misnomer, so I wouldn't be surprised if 1982 vintage code is not even by the F77 standard.)

                                      Religious freedom is the freedom to say that two plus two make five.

                                      D Offline
                                      D Offline
                                      Dr Walt Fair PE
                                      wrote on last edited by
                                      #35

                                      trønderen wrote: o my curious question is: How did your 1982 vintage Fortran code fare with a 2024 vintage Fortran compiler? I was translating the code to C#, so there was no problem, except I wonder if I had a brain 46 years ago. CQ de W5ALT

                                      Walt Fair, Jr.PhD P. E. Comport Computing Specializing in Technical Engineering Software

                                      1 Reply Last reply
                                      0
                                      • J Joe Fallon

                                        OF = Old Fogey (or some ruder word that starts with F.)

                                        C Offline
                                        C Offline
                                        charlieg
                                        wrote on last edited by
                                        #36

                                        oops :) yeah I have that shirt.

                                        Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

                                        1 Reply Last reply
                                        0
                                        • T trønderen

                                          Old guru Tony Hoare remarked after reviewing the various proposals for Fortran-77 extensions (some of them went quite far, to phrase it in a polite manner): "I don't know what programming languages will look like in the year 2000, but I know that they will be named 'Fortran'." When I first saw code written to the Fortran-2003 standard, my immediate reaction was: Hoare was right! So my curious question is: How did your 1982 vintage Fortran code fare with a 2024 vintage Fortran compiler? (Fortran 77 was so much delayed that the '77' is a misnomer, so I wouldn't be surprised if 1982 vintage code is not even by the F77 standard.)

                                          Religious freedom is the freedom to say that two plus two make five.

                                          C Offline
                                          C Offline
                                          charlieg
                                          wrote on last edited by
                                          #37

                                          Lord willing, I will be in this boat late this year or maybe next year. The FORTRAN production system I support breaks down into basic components: 1) UI. It's designed to allow order entry people to do it FAST. The new developers want to make the UI pretty, and they don't bother to talk to their customers. The customer is NOT The contract manager, it's the people in the factory. 2) Reports - enough said. 3) Number crunching to produce a manufacturing file. This is the grail. I cut my teeth on FORTRAN, but C and C++ allow string processing to a useful form. Trying to do it in FORTRAN brings tears to my eyes and my hemeroids swell.

                                          Charlie Gilley “They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759 Has never been more appropriate.

                                          D 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