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.

Neel Sandell
  • 105
  • 3
Freddykong
  • 149
  • 9
  • Possible duplicate of [Clean OOP-Design: How to implement single responsibility and no procedural programming](https://softwareengineering.stackexchange.com/questions/323661/clean-oop-design-how-to-implement-single-responsibility-and-no-procedural-progr) – gnat Apr 24 '17 at 14:58
  • see also: [How to determine if a class meets the single responsibility principle?](https://softwareengineering.stackexchange.com/q/154723/31260) – gnat Apr 24 '17 at 14:58
  • Why is the file so large? Is it trying to do too many things?. Since this is C++ is it worth considering breaking up a large class? – Nick Keighley Apr 25 '17 at 13:44
  • You're right, but my source file is not a class at all. At the begining, I was working with a class with static functions only, and by the time I though it was useless to do that so now it's only a namespace with several functions in it and all the others "child" sources files are part of this namespace. I will edit again my message to be clearer. – Freddykong Apr 25 '17 at 13:53
  • Is there much "global" data? If groups of functions share data consider making them into a class (this is assuming you want an OO design) – Nick Keighley May 16 '17 at 14:34
  • If its C (some C++ is really just C code) consider breaking out libraries or even ADTs. – Nick Keighley May 16 '17 at 14:34
  • @NickKeighley Sorry for my late answer. There is no Global Data, they do not share any data. Actually it's C++ code but as you said, my code has a strong C component. My work is to make a DLL made of functions called by another program, written in another language. There are classes in this other program and their functions are just calling their "twin" from my DLL to do their work. – Freddykong May 24 '17 at 09:58

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,105
  • 7
  • 126
  • 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
  • 199,015
  • 33
  • 367
  • 565