Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Measuring code reusability

I am trying to measure how much of the code produced in our organisation is actually reusable and I'd like to set some guidelines. I'd like to have some reference to outer world:

How much code is typically reused in a single application ? More specifically - if we consider all the code of a complete end-user product (and eventually exclude 3rd party libraries), how many functions and methods are called from more than one place ?

What metrics are used to measure code reusability ? Are there any available numbers or studies for opensource and/or closed source software ?

like image 862
user384278 Avatar asked Jul 06 '10 07:07

user384278


1 Answers

How much code is typically reused in a single application ?

IMO there is no "typical" application, especially not in this respect. Apps have wildly different architectures and execution flows, which result in different patterns of "reuse".

Consider a batch data processing app, which reads data from a file in a specific format, converts it to another format, then saves it. It practically has a single execution path, so not many methods are called from more than one place.

OTOH consider a plugin framework with several independent plugins which all use the same infrastructure layer, so functions in that layer are called from many different places.

You can't really say the design of the first app is worse than that of the second app (without actually going into the case-specific details).

Note also that the metric in the 2nd case is tricky: if you measure only the core framework itself without plugins, you get a low reuse count, but with the actual plugins the reuse count is higher. Since the plugins may be externally developed, you may not even have access to these, so your metric will be skewed.

Which leads to another point: reuse can happen on many levels. You can reuse code within an app, or between apps. The latter can be measured only by taking into account all the apps in question.

I think a better approach to this might be to start from the other end, and search for duplicated code (e.g. using tools like PMD for Java code). If you have large chunks of duplicated code in lots of places, you need to refactor.

like image 132
Péter Török Avatar answered Oct 11 '22 13:10

Péter Török