Christian Posta bio photo

Christian Posta

Global Field CTO at solo.io, author 'Istio in Action', 'AI Gateways in the Enterprise' and other books. He is known for being an architect, speaker, blogger and contributor to AI and infrastructure open-source projects.

LinkedIn Twitter Github Stackoverflow

In Python, mixins allow a programmer to package a set of clearly defined and cohesive methods into a unit that can then be used to add functionality to other classes by “mixing in” these methods. This programming style, when used correctly, can lead to well-organized code as well as improved readability. However, in python, there may be better approaches than to use mixins. As Michele Simionato points out in his two part series (part 1 and part 2), python has better constructs for providing the same advantages to using mixins without the drawbacks.

The drawbacks Michele points out include: class namespace pollution, methond-name collisions, accidentally overridden methods, unclear class hierarchy, and cognitive load to understand classes composed of many mixins. To learn more about mixins, see an overview from wikipedia, this post from StackOverflow, this article from Linux Journal and of course the Artima posts from Michele (part 1 and part 2). Michele advises to use this as an alternative: Overloading/Generic Functions