Suppose that:

  • you invent a new coordinates system and you create a class to represent it
  • you have two products which need to deal with this coordinates system but which, apart from that, are completely independent

Then, how do you share this class among both products?


I think this question can receive a generic answer, but I ask it in the specific context of Python programming.
Translated in "Python words", the question is: is it worth creating a package which defines only one class? What other ways are there to share very small bits of functionality?

  • I don't know Python, but in C# you could create a dll. Seems excessive for a single class, but it would certainly work. – Phil N DeBlanc Nov 9 at 14:26
up vote 0 down vote accepted

The correct way is to make a package.

Now, when its a single class you have to ask yourself whether its easier just to copy and paste the code.

But even if thats the case, it doesnt make it the right way to do it generally, it just means you decided to cut a corner and save some time.

  • Thank you for your answer. Have you ever encountered packages which define only couple of classes and don't do much more than that? – filaton Nov 9 at 14:41
  • yes, I've got into the practice of always separating eveything, so if I have a small project I end up with packages with only a couple of things ir even just a single thing in. – Ewan Nov 9 at 14:43
  • Ok! One additional question (which could be an entirely new question) but do you sometimes "regret" separating everything into packages? That it's sometimes less flexible, etc. – filaton Nov 9 at 14:48
  • 1
    nope. sometimes its more typing, but theres plently of times in the past where I have regreted NOT seperating things out and had to do extensive refactoring to fix it – Ewan Nov 9 at 14:51

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.