When using version control there are some bad habits that need to be broken to get the most from it. One bad habit that really needs to be broken is the habit of commenting out dead code instead of deleting it.
It always starts the same way. You have to modify an existing piece of code, so you quickly comment out the old code and start adding your new code. Having the old code is handy - it gives you a reference for the new code you're writing and if something goes wrong you just uncomment it and you're back where you started. Easy.

Once you've finished writing your new procedure you give it a rough test and decide it's good to go, so you commit it to version control. But you leave the original code in - commented out of course, just in case you need it again later.

But not deleting dead code is totally counter-productive in a version controlled world. Firstly because your version control system already stores every past version. And secondly you are making it very hard to identify what's changed between versions when using a diff tool when you just use comments.

See how much clearer it is. We can easily tell that the function 'some_function_call' has been removed and nothing else. Deleting the code makes the change show up clearly in a diff.

In the long run this actually makes merging and reverting changes far easier. It helps team members and makes your code that little bit cleaner. Sure it might mean you actually have to learn the more advanced features of your version control system, but it will eventually save you time and help you avoid making mistakes.

Top Whitepapers

The following report, is based on a global survey of 706 IT and security professionals conducted in the United States, Canada, Germany, United Kingdom, Australia and New Zealand. The goal of the survey was to capture data on current attitudes and trends with mobile devices and IT security. This is the third survey on this topic and this report evaluates differences in responses to similar questions asked over the past two years.

Featured Whitepapers

Just as we’ve learned to tune out car alarms, so have we become impervious to the headlines of cybercrime. That’s despite cybercriminals stealing over 500 million identities1 in 2014, alone. According to a December 2014 Computer Weekly article2, “The production of malware continues on an industrial scale, with exploit kits and malware services putting sophisticated attack methods in the hands of relatively unskilled cyber criminals.” And unfortunately, ignoring the issue will not make it go away.

Copyright 2015 IDG Communications. ABN 14 001 592 650. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of IDG Communications is prohibited.