Nigel Rowe <tutor.fisheggs <at> xoxy.net> writes: > >> I have two modules, both define the same set of classes (with differing > >> implementations) and a number of utility functions that use those > >> classes. > >> The utility functions are identical (the differences I need are > >> abstracted in the classes), so they are cut'n'pasted into both files.
How about putting all utility functions in a separate module and doing a "from P import *" or "from C import *" at the top of that module, depending on some command line parameter or whatever it is that determines which one should be imported? It's not elegant by any means, but at least you don't have to copy-paste code around any more and the changes to the existing code are minimal. > >> How can I refactor these modules to avoid the code duplication? I would say that the fact that there are two parallel implementations of the same classes with small differences is worrying as well. There should be an ancestor layer in there implementing common behavior. > Maybe I'm going too far, trying to eliminate the cut'n'paste, but I've > always thought it a bad smell. It does indeed smell of a maintenance nightmare waiting to happen :). The bad part is that it tends to get progressively worse. Imagine also what would happen if you'd get even more of those similar modules. Yours, Andrei _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor