I am very fond of the concept of mixins as well as the Python language. The Python language does not really have the concept of mixins, however it does provide multiple inheritance. Although mixins and multiple inheritance are similar, or can be used similarly, in a lot of ways there are some very important differences.
Here is a simple illustration of mixin behavior in Python.
In this example, Jsonable is the mixin which provides generic reusable functionality that can be "mixed into" an existing object. This example is nothing special, this is a very typical use of inheritance in Python.
Let's take a look at a similar example in Ruby, which provides native mixin support.
After looking at the assertions at the ends of both the Python and Ruby examples, it is easy to see the differences between the inheritance approach and the mixin approach. The inheritance approach in the Python example actually changes the classification of our class, by making it a subclass, as well as the classification of our class's instances by making them instances of both Person and Jsonable. In the mixin approach Person is not a subclass and Person instances are not instances of Jsonable so there is no re-classification.
Before going any further, I want to say a few things about object oriented programming. OOP allows developers to categorize pieces of data and functionality into reusable components that mimic the behavior of the real world business concepts they are attempting to represent with code. In a perfect world, that statement would be true, but we all know that objects do not always represent something in the real world.
Let's analyse some OOP terminology. We have classes, which are CLASSifications of some functionality. We have superclasses, which are high level broad classifications (or SUPERsets of functionality) and subclasses which are more specific classifications (or SUBsets of functionality). Given that classes are for CLASSifying functionality, where do we, as developers, draw the line between how we classify our objects and what our objects are capable of doing? Good question.
Is an object classified by what it can do, or by what it is? I am a Person. I am a Developer. I am a Male. I can do a somersault and stand on my head, but I'm not a Gymnast, and I would never classify myself as one. I can do those things, like many other People, many other Developers, and many other Males but so can Females and Gymnasts and probably even some kinds of Monkeys and maybe some kinds of Fish. Really, the only thing shared between all of these groups is that they have the ability to do the same action.
So, we have a bunch of different classifications of objects that share only a single ability. We could categorize them all as Somersaulters, but is that really a valid classification? I can do a somersault, but I wouldn't call myself a somersaulter, because as far as my abilities go that is quite insignificant. There are much more important and significant things that should classify me. When I meet someone on the street are they more likely to say, "Are you a somersaulter?" or "Can you do a somersault?" ? Honestly, probably neither. I would think the latter is more likely, however.
The point that I am alluding to is that using multiple inheritance to "mix in" some type of functionality to an object causes us to do some things that I consider breaking the rules, and we all know that "...Special cases aren't special enough to break the rules...". Referring back to the Python code example, we are reclassifying Person by making it a subclass of Jsonable. Is the fact that the Person can "save_json" significant enough that it should define it? Think about the relationship between Jsonable and Person. Person is a subclass of Jsonable, which means that Person should further define Jsonable to be more specific, right? Does it? No, I don't think so. A Person doesn't further define anything about Jsonable, other than the fact that it prints Person related json data, but Jsonable already does that without any further definition.
tl;dr - I know, so I'll cut it off here. There will be a follow up post about mixins because there was a lot I didn't cover. First class functions as mixin alternatives, why some think that mixins are harmful, and classification of bacteria and lichen. Hope you check back soon, thanks for reading!
Passionate, professional software developer & hobbyist. Language nerd & regular user of Unix, Python, Ruby & JavaScript.
Tuesday, November 22, 2011
Wednesday, November 9, 2011
My Crusade for Agility: Part 12
Welcome to the 12th installment of My Crusade for Agility. My crusade began nearly two years ago when I changed employers. In that time I have seen more change than I would think many developers have seen in their entire career. Fortunately, I've got a great team to work with who are all on board with implementing changes that allow our team to be more adaptive.
We're doing a lot of good things that include but are not limited to:

Our team has grown quite a bit recently also. When I first started there was myself and 2 other developers working on our project, now we have 3 Full time web developers, 1 part time web developer, 1 half web developer / half manager, 3 developers who have been primarily supporting the legacy system who are recently getting more involved with web development.
Another challenge
We're doing a lot of good things that include but are not limited to:
- test driven development
- pair programming
- a weekly code kata
- continuous integration
- automated deployments
- automated database migrations
- contributing to open source
- development sprints
Fairly recently we added some monitors in our common development area that displays all of our bilds on one monitor and scrolls through each build individually (to show more details for each build) on the other (see above). We also recently got some new (awesome) laptops for our development machines and added a third pairing station in our development area (see left and below).
We also did a bit of redecorating. We raised some desks to standing height (like the rest of our desks) for both our build display monitors and a dedicated IE testing machine (see below). We also added some shelves four our growing library of technical books.

Our team has grown quite a bit recently also. When I first started there was myself and 2 other developers working on our project, now we have 3 Full time web developers, 1 part time web developer, 1 half web developer / half manager, 3 developers who have been primarily supporting the legacy system who are recently getting more involved with web development.
Another challenge
Along side all of the agile adoption changes that have been going on there has been another very important thing happening. We are transitioning from our legacy desktop application technology (written in PC Cobol) to the web (written in Python). We are trying to approach this as iteratively as possible, swapping out components and sub-systems and integrating with the legacy system where necessary. This is a fairly significant amount of work to do, but the challenge is training ourselves.
The fact that the replacement system is written in a completely different technology for a completely different platform makes the transition very difficult for the developers and maintainers of the legacy system. Also, the fact that the legacy system is so vast with a large number of undocumented features complicates the process of providing the same business value in a new platform. We need to simultaneously iteratively develop a replacement product and train the existing developers in the new technology and the new developers on the legacy system. The technical training is more than just learning a new language or platform, it's learning OOP, Python, JavaScript, CSS, HTML, HTTP, SQL (and relational databases), etc, plus all of the various open source libraries that we use.
To help with the technical training we started doing a weekly code kata. We started with Uncle Bob's bowling kata to practice pair programming and TDD. We have had quite a few katas now, each has added some type of functionality to our original bowling game, and have largely focused on pairing/mentoring and TDD. I have found that the katas that seem to go the most smoothly are those that we start with some failing acceptance tests.
That concludes part 12 of My Crusade for Agility. Thanks for reading and I hope you check in again for future installments.
The fact that the replacement system is written in a completely different technology for a completely different platform makes the transition very difficult for the developers and maintainers of the legacy system. Also, the fact that the legacy system is so vast with a large number of undocumented features complicates the process of providing the same business value in a new platform. We need to simultaneously iteratively develop a replacement product and train the existing developers in the new technology and the new developers on the legacy system. The technical training is more than just learning a new language or platform, it's learning OOP, Python, JavaScript, CSS, HTML, HTTP, SQL (and relational databases), etc, plus all of the various open source libraries that we use.
To help with the technical training we started doing a weekly code kata. We started with Uncle Bob's bowling kata to practice pair programming and TDD. We have had quite a few katas now, each has added some type of functionality to our original bowling game, and have largely focused on pairing/mentoring and TDD. I have found that the katas that seem to go the most smoothly are those that we start with some failing acceptance tests.
That concludes part 12 of My Crusade for Agility. Thanks for reading and I hope you check in again for future installments.
Subscribe to:
Posts (Atom)

