1

I am working on a project in C++, and I have a big CPP file with several functions in it. I am actually working on splitting all these functions into smaller cpp files to make it more readable. I was wondering if this process had actually a name? I was thinking about calling it "Refactoring", but this process seems more complicated than my "little" work.

This is a simple example of what I am doing:

Coming from FileA.cpp:

extern "C"
{
    namespace foo
    {
        functionA()
        {
            //Some Code
        }
        functionB()
        {
            //Some Code
        }
        .
        .
        .
        functionZ()
        {
             // Some Code
        }
    }
}

To FileB.cpp

extern "C"
{
    namespace foo
    {
        functionA()
        {
            // Some Code
        }
        functionB()
        {
            // Some Code
        }
    }
}

FileC.cpp

extern "C"
{
    namespace foo
    {
        functionC()
        {
            // Some Code
        }
        functionD()
        {
            // Some Code
        }
    }
}

etc.

2 Answers2

3

Yes, the term "refactoring" will apply here. See: https://en.wikipedia.org/wiki/Code_refactoring#List_of_refactoring_techniques

  • Techniques for breaking code apart into more logical pieces ...
    • Extract Method, to turn part of a larger method into a new method. By breaking down code in smaller pieces, it is more easily understandable. This is also applicable to functions.

UPDATE

Now that the question has been updated and clarified, I would agree with Doc Brown and say that "clean-up" is probably a better term for this activity than "refactoring".

FrustratedWithFormsDesigner
  • 46,235
  • 7
  • 128
  • 176
2

Some people might use the term "refactoring" for what you described, however, Martin Fowler, who invented the term, published a catalog of typical refactorings. Splitting a big CPP file into smaller ones, by distributing the classes and functions to different files (without changing any of the functions) - is not in that catalogue.

The refactorings Fowler describes are logical cleanups, where, for example, functions with more than one responsibility are reworked and divided into functions with just one responsibility. This is opposed to physical cleanups, where the functions themselves stay the same, only the CPP file (the "physical place") where one finds the function's source code changes. So if you are doing the first, it is clearly refactoring, but if it is the latter, then I think the term "cleaning" fits better.

Doc Brown
  • 206,877