Question

I was working in a story and in last minute, I have been asked to hide something from UI and we will used it next release.

  • Should i remove it or comment it

  • Should i remove or comment anything related to this part from code or leave it if it won't effect in anything.

Was it helpful?

Solution

If you value clean work practices, I would suggest that instead of commenting out code (which is an OK enough practice in the very short term, i.e. when we're talking a few weeks or less), prefer to use a source control system (Git, Mercurial, Subversion, etc.) instead:

Move the feature's code, and all that's specifically related to it and not used by other code, to a separate feature branch (i.e. a fork off your current development branch). Make sure the code is completely removed in the main development branch. That way, all you will have to do to reactivate the feature is to merge the feature branch back into the main development branch. What you will not have to do is undoing the commenting-out on a line-by-line basis (running the chance that you forget to uncomment something, somewhere).

It might be a little bit more work, but a much cleaner work practice than commenting out code. Commented-out code has the habit of accumulating over time, and it's often never uncommented again (against previous expectations). For that reason, unless a piece of commented-out code has explicit documentation stating why it's commented out, and when it should be uncommented again, I tend to purge commented-out code from a code base whenever I stumble upon it.

For the same reason, I would suggest that you don't only disable/remove the "triggering" code of a feature, but all other code that is also related to only it (even if it would never have any effect if you removed the core feature code). Because, if you eventually don't put the feature in the next release, you might forget about the dependent code. So treat it the same was as the "core" / triggering feature code.

OTHER TIPS

Here's what I would do:

  • Before you do anything, we make sure your code is checked in to source control. That way, you can always recover it later if you need to.

  • The general rule is that you should remove code that you don't need any more, to keep the codebase as clean as possible. So, if you don't expect your code to be re-used in the 'near future', remove it.

  • However, in this case, there is good reason to expect your code to be used in the next release. So, commenting it out (with a comment to explain what you're doing) is probably your best bet. If you discover that you don't use it after all, you (or your successor) can remove it later.

Alternatively, if your code is self-contained and this measure is temporary, you may get away by wrapping the code inside an if statement and set a boolean flag to disable the code block. Whether this is good practice though...

If you use version control such as SVN, Git or Mercurial you can put it on another branch and remove it from the release/main branch. You can merge the branch to the release branch when it's ready for release.

If you do not use version control, it's okay to put it in comments. However, when you put something in comments it's easy to forget about it, so I would advise to start using version control if you don't do that already.

Licensed under: CC-BY-SA with attribution
scroll top