6
Ngash
2y

After how long do we delete the commented code

Comments
  • 22
    The moment you commented it out, after all that's what Version control is for.
  • 7
    I'd say, at code review.

    commented out code should never pass code review unless it is super clear, that it's going to get uncommented very very soon...

    Like it could be to avoid tests failing while another system is getting fixed or something but you still need to push changes for a client. It's not pretty and recommended, but in real life it happens more than we'd like and managers don't care. So in very small subset of particular cases, I can imagine commented code getting out, but it should be uncommented very soon, otherwise nothing like that should ever pass review... no shit like "we might need it" or "I'm just testing something"... that's what git is for already.

    I'd say, if you found commented code that's older than a week it's definitely safe to remove, I mean worst case it's already tracked by git, so who cares, it's just very slightly more convenient to keep it around in the files, but not enough to justify doing it willy nilly
  • 9
    @C0D4 has the right notion.

    that's what version control is for.

    and if you don't have version control, you have far bigger problems than commented out code.
  • 8
    Or, before you create "MyProject - Copy (2).zip" 🙂
  • 1
    @C0D4 nah, that is too idealistic. I am keeping commented out code as easy constant reminder for something to decide later. I don’t take any notes outside my code. Also bringing that code from the history is tedious. L
  • 1
    Hehehehehehe
  • 3
    @aviophile I can't stand commented out code, especially when it's deprecated or even been rewritten.

    Sure it's a bit of a pain to rollback a change, but that's the point of testing and assuring the changes align with the needs.

    Having hundreds of lines of code doing nothing besides taking up space in a file is pointless and tiresome when it's a project with millions of lines and endless blocks of :

    /**
    revert this if needed

    **/
  • 0
    You don't you commit it to source control and then you delete it hehe
    But yeah after testing and debugging
  • 2
    Immediately.

    It's the VCS job to keep track of changes.

    Commented code is just being lazy.

    Delete it, it's unneeded.

    If it breaks things, find out why, learn that your workflow sucks as that shouldn't have happened, clean up the mess you made and do it properly the next time.

    This laziness is what I really... really...really hate.

    If it's not laziness, then I'd need to assume that you don't know what you're doing, you cannot use a VCS properly and that you're insecure about the changes you made.

    Things that are all high red flags for me.
  • 1
    Ooh boy this is one of my strongest code review moments

    Any commented out code must be deleted UNLESS a valid reason above the snippet is written down.

    'Maybe we need it later and it'd be lost...' no shithead that's what git is for
Add Comment