1

I am working on a project in C++ and I have a big CPP file with several function in it. I am actually working on splitting all this function into smaller cpp files to make it more readable. I was wondering if this process had actually a name ? I was thinking about "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

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.

  • I am sorry, can you explain what is the difference between logical and physical cleanups ? – Freddykong Apr 24 '17 at 15:31
  • @Freddykong: see my edit – Doc Brown Apr 24 '17 at 17:46
4

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".

  • The way the OP describes it does not sound like he is "turning parts of a larger method into a new method" - it sounds like he is only moving unchanged methods from one source file into another. – Doc Brown Apr 24 '17 at 17:50
  • You're right @DocBrown , I made an example to be more understandable – Freddykong Apr 25 '17 at 13:13
  • @Freddykong: Thanks for the example. Yes, that changes the meaning of the question, and now I need to update my answer. – FrustratedWithFormsDesigner Apr 25 '17 at 14:00

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.