0

There are metrics for class and module cohesion and coupling, but I didn't find anything yet for a single function. Some functions are obviously doing too much, like doThisAndThat (should be doThat(doThis())) or getDataForThis (should be convertForThis(getData())), and it would be very nice if there were an automatic way to detect such cases, to increase composability and testability of functions, which in turn will increase code reuse. Maybe this is the same as a metric for potential code reuse in the code-base?

1
0

Cohesion inside a single function might simply be called code duplication.

There's also algorithms for automatic procedure extraction. Here's one thesis about it: https://research.cs.wisc.edu/areas/pl/theses/raghavan.thesis.pdf

One could say that a function has "cohesion" if the procedure extraction algorithm is unable to extract anything from it further (give and take the tuning of that algorithm).

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.