I just refactored a script with about twelve, nearly identical, one-liners to one that uses reflection to dynamically bind static methods to a class.
The refactored version can be found here. And before refactoring here.
My question is: Does this seem over-engineered? Am I chasing some academic elegance that is in practice, worse than the obvious way? The refactored form is way shorter (about 70 lines) and more "beautiful" (for some defined notion of beauty), but a novice programmer might not understand it at all.
One problem with the "naive" approach is maintainability - you have 12 times more methods to maintain, debug and test. Imagine you need to add an extra parameter to all of them... with time, the methods will become very similar but not exactly the same. So the "complicated" approach may pay off with time.
By the way, there's a bug in one of the 28 "naive" methods which is not present in the rest 27 of them :)
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