The perils of bunch/bundle?by Rob Galanakis on 25/08/2013
I had some discussion on Friday about static vs. dynamic typing (grass is always green, eh?), and our frequent use of the “dictionary with attribute-like notation” object came up (commonly called a “bunch” or “bundle”). A number of people were saying how bad/unsafe it is. Not convinced, I brought the source code up on the projector and asked people: “If I were to set the ‘__’ key, what would happen?” My thinking was that, if this is a data container like a dictionary, what happens when the data conflicts with non-data keys?
A room full of programmers, and no one could answer (actually I still don’t know, nor do I remember if it raised a KeyError and AttributeError in the appropriate circumstances, but I’d guess not). I pointed out the reason this type of object is a problem is because, even though we have several thousand uses of it and it’s been around for a decade, how it works isn’t clear or documented. Static typing doesn’t change that. Bad code is bad code and there’s heaps of bad code in wonderful statically typed languages.
It so happens we have several more implementations of the same object. The only one that has documented edge case behavior is in probably the highest quality area of the codebase. Incidentally, it is only used during testing. So maybe bunches aren’t that useful after all…firstname.lastname@example.org