Is there a method for differentiating informative comments from commented out code?Is commented out code really always bad?Where should I include comments in my “self-documenting code”?Code maintenance: To add comments in code or to just leave it to the version control?Can commented-out code be valuable documentation?Why are we supposed to use short functions to sectionalize our code?What's wrong with comments that explain complex code?Clean Code comments vs class documentationIs a JS Boolean having custom properties a bad practice?Is the following comment clear: “Until contested”Alternative for commented out code that will be used later

How do ballistic trajectories work in a ring world?

What was the profession 芸者 (female entertainer) called in Russia?

Draw a diagram with rectangles

Is it okay to use open source code to do an interview task?

Sense of humor in your sci-fi stories

When do flights get cancelled due to fog?

My previous employer committed a severe violation of the law and is also being sued by me. How do I explain the situation to future employers?

Strong Password Detection in Python

Is this really the Saturn V computer only, or are there other systems here as well?

Was it ever illegal to name a pig "Napoleon" in France?

Is it possible to complete a PhD in CS in 3 years?

How to understand flavors and when to use combination of them?

How to slice a string input at a certain unknown index

Can Jimmy hang on his rope?

Need a non-volatile memory IC with near unlimited read/write operations capability

Is homosexuality or bisexuality allowed for women?

What does the multimeter dial do internally?

What factors could lead to bishops establishing monastic armies?

Who goes first? Person disembarking bus or the bicycle?

Is it possible for a character at any level to cast all 44 Cantrips in one week without Magic Items?

How do I separate enchants from items?

A ring of generalized power series

Why is a semiprime used as the modulus in RSA?

Moving millions of files to a different directory with specfic name patterns



Is there a method for differentiating informative comments from commented out code?


Is commented out code really always bad?Where should I include comments in my “self-documenting code”?Code maintenance: To add comments in code or to just leave it to the version control?Can commented-out code be valuable documentation?Why are we supposed to use short functions to sectionalize our code?What's wrong with comments that explain complex code?Clean Code comments vs class documentationIs a JS Boolean having custom properties a bad practice?Is the following comment clear: “Until contested”Alternative for commented out code that will be used later






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








10















Throughout the course of programming, you will end up with some comments that explain code and some comments that are removing code:



// A concise description 
const a = Boolean(obj);
//b = false;


Is there a good method to quickly parse which is which?



I've played around with using 3 /'s and /** */ for descriptive comments.










share|improve this question









New contributor



