Mixins

code

A term I’ve seen before, but never investigated: Mixins. A nice post on mixins in Lua on r/programming acquainted me with this pattern. I like it, because the general idea is to have many reusable bits of code without inheritance hell as seen in any Java project and many C++ codebases. Depending on how the languages allows you to implements mixins, one defines small classes with one or a few functions and with multiple inheritance you pick what you need for your new class. Python and C++ work that way, and DrDobbs wrote an article that shows the nitty gritty of an implementation in C++. Unfortunately, it’s gets hairy fast, but if all you care about is sharing a function between some classes (which is what I would like most of the time), it seems to remain pretty simple (no need for any initialization).

Intradasting.