We're using Git as our DVCS and we're about to start to do a clean up (never done before in this team) of files that are not necessary (not part of the sources) from our products.

This is done in two ways:

  • removing the product files from the repo and adding them to the ignore list.
  • deleting dead code

According to Wikipedia:

Code refactoring is the process of restructuring existing computer code without changing its external behavior. Refactoring improves nonfunctional attributes of the software. Advantages include improved code readability and reduced complexity to improve source code maintainability, and create a more expressive internal architecture or object model to improve extensibility.

and from Martin Fowler's entry:

Refactoring is a very specific technique, founded on using small behavior-preserving transformations (themselves called refactorings).

I haven't read anywhere that removing dead code or removing files from your repo are considered refactoring techniques but I see them both as techniques that "improve source code maintainability" by removing irrelevant code that may distract us later on.

Do you think it's reasonable to call those two activities "Refactoring"?

  • 2
    Unfortunately, I think this is somewhat an opinion-based question, because I don't believe there is any definitive definition of the word "refactor". It's actually not even considered a real word by many dictionaries. Does it matter whether your activities are considered to be refactoring? What is the consequence of not calling it "refactoring"? – Dr. Wily's Apprentice Jan 28 '14 at 20:37
  • 1
    Why does it matter? Will you change anything depending on the answer? – psr Jan 28 '14 at 22:24
  • @Dr.Wily'sApprentice when people talk about refactoring in software terms they are usually referring to Martin Fowler's book which talks about the principle, which I guess acts as a definition. – gbjbaanb Feb 21 '14 at 23:39

I had to stop and think for a minute. This is not refactoring all on its own, but it's completing someone's refactoring or feature which was never finished.

Think about how the inert resources and dead code works its way into the codebase.

  1. It was added, but never used. Someone began a refactoring or started a feature but never completed that task.

  2. It was a tagalong with other useful code. Someone needed 1 function, but they added a whole directory of code/resources just to get that 1 function.

  3. New logic caused the resources/code to be abandoned. A re-skin was done, but the old resources were never removed. A refactoring caused unused classes/functions, but that code was never removed.

In all of these cases, if the work was properly completed, the cleanup would have been done as a part of that task.

Now you need to go back and finish those old tasks. It's not refactoring. It's completing old work.

|improve this answer|||||

Nope, I wouldn't consider it refactoring - you're not actually changing anything by removing unused code files from a project, its more a cleanup task. As you say these are not part of the sources.

However, removing unused code from a file where some code remains can be considered a refactoring because you are changing the codebase, or removing code files from an active project where they used to be compiled in is a refactor - your codebase has changed, even if very slightly. You never know what crazy side-effects this change might have, whether its due to the executable size, include chains, or even simple reflection into the application that used to work and no longer does after you remove the code. As a result, you should be keeping track of the change as if it was a real code change, just so you can return to it later and pinpoint what changes were made to your old, working application.

So if you have truly useless files in your repo that are truly not used (and I think of things like .obj files or other non-code files) then get rid of them before you migrate. If, however, they are code files, add them in and then delete them from the project and your repo so they remain in history only.

|improve this answer|||||

I think removing dead code would technically be classified as refactoring, because it's a code transformation that does not change the overall code's functional behavior.

Adding files to an ignore list seems more like a code metadata transformation than an actual code transformation, so I'm not sure whether it would technically be considered refactoring.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.