Ace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    10















    Throughout the course of programming, you will end up with some comments that explain code and some comments that are removing code:



    // A concise description 
    const a = Boolean(obj);
    //b = false;


    Is there a good method to quickly parse which is which?



    I've played around with using 3 /'s and /** */ for descriptive comments.










    share|improve this question









    New contributor



    Ace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      10












      10








      10


      1






      Throughout the course of programming, you will end up with some comments that explain code and some comments that are removing code:



      // A concise description 
      const a = Boolean(obj);
      //b = false;


      Is there a good method to quickly parse which is which?



      I've played around with using 3 /'s and /** */ for descriptive comments.










      share|improve this question









      New contributor



      Ace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      Throughout the course of programming, you will end up with some comments that explain code and some comments that are removing code:



      // A concise description 
      const a = Boolean(obj);
      //b = false;


      Is there a good method to quickly parse which is which?



      I've played around with using 3 /'s and /** */ for descriptive comments.







      javascript comments






      share|improve this question









      New contributor



      Ace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question









      New contributor



      Ace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question








      edited 1 hour ago









      Peter Mortensen

      1,1152 gold badges11 silver badges14 bronze badges




      1,1152 gold badges11 silver badges14 bronze badges






      New contributor



      Ace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked yesterday









      AceAce

      1595 bronze badges




      1595 bronze badges




      New contributor



      Ace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      Ace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          6 Answers
          6






          active

          oldest

          votes


















          63














          There is a very simple solution to this: remove the commented-out code.



          Really, there are only two good reasons to comment out code: to test something/make a fix, or to save code you might use later. If you're testing or fixing something, remove the commented out code as soon as you're done with the test or fix. If you're saving code you might use later, make it first-class code and put it somewhere such as a library where it can be put to good use.






          share|improve this answer




















          • 50





            Also, if the code has been checked in: just remove it. If you ever need it back, source control has got you covered

            – marstato
            yesterday






          • 9





            When code is removed nobody notices it ever existed. That makes it harder to recover. There is value in leaving commented code, especially if it seems likely that it will be used in the future.

            – usr
            16 hours ago






          • 21





            @usr: When code is removed nobody notices it ever existed - and to my experience, in 99% of all real-world cases that is the right thing. In 1%, there may be some value in the outcommented lines, however, if commented-out code stays in for several weeks or months (or longer), chances are high it won't even compile any more due to refactorings of the active code lines. The "pontential value for future uses" argument is often used as a wrong excuse by people who have an emotional problem of stripping things out of the codebase for which they had invested some hours of brainwork.

            – Doc Brown
            15 hours ago







          • 5





            I never commit commented code without additional explanatory comments. There are rare situations where you might want the code back in the near term, but every single one of those is exceptional and requires an explanation for future developers (or future you). 90% of my comments are "Removed because it appears to be unused. Delete after Nov 2021 if there are no problems"

            – James Beninger
            13 hours ago






          • 3





            My colleague once put "There was code here that did X but I removed it" when we removed some feature for the time being. That worked really well; you knew it was in source history for that file, but it wasn't bothering you.

            – Erik
            4 hours ago


















          14














          Hmm, I read this question slightly differently from Robert who correctly asserts that commented out code should be removed.



          If, however, you are looking for a convention to mark code for later removal, an old favorite of mine is //b = false; //TODO: remove



          Some IDE's flag //TODO: comments or can be taught to. If not, it's usually a searchable string. It's best to follow whatever convention your shop has established because this can be done several ways. Every code base should do this one way. Keeps it searchable.




          quickly parse which is which?




          Without that mark the automated way to do this is with the compiler. If stripping the comment off produces code that compiles, it must have been commented code. Writing an IDE plugin that checks that wouldn't be hard. But it will leave buggy commented code behind.



          This is why it's better to simply mark commented out code as code the moment you comment it out. This lets you work non-destructively while you decide if you really want it gone. Since we all get interrupted, and are somewhat forgetful, don't be surprised if some lines get checked in while in that state. If they do it's nice that they're at least clearly marked and searchable. Keyboard macros have helped me with this in the past. It's hard to get interrupted in the middle of this if you can do it with a single keystroke.



          You can take this as far as enshrining the mark in your continuous integration tests. Oops, I'm trying to check in with outstanding TODO's again.






          share|improve this answer

























          • Instead of seeing if comments compile to label them as code, you could run comments through a natural language processor and label the ones that parse as a sentence or noun phrase in the language your team speaks.

            – TheHansinator
            4 hours ago











          • @TheHansinator that sounds good but my experience with my cellphones auto correct relationship with my coder jargon makes me cautious.

            – candied_orange
            1 hour ago


















          11














          Adding to @RobertHarvey's excellent answer I believe there is only one legitimate reason I've ever encountered for saving commented code to source control, even temporarily: in case of a non-obvious improvement which depends on some third party change. This could be a bug or a feature of the language which is not yet considered stable. It might look something like this:



          # TODO: Replace with `foo = frobnicate(bar)` once <link.to/bug> is fixed
          foo = [some complex workaround]


          Basically, the work has already been done, but you can't yet take advantage of it, so deleting it means someone would have to rediscover it later.






          share|improve this answer
































            3














            I agree with the answer stating that old code should be removed rather than commented out where possible, however I have observed a convention for those few occasions when commented-out code is needed.



            (My basis is C# but this can be applied to any C-syntax language eg java)



            // An explanatory comment has a space between the comment marker and the content.

            // The following lines are commented out code so do not have the space (except where indented).
            //var a = something();
            //if(a==2)
            // doSomethingElse();
            //





            share|improve this answer








            New contributor



            IanF1 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.














            • 1





              This depends totally on style: When I comment out code, I generally add the // to the first column, and since virtually all code is indented, the result is virtually always that the comment starts with some tabs. Normal comments don't get a leading space from me, unless there are already other comments with a leading space in the vicinity. So, your method would fail abysmally on comments that I produced, and any method designed to recognize my comment patterns would fail abysmally on yours.

              – cmaster
              8 hours ago











            • @cmaster Ah I see, I think I misunderstood the question. I provided a simple way of formatting the comments in such a way that they can be easily parsed for type, which isn't what was asked for.

              – IanF1
              6 hours ago


















            2














            If you use an editor with a compiler running in the background (like Xcode and Clang), you can just try to compile the text of the comment. For example”a concise description” gives errors, “b = false;” doesn’t. You could then use different syntax highlighting.



            A simpler method would be an IDE plugin that uses some heuristics, like multiple words in a row other than keywords points to comments, matched curly braced point to code etc.






            share|improve this answer






























              1














              I am interpreting the question different still, thinking you want to find commented out code.



              C-style code is bound to have semi-colons in it while comment is unlikely to have semi-colons in it. So for single line commented-out code you could use this regular expression:



              s*//[sS]*;


              For multi-line commented-out code it could be



              /*[^;]*;[^;]**/


              Note Visual Studio is a bit peculiar about line breaks in regular expressions, they do not count as whitespace, you need to specify an explicit n.






              share|improve this answer

























                Your Answer








                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "131"
                ;
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function()
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled)
                StackExchange.using("snippets", function()
                createEditor();
                );

                else
                createEditor();

                );

                function createEditor()
                StackExchange.prepareEditor(
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: false,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                imageUploader:
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                ,
                onDemand: false,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                );



                );






                Ace is a new contributor. Be nice, and check out our Code of Conduct.









                draft saved

                draft discarded


















                StackExchange.ready(
                function ()
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsoftwareengineering.stackexchange.com%2fquestions%2f394287%2fis-there-a-method-for-differentiating-informative-comments-from-commented-out-co%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown




















                StackExchange.ready(function ()
                $("#show-editor-button input, #show-editor-button button").click(function ()
                var showEditor = function()
                $("#show-editor-button").hide();
                $("#post-form").removeClass("dno");
                StackExchange.editor.finallyInit();
                ;

                var useFancy = $(this).data('confirm-use-fancy');
                if(useFancy == 'True')
                var popupTitle = $(this).data('confirm-fancy-title');
                var popupBody = $(this).data('confirm-fancy-body');
                var popupAccept = $(this).data('confirm-fancy-accept-button');

                $(this).loadPopup(
                url: '/post/self-answer-popup',
                loaded: function(popup)
                var pTitle = $(popup).find('h2');
                var pBody = $(popup).find('.popup-body');
                var pSubmit = $(popup).find('.popup-submit');

                pTitle.text(popupTitle);
                pBody.html(popupBody);
                pSubmit.val(popupAccept).click(showEditor);

                )
                else
                var confirmText = $(this).data('confirm-text');
                if (confirmText ? confirm(confirmText) : true)
                showEditor();


                );
                );






                6 Answers
                6






                active

                oldest

                votes








                6 Answers
                6






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                63














                There is a very simple solution to this: remove the commented-out code.



                Really, there are only two good reasons to comment out code: to test something/make a fix, or to save code you might use later. If you're testing or fixing something, remove the commented out code as soon as you're done with the test or fix. If you're saving code you might use later, make it first-class code and put it somewhere such as a library where it can be put to good use.






                share|improve this answer




















                • 50





                  Also, if the code has been checked in: just remove it. If you ever need it back, source control has got you covered

                  – marstato
                  yesterday






                • 9





                  When code is removed nobody notices it ever existed. That makes it harder to recover. There is value in leaving commented code, especially if it seems likely that it will be used in the future.

                  – usr
                  16 hours ago






                • 21





                  @usr: When code is removed nobody notices it ever existed - and to my experience, in 99% of all real-world cases that is the right thing. In 1%, there may be some value in the outcommented lines, however, if commented-out code stays in for several weeks or months (or longer), chances are high it won't even compile any more due to refactorings of the active code lines. The "pontential value for future uses" argument is often used as a wrong excuse by people who have an emotional problem of stripping things out of the codebase for which they had invested some hours of brainwork.

                  – Doc Brown
                  15 hours ago







                • 5





                  I never commit commented code without additional explanatory comments. There are rare situations where you might want the code back in the near term, but every single one of those is exceptional and requires an explanation for future developers (or future you). 90% of my comments are "Removed because it appears to be unused. Delete after Nov 2021 if there are no problems"

                  – James Beninger
                  13 hours ago






                • 3





                  My colleague once put "There was code here that did X but I removed it" when we removed some feature for the time being. That worked really well; you knew it was in source history for that file, but it wasn't bothering you.

                  – Erik
                  4 hours ago















                63














                There is a very simple solution to this: remove the commented-out code.



                Really, there are only two good reasons to comment out code: to test something/make a fix, or to save code you might use later. If you're testing or fixing something, remove the commented out code as soon as you're done with the test or fix. If you're saving code you might use later, make it first-class code and put it somewhere such as a library where it can be put to good use.






                share|improve this answer




















                • 50





                  Also, if the code has been checked in: just remove it. If you ever need it back, source control has got you covered

                  – marstato
                  yesterday






                • 9





                  When code is removed nobody notices it ever existed. That makes it harder to recover. There is value in leaving commented code, especially if it seems likely that it will be used in the future.

                  – usr
                  16 hours ago






                • 21





                  @usr: When code is removed nobody notices it ever existed - and to my experience, in 99% of all real-world cases that is the right thing. In 1%, there may be some value in the outcommented lines, however, if commented-out code stays in for several weeks or months (or longer), chances are high it won't even compile any more due to refactorings of the active code lines. The "pontential value for future uses" argument is often used as a wrong excuse by people who have an emotional problem of stripping things out of the codebase for which they had invested some hours of brainwork.

                  – Doc Brown
                  15 hours ago







                • 5





                  I never commit commented code without additional explanatory comments. There are rare situations where you might want the code back in the near term, but every single one of those is exceptional and requires an explanation for future developers (or future you). 90% of my comments are "Removed because it appears to be unused. Delete after Nov 2021 if there are no problems"

                  – James Beninger
                  13 hours ago






                • 3





                  My colleague once put "There was code here that did X but I removed it" when we removed some feature for the time being. That worked really well; you knew it was in source history for that file, but it wasn't bothering you.

                  – Erik
                  4 hours ago













                63












                63








                63







                There is a very simple solution to this: remove the commented-out code.



                Really, there are only two good reasons to comment out code: to test something/make a fix, or to save code you might use later. If you're testing or fixing something, remove the commented out code as soon as you're done with the test or fix. If you're saving code you might use later, make it first-class code and put it somewhere such as a library where it can be put to good use.






                share|improve this answer















                There is a very simple solution to this: remove the commented-out code.



                Really, there are only two good reasons to comment out code: to test something/make a fix, or to save code you might use later. If you're testing or fixing something, remove the commented out code as soon as you're done with the test or fix. If you're saving code you might use later, make it first-class code and put it somewhere such as a library where it can be put to good use.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited yesterday

























                answered yesterday









                Robert HarveyRobert Harvey

                170k46 gold badges402 silver badges609 bronze badges




                170k46 gold badges402 silver badges609 bronze badges







                • 50





                  Also, if the code has been checked in: just remove it. If you ever need it back, source control has got you covered

                  – marstato
                  yesterday






                • 9





                  When code is removed nobody notices it ever existed. That makes it harder to recover. There is value in leaving commented code, especially if it seems likely that it will be used in the future.

                  – usr
                  16 hours ago






                • 21





                  @usr: When code is removed nobody notices it ever existed - and to my experience, in 99% of all real-world cases that is the right thing. In 1%, there may be some value in the outcommented lines, however, if commented-out code stays in for several weeks or months (or longer), chances are high it won't even compile any more due to refactorings of the active code lines. The "pontential value for future uses" argument is often used as a wrong excuse by people who have an emotional problem of stripping things out of the codebase for which they had invested some hours of brainwork.

                  – Doc Brown
                  15 hours ago







                • 5





                  I never commit commented code without additional explanatory comments. There are rare situations where you might want the code back in the near term, but every single one of those is exceptional and requires an explanation for future developers (or future you). 90% of my comments are "Removed because it appears to be unused. Delete after Nov 2021 if there are no problems"

                  – James Beninger
                  13 hours ago






                • 3





                  My colleague once put "There was code here that did X but I removed it" when we removed some feature for the time being. That worked really well; you knew it was in source history for that file, but it wasn't bothering you.

                  – Erik
                  4 hours ago












                • 50





                  Also, if the code has been checked in: just remove it. If you ever need it back, source control has got you covered

                  – marstato
                  yesterday






                • 9





                  When code is removed nobody notices it ever existed. That makes it harder to recover. There is value in leaving commented code, especially if it seems likely that it will be used in the future.

                  – usr
                  16 hours ago






                • 21





                  @usr: When code is removed nobody notices it ever existed - and to my experience, in 99% of all real-world cases that is the right thing. In 1%, there may be some value in the outcommented lines, however, if commented-out code stays in for several weeks or months (or longer), chances are high it won't even compile any more due to refactorings of the active code lines. The "pontential value for future uses" argument is often used as a wrong excuse by people who have an emotional problem of stripping things out of the codebase for which they had invested some hours of brainwork.

                  – Doc Brown
                  15 hours ago







                • 5





                  I never commit commented code without additional explanatory comments. There are rare situations where you might want the code back in the near term, but every single one of those is exceptional and requires an explanation for future developers (or future you). 90% of my comments are "Removed because it appears to be unused. Delete after Nov 2021 if there are no problems"

                  – James Beninger
                  13 hours ago






                • 3





                  My colleague once put "There was code here that did X but I removed it" when we removed some feature for the time being. That worked really well; you knew it was in source history for that file, but it wasn't bothering you.

                  – Erik
                  4 hours ago







                50




                50





                Also, if the code has been checked in: just remove it. If you ever need it back, source control has got you covered

                – marstato
                yesterday





                Also, if the code has been checked in: just remove it. If you ever need it back, source control has got you covered

                – marstato
                yesterday




                9




                9





                When code is removed nobody notices it ever existed. That makes it harder to recover. There is value in leaving commented code, especially if it seems likely that it will be used in the future.

                – usr
                16 hours ago





                When code is removed nobody notices it ever existed. That makes it harder to recover. There is value in leaving commented code, especially if it seems likely that it will be used in the future.

                – usr
                16 hours ago




                21




                21





                @usr: When code is removed nobody notices it ever existed - and to my experience, in 99% of all real-world cases that is the right thing. In 1%, there may be some value in the outcommented lines, however, if commented-out code stays in for several weeks or months (or longer), chances are high it won't even compile any more due to refactorings of the active code lines. The "pontential value for future uses" argument is often used as a wrong excuse by people who have an emotional problem of stripping things out of the codebase for which they had invested some hours of brainwork.

                – Doc Brown
                15 hours ago






                @usr: When code is removed nobody notices it ever existed - and to my experience, in 99% of all real-world cases that is the right thing. In 1%, there may be some value in the outcommented lines, however, if commented-out code stays in for several weeks or months (or longer), chances are high it won't even compile any more due to refactorings of the active code lines. The "pontential value for future uses" argument is often used as a wrong excuse by people who have an emotional problem of stripping things out of the codebase for which they had invested some hours of brainwork.

                – Doc Brown
                15 hours ago





                5




                5





                I never commit commented code without additional explanatory comments. There are rare situations where you might want the code back in the near term, but every single one of those is exceptional and requires an explanation for future developers (or future you). 90% of my comments are "Removed because it appears to be unused. Delete after Nov 2021 if there are no problems"

                – James Beninger
                13 hours ago





                I never commit commented code without additional explanatory comments. There are rare situations where you might want the code back in the near term, but every single one of those is exceptional and requires an explanation for future developers (or future you). 90% of my comments are "Removed because it appears to be unused. Delete after Nov 2021 if there are no problems"

                – James Beninger
                13 hours ago




                3




                3





                My colleague once put "There was code here that did X but I removed it" when we removed some feature for the time being. That worked really well; you knew it was in source history for that file, but it wasn't bothering you.

                – Erik
                4 hours ago





                My colleague once put "There was code here that did X but I removed it" when we removed some feature for the time being. That worked really well; you knew it was in source history for that file, but it wasn't bothering you.

                – Erik
                4 hours ago













                14














                Hmm, I read this question slightly differently from Robert who correctly asserts that commented out code should be removed.



                If, however, you are looking for a convention to mark code for later removal, an old favorite of mine is //b = false; //TODO: remove



                Some IDE's flag //TODO: comments or can be taught to. If not, it's usually a searchable string. It's best to follow whatever convention your shop has established because this can be done several ways. Every code base should do this one way. Keeps it searchable.




                quickly parse which is which?




                Without that mark the automated way to do this is with the compiler. If stripping the comment off produces code that compiles, it must have been commented code. Writing an IDE plugin that checks that wouldn't be hard. But it will leave buggy commented code behind.



                This is why it's better to simply mark commented out code as code the moment you comment it out. This lets you work non-destructively while you decide if you really want it gone. Since we all get interrupted, and are somewhat forgetful, don't be surprised if some lines get checked in while in that state. If they do it's nice that they're at least clearly marked and searchable. Keyboard macros have helped me with this in the past. It's hard to get interrupted in the middle of this if you can do it with a single keystroke.



                You can take this as far as enshrining the mark in your continuous integration tests. Oops, I'm trying to check in with outstanding TODO's again.






                share|improve this answer

























                • Instead of seeing if comments compile to label them as code, you could run comments through a natural language processor and label the ones that parse as a sentence or noun phrase in the language your team speaks.

                  – TheHansinator
                  4 hours ago











                • @TheHansinator that sounds good but my experience with my cellphones auto correct relationship with my coder jargon makes me cautious.

                  – candied_orange
                  1 hour ago















                14














                Hmm, I read this question slightly differently from Robert who correctly asserts that commented out code should be removed.



                If, however, you are looking for a convention to mark code for later removal, an old favorite of mine is //b = false; //TODO: remove



                Some IDE's flag //TODO: comments or can be taught to. If not, it's usually a searchable string. It's best to follow whatever convention your shop has established because this can be done several ways. Every code base should do this one way. Keeps it searchable.




                quickly parse which is which?




                Without that mark the automated way to do this is with the compiler. If stripping the comment off produces code that compiles, it must have been commented code. Writing an IDE plugin that checks that wouldn't be hard. But it will leave buggy commented code behind.



                This is why it's better to simply mark commented out code as code the moment you comment it out. This lets you work non-destructively while you decide if you really want it gone. Since we all get interrupted, and are somewhat forgetful, don't be surprised if some lines get checked in while in that state. If they do it's nice that they're at least clearly marked and searchable. Keyboard macros have helped me with this in the past. It's hard to get interrupted in the middle of this if you can do it with a single keystroke.



                You can take this as far as enshrining the mark in your continuous integration tests. Oops, I'm trying to check in with outstanding TODO's again.






                share|improve this answer

























                • Instead of seeing if comments compile to label them as code, you could run comments through a natural language processor and label the ones that parse as a sentence or noun phrase in the language your team speaks.

                  – TheHansinator
                  4 hours ago











                • @TheHansinator that sounds good but my experience with my cellphones auto correct relationship with my coder jargon makes me cautious.

                  – candied_orange
                  1 hour ago













                14












                14








                14







                Hmm, I read this question slightly differently from Robert who correctly asserts that commented out code should be removed.



                If, however, you are looking for a convention to mark code for later removal, an old favorite of mine is //b = false; //TODO: remove



                Some IDE's flag //TODO: comments or can be taught to. If not, it's usually a searchable string. It's best to follow whatever convention your shop has established because this can be done several ways. Every code base should do this one way. Keeps it searchable.




                quickly parse which is which?




                Without that mark the automated way to do this is with the compiler. If stripping the comment off produces code that compiles, it must have been commented code. Writing an IDE plugin that checks that wouldn't be hard. But it will leave buggy commented code behind.



                This is why it's better to simply mark commented out code as code the moment you comment it out. This lets you work non-destructively while you decide if you really want it gone. Since we all get interrupted, and are somewhat forgetful, don't be surprised if some lines get checked in while in that state. If they do it's nice that they're at least clearly marked and searchable. Keyboard macros have helped me with this in the past. It's hard to get interrupted in the middle of this if you can do it with a single keystroke.



                You can take this as far as enshrining the mark in your continuous integration tests. Oops, I'm trying to check in with outstanding TODO's again.






                share|improve this answer















                Hmm, I read this question slightly differently from Robert who correctly asserts that commented out code should be removed.



                If, however, you are looking for a convention to mark code for later removal, an old favorite of mine is //b = false; //TODO: remove



                Some IDE's flag //TODO: comments or can be taught to. If not, it's usually a searchable string. It's best to follow whatever convention your shop has established because this can be done several ways. Every code base should do this one way. Keeps it searchable.




                quickly parse which is which?




                Without that mark the automated way to do this is with the compiler. If stripping the comment off produces code that compiles, it must have been commented code. Writing an IDE plugin that checks that wouldn't be hard. But it will leave buggy commented code behind.



                This is why it's better to simply mark commented out code as code the moment you comment it out. This lets you work non-destructively while you decide if you really want it gone. Since we all get interrupted, and are somewhat forgetful, don't be surprised if some lines get checked in while in that state. If they do it's nice that they're at least clearly marked and searchable. Keyboard macros have helped me with this in the past. It's hard to get interrupted in the middle of this if you can do it with a single keystroke.



                You can take this as far as enshrining the mark in your continuous integration tests. Oops, I'm trying to check in with outstanding TODO's again.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 9 hours ago

























                answered yesterday









                candied_orangecandied_orange

                58.8k18 gold badges117 silver badges203 bronze badges




                58.8k18 gold badges117 silver badges203 bronze badges












                • Instead of seeing if comments compile to label them as code, you could run comments through a natural language processor and label the ones that parse as a sentence or noun phrase in the language your team speaks.

                  – TheHansinator
                  4 hours ago











                • @TheHansinator that sounds good but my experience with my cellphones auto correct relationship with my coder jargon makes me cautious.

                  – candied_orange
                  1 hour ago

















                • Instead of seeing if comments compile to label them as code, you could run comments through a natural language processor and label the ones that parse as a sentence or noun phrase in the language your team speaks.

                  – TheHansinator
                  4 hours ago











                • @TheHansinator that sounds good but my experience with my cellphones auto correct relationship with my coder jargon makes me cautious.

                  – candied_orange
                  1 hour ago
















                Instead of seeing if comments compile to label them as code, you could run comments through a natural language processor and label the ones that parse as a sentence or noun phrase in the language your team speaks.

                – TheHansinator
                4 hours ago





                Instead of seeing if comments compile to label them as code, you could run comments through a natural language processor and label the ones that parse as a sentence or noun phrase in the language your team speaks.

                – TheHansinator
                4 hours ago













                @TheHansinator that sounds good but my experience with my cellphones auto correct relationship with my coder jargon makes me cautious.

                – candied_orange
                1 hour ago





                @TheHansinator that sounds good but my experience with my cellphones auto correct relationship with my coder jargon makes me cautious.

                – candied_orange
                1 hour ago











                11














                Adding to @RobertHarvey's excellent answer I believe there is only one legitimate reason I've ever encountered for saving commented code to source control, even temporarily: in case of a non-obvious improvement which depends on some third party change. This could be a bug or a feature of the language which is not yet considered stable. It might look something like this:



                # TODO: Replace with `foo = frobnicate(bar)` once <link.to/bug> is fixed
                foo = [some complex workaround]


                Basically, the work has already been done, but you can't yet take advantage of it, so deleting it means someone would have to rediscover it later.






                share|improve this answer





























                  11














                  Adding to @RobertHarvey's excellent answer I believe there is only one legitimate reason I've ever encountered for saving commented code to source control, even temporarily: in case of a non-obvious improvement which depends on some third party change. This could be a bug or a feature of the language which is not yet considered stable. It might look something like this:



                  # TODO: Replace with `foo = frobnicate(bar)` once <link.to/bug> is fixed
                  foo = [some complex workaround]


                  Basically, the work has already been done, but you can't yet take advantage of it, so deleting it means someone would have to rediscover it later.






                  share|improve this answer



























                    11












                    11








                    11







                    Adding to @RobertHarvey's excellent answer I believe there is only one legitimate reason I've ever encountered for saving commented code to source control, even temporarily: in case of a non-obvious improvement which depends on some third party change. This could be a bug or a feature of the language which is not yet considered stable. It might look something like this:



                    # TODO: Replace with `foo = frobnicate(bar)` once <link.to/bug> is fixed
                    foo = [some complex workaround]


                    Basically, the work has already been done, but you can't yet take advantage of it, so deleting it means someone would have to rediscover it later.






                    share|improve this answer















                    Adding to @RobertHarvey's excellent answer I believe there is only one legitimate reason I've ever encountered for saving commented code to source control, even temporarily: in case of a non-obvious improvement which depends on some third party change. This could be a bug or a feature of the language which is not yet considered stable. It might look something like this:



                    # TODO: Replace with `foo = frobnicate(bar)` once <link.to/bug> is fixed
                    foo = [some complex workaround]


                    Basically, the work has already been done, but you can't yet take advantage of it, so deleting it means someone would have to rediscover it later.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 3 hours ago

























                    answered 14 hours ago









                    l0b0l0b0

                    7,5712 gold badges28 silver badges38 bronze badges




                    7,5712 gold badges28 silver badges38 bronze badges





















                        3














                        I agree with the answer stating that old code should be removed rather than commented out where possible, however I have observed a convention for those few occasions when commented-out code is needed.



                        (My basis is C# but this can be applied to any C-syntax language eg java)



                        // An explanatory comment has a space between the comment marker and the content.

                        // The following lines are commented out code so do not have the space (except where indented).
                        //var a = something();
                        //if(a==2)
                        // doSomethingElse();
                        //





                        share|improve this answer








                        New contributor



                        IanF1 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.














                        • 1





                          This depends totally on style: When I comment out code, I generally add the // to the first column, and since virtually all code is indented, the result is virtually always that the comment starts with some tabs. Normal comments don't get a leading space from me, unless there are already other comments with a leading space in the vicinity. So, your method would fail abysmally on comments that I produced, and any method designed to recognize my comment patterns would fail abysmally on yours.

                          – cmaster
                          8 hours ago











                        • @cmaster Ah I see, I think I misunderstood the question. I provided a simple way of formatting the comments in such a way that they can be easily parsed for type, which isn't what was asked for.

                          – IanF1
                          6 hours ago















                        3














                        I agree with the answer stating that old code should be removed rather than commented out where possible, however I have observed a convention for those few occasions when commented-out code is needed.



                        (My basis is C# but this can be applied to any C-syntax language eg java)



                        // An explanatory comment has a space between the comment marker and the content.

                        // The following lines are commented out code so do not have the space (except where indented).
                        //var a = something();
                        //if(a==2)
                        // doSomethingElse();
                        //





                        share|improve this answer








                        New contributor



                        IanF1 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.














                        • 1





                          This depends totally on style: When I comment out code, I generally add the // to the first column, and since virtually all code is indented, the result is virtually always that the comment starts with some tabs. Normal comments don't get a leading space from me, unless there are already other comments with a leading space in the vicinity. So, your method would fail abysmally on comments that I produced, and any method designed to recognize my comment patterns would fail abysmally on yours.

                          – cmaster
                          8 hours ago











                        • @cmaster Ah I see, I think I misunderstood the question. I provided a simple way of formatting the comments in such a way that they can be easily parsed for type, which isn't what was asked for.

                          – IanF1
                          6 hours ago













                        3












                        3








                        3







                        I agree with the answer stating that old code should be removed rather than commented out where possible, however I have observed a convention for those few occasions when commented-out code is needed.



                        (My basis is C# but this can be applied to any C-syntax language eg java)



                        // An explanatory comment has a space between the comment marker and the content.

                        // The following lines are commented out code so do not have the space (except where indented).
                        //var a = something();
                        //if(a==2)
                        // doSomethingElse();
                        //





                        share|improve this answer








                        New contributor



                        IanF1 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.









                        I agree with the answer stating that old code should be removed rather than commented out where possible, however I have observed a convention for those few occasions when commented-out code is needed.



                        (My basis is C# but this can be applied to any C-syntax language eg java)



                        // An explanatory comment has a space between the comment marker and the content.

                        // The following lines are commented out code so do not have the space (except where indented).
                        //var a = something();
                        //if(a==2)
                        // doSomethingElse();
                        //






                        share|improve this answer








                        New contributor



                        IanF1 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.








                        share|improve this answer



                        share|improve this answer






                        New contributor



                        IanF1 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.








                        answered 13 hours ago









                        IanF1IanF1

                        1312 bronze badges




                        1312 bronze badges




                        New contributor



                        IanF1 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.




                        New contributor




                        IanF1 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.









                        • 1





                          This depends totally on style: When I comment out code, I generally add the // to the first column, and since virtually all code is indented, the result is virtually always that the comment starts with some tabs. Normal comments don't get a leading space from me, unless there are already other comments with a leading space in the vicinity. So, your method would fail abysmally on comments that I produced, and any method designed to recognize my comment patterns would fail abysmally on yours.

                          – cmaster
                          8 hours ago











                        • @cmaster Ah I see, I think I misunderstood the question. I provided a simple way of formatting the comments in such a way that they can be easily parsed for type, which isn't what was asked for.

                          – IanF1
                          6 hours ago












                        • 1





                          This depends totally on style: When I comment out code, I generally add the // to the first column, and since virtually all code is indented, the result is virtually always that the comment starts with some tabs. Normal comments don't get a leading space from me, unless there are already other comments with a leading space in the vicinity. So, your method would fail abysmally on comments that I produced, and any method designed to recognize my comment patterns would fail abysmally on yours.

                          – cmaster
                          8 hours ago











                        • @cmaster Ah I see, I think I misunderstood the question. I provided a simple way of formatting the comments in such a way that they can be easily parsed for type, which isn't what was asked for.

                          – IanF1
                          6 hours ago







                        1




                        1





                        This depends totally on style: When I comment out code, I generally add the // to the first column, and since virtually all code is indented, the result is virtually always that the comment starts with some tabs. Normal comments don't get a leading space from me, unless there are already other comments with a leading space in the vicinity. So, your method would fail abysmally on comments that I produced, and any method designed to recognize my comment patterns would fail abysmally on yours.

                        – cmaster
                        8 hours ago





                        This depends totally on style: When I comment out code, I generally add the // to the first column, and since virtually all code is indented, the result is virtually always that the comment starts with some tabs. Normal comments don't get a leading space from me, unless there are already other comments with a leading space in the vicinity. So, your method would fail abysmally on comments that I produced, and any method designed to recognize my comment patterns would fail abysmally on yours.

                        – cmaster
                        8 hours ago













                        @cmaster Ah I see, I think I misunderstood the question. I provided a simple way of formatting the comments in such a way that they can be easily parsed for type, which isn't what was asked for.

                        – IanF1
                        6 hours ago





                        @cmaster Ah I see, I think I misunderstood the question. I provided a simple way of formatting the comments in such a way that they can be easily parsed for type, which isn't what was asked for.

                        – IanF1
                        6 hours ago











                        2














                        If you use an editor with a compiler running in the background (like Xcode and Clang), you can just try to compile the text of the comment. For example”a concise description” gives errors, “b = false;” doesn’t. You could then use different syntax highlighting.



                        A simpler method would be an IDE plugin that uses some heuristics, like multiple words in a row other than keywords points to comments, matched curly braced point to code etc.






                        share|improve this answer



























                          2














                          If you use an editor with a compiler running in the background (like Xcode and Clang), you can just try to compile the text of the comment. For example”a concise description” gives errors, “b = false;” doesn’t. You could then use different syntax highlighting.



                          A simpler method would be an IDE plugin that uses some heuristics, like multiple words in a row other than keywords points to comments, matched curly braced point to code etc.






                          share|improve this answer

























                            2












                            2








                            2







                            If you use an editor with a compiler running in the background (like Xcode and Clang), you can just try to compile the text of the comment. For example”a concise description” gives errors, “b = false;” doesn’t. You could then use different syntax highlighting.



                            A simpler method would be an IDE plugin that uses some heuristics, like multiple words in a row other than keywords points to comments, matched curly braced point to code etc.






                            share|improve this answer













                            If you use an editor with a compiler running in the background (like Xcode and Clang), you can just try to compile the text of the comment. For example”a concise description” gives errors, “b = false;” doesn’t. You could then use different syntax highlighting.



                            A simpler method would be an IDE plugin that uses some heuristics, like multiple words in a row other than keywords points to comments, matched curly braced point to code etc.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 13 hours ago









                            gnasher729gnasher729

                            21.5k2 gold badges32 silver badges65 bronze badges




                            21.5k2 gold badges32 silver badges65 bronze badges





















                                1














                                I am interpreting the question different still, thinking you want to find commented out code.



                                C-style code is bound to have semi-colons in it while comment is unlikely to have semi-colons in it. So for single line commented-out code you could use this regular expression:



                                s*//[sS]*;


                                For multi-line commented-out code it could be



                                /*[^;]*;[^;]**/


                                Note Visual Studio is a bit peculiar about line breaks in regular expressions, they do not count as whitespace, you need to specify an explicit n.






                                share|improve this answer



























                                  1














                                  I am interpreting the question different still, thinking you want to find commented out code.



                                  C-style code is bound to have semi-colons in it while comment is unlikely to have semi-colons in it. So for single line commented-out code you could use this regular expression:



                                  s*//[sS]*;


                                  For multi-line commented-out code it could be



                                  /*[^;]*;[^;]**/


                                  Note Visual Studio is a bit peculiar about line breaks in regular expressions, they do not count as whitespace, you need to specify an explicit n.






                                  share|improve this answer

























                                    1












                                    1








                                    1







                                    I am interpreting the question different still, thinking you want to find commented out code.



                                    C-style code is bound to have semi-colons in it while comment is unlikely to have semi-colons in it. So for single line commented-out code you could use this regular expression:



                                    s*//[sS]*;


                                    For multi-line commented-out code it could be



                                    /*[^;]*;[^;]**/


                                    Note Visual Studio is a bit peculiar about line breaks in regular expressions, they do not count as whitespace, you need to specify an explicit n.






                                    share|improve this answer













                                    I am interpreting the question different still, thinking you want to find commented out code.



                                    C-style code is bound to have semi-colons in it while comment is unlikely to have semi-colons in it. So for single line commented-out code you could use this regular expression:



                                    s*//[sS]*;


                                    For multi-line commented-out code it could be



                                    /*[^;]*;[^;]**/


                                    Note Visual Studio is a bit peculiar about line breaks in regular expressions, they do not count as whitespace, you need to specify an explicit n.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered yesterday









                                    Martin MaatMartin Maat

                                    8,7992 gold badges11 silver badges35 bronze badges




                                    8,7992 gold badges11 silver badges35 bronze badges




















                                        Ace is a new contributor. Be nice, and check out our Code of Conduct.









                                        draft saved

                                        draft discarded


















                                        Ace is a new contributor. Be nice, and check out our Code of Conduct.












                                        Ace is a new contributor. Be nice, and check out our Code of Conduct.











                                        Ace is a new contributor. Be nice, and check out our Code of Conduct.














                                        Thanks for contributing an answer to Software Engineering Stack Exchange!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid


                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.

                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function ()
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsoftwareengineering.stackexchange.com%2fquestions%2f394287%2fis-there-a-method-for-differentiating-informative-comments-from-commented-out-co%23new-answer', 'question_page');

                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown











                                        Popular posts from this blog

                                        Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                                        Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                                        Tom Holland Mục lục Đầu đời và giáo dục | Sự nghiệp | Cuộc sống cá nhân | Phim tham gia | Giải thưởng và đề cử | Chú thích | Liên kết ngoài | Trình đơn chuyển hướngProfile“Person Details for Thomas Stanley Holland, "England and Wales Birth Registration Index, 1837-2008" — FamilySearch.org”"Meet Tom Holland... the 16-year-old star of The Impossible""Schoolboy actor Tom Holland finds himself in Oscar contention for role in tsunami drama"“Naomi Watts on the Prince William and Harry's reaction to her film about the late Princess Diana”lưu trữ"Holland and Pflueger Are West End's Two New 'Billy Elliots'""I'm so envious of my son, the movie star! British writer Dominic Holland's spent 20 years trying to crack Hollywood - but he's been beaten to it by a very unlikely rival"“Richard and Margaret Povey of Jersey, Channel Islands, UK: Information about Thomas Stanley Holland”"Tom Holland to play Billy Elliot""New Billy Elliot leaving the garage"Billy Elliot the Musical - Tom Holland - Billy"A Tale of four Billys: Tom Holland""The Feel Good Factor""Thames Christian College schoolboys join Myleene Klass for The Feelgood Factor""Government launches £600,000 arts bursaries pilot""BILLY's Chapman, Holland, Gardner & Jackson-Keen Visit Prime Minister""Elton John 'blown away' by Billy Elliot fifth birthday" (video with John's interview and fragments of Holland's performance)"First News interviews Arrietty's Tom Holland"“33rd Critics' Circle Film Awards winners”“National Board of Review Current Awards”Bản gốc"Ron Howard Whaling Tale 'In The Heart Of The Sea' Casts Tom Holland"“'Spider-Man' Finds Tom Holland to Star as New Web-Slinger”lưu trữ“Captain America: Civil War (2016)”“Film Review: ‘Captain America: Civil War’”lưu trữ“‘Captain America: Civil War’ review: Choose your own avenger”lưu trữ“The Lost City of Z reviews”“Sony Pictures and Marvel Studios Find Their 'Spider-Man' Star and Director”“‘Mary Magdalene’, ‘Current War’ & ‘Wind River’ Get 2017 Release Dates From Weinstein”“Lionsgate Unleashing Daisy Ridley & Tom Holland Starrer ‘Chaos Walking’ In Cannes”“PTA's 'Master' Leads Chicago Film Critics Nominations, UPDATED: Houston and Indiana Critics Nominations”“Nominaciones Goya 2013 Telecinco Cinema – ENG”“Jameson Empire Film Awards: Martin Freeman wins best actor for performance in The Hobbit”“34th Annual Young Artist Awards”Bản gốc“Teen Choice Awards 2016—Captain America: Civil War Leads Second Wave of Nominations”“BAFTA Film Award Nominations: ‘La La Land’ Leads Race”“Saturn Awards Nominations 2017: 'Rogue One,' 'Walking Dead' Lead”Tom HollandTom HollandTom HollandTom Hollandmedia.gettyimages.comWorldCat Identities300279794no20130442900000 0004 0355 42791085670554170004732cb16706349t(data)XX5557367