I'm writing this library in which the user can provide custom code defining the algorithm used for finding an optimal solution. In the papers that I have read, the targeted user thinks in terms of finding the hyperplane that maximizes a measure of impurity. Since I want the user to articulate its code in a way that is consistent with their view of the problem, I created a struct hyperplane
and a function double impurity(hyperplane* phyperplane)
that should ease their writing of the algorithm.
However, inside the implementation of impurity
, many intermediary expensive calculations that are of interest to the calling library code are performed. If the user-defined code only returns an instance of the struct hyperplane
, the calling code will have to re-calculate these values once again.
I was thinking of adding a field representing each of these values to the definition of the struct hyperplane
. This way, when impurity()
is calculated, the intermediary values are stored in the instance returned to the calling library code. However, this will change both what struct hyperplane
and impurity
stand for. I could rename them to struct hyperplane_and_values
and get_impurity_and_set_values
respectively but this could risk confusing the end-user, which shouldn't be concerned with these details. On the other hand, keeping the original names seems like dirty code because it misleads the reader to what the named entities actually represent. Is there a "right" choice here?