But the problem with this code isn't that there is too little duplication! The trouble wass that your grasp of the language wasn't that good and didn't have any idea of how to organize the code.
So, would you have solved it by a more readable form of metaprogramming? Seems to me it's either that, or copypasta.
(Could still be me being a noob, but I can't see some other architectural means of avoiding a choice between either duplication or tricky-to-read metaprogramming in that case.)
(Could still be me being a noob, but I can't see some other architectural means of avoiding a choice between either duplication or tricky-to-read metaprogramming in that case.)