Reputation: 36339
I often have the problem that function and type definitions aggregate over time in a single module (we can assume that a module corresponds to a source file). At some point the source file is so big that it is barely maintenable anymore. For example, one realizes the module contains a lot of functions that are logically related to a handful of different topics, and one feels that they should be in their own modules.
The idea is to have a tool that suggests ways to split up such a module. The actual creation of new source files from the old ones could then be made automatically.
I have the follwoing:
we can do a topological sort, to make dependency groups. For example
(a, (b,c,d), e)
The modules must form an acyclic hierarchy, i.e. it is not possible that module A imports module B when B or one of the modules it imports already imports A. From this it follows that (b, c, d)
from the example above must not be splitted across different modules.
Now I am somehow stuck and looking for a strategy to make sensible suggestions based on the information found so far.
Of course, one possibility would be to split according to the topologically sorted list of dependency groups. However, let us assume the list starts thus:
(a, b, c, ....)
Where c depends on b and a, b on a and a on nothing. Here we could do the following:
If we simply map dependencies between functions into dependencies between modules we may end up with a module hierarchy that is too complex and fine grained.
Somehow I must take further factors into account. Maybe some desired module size, or number of imports.
Any advice, as well as pointers to existing software doing something like this are most welcome.
Upvotes: 2
Views: 76
Reputation: 31648
It sounds like you are describing Efferent and Afferent Couplings http://en.wikipedia.org/wiki/Software_package_metrics
This is a language agnostic question but I know of a few tools in Java such as JDepend (http://clarkware.com/software/JDepend.html) that will compute these metrics for you to help guide future refactorings.
Upvotes: 1