I'm refactoring a 500-lines of C++ code in main() for solving a differential equation. I'd like to encapsulate the big ideas of our solver into smaller functions (i.e. "SolvePotential(...)" instead of 50 lines of numerics code).
Should I code this sequentially with a bunch of functions taking very long parameters lists, such as:
int main(int *argc, void **argv){
interpolate(x,y,z, x_interp, y_interp, z_interp, potential, &newPotential);
compute_flux(x,y,z, &flux)
compute_energy(x,y,z, &eng)
...
// 10 other high-level function calls with long parameter lists
...
return 0;
}
Or should I create a "SolvePotential" class that would be called like so:
int main(int *argc, void **argv){
potential = SolvePotential(nx, ny, nz, nOrder);
potential.solve();
return 0;
}
Where I would define functions in SolvePotential that uses member variables rather than long parameter lists, such as:
SolverPotential::solve(){
SolvePotential::interpolate()
SolverPotential::compute_flux()
SolverPotential::compute_energy()
// ...
// 10 other high-level function calls with NO parameter lists (just use private member variables)
}
In either case, I doubt I'll re-use the code very much... really, I'm just refactoring to help with code clarity down the road.
Maybe this is like arguing "Is it '12' or 'one dozen'?", but what do you think?
Write it sequentially and then refactor if there's something you think you can reuse or would make it clearer.
Also, a SolvePotential class doesn't make a lot of sense since a class should be an Object with the method SolvePotential.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With