On Wed, Mar 11, 2009 at 12:00 PM, Konrad Hinsen <konrad.hin...@laposte.net>wrote:
> > On Mar 8, 2009, at 18:53, Rich Hickey wrote: > > > I know people usually think of collections when they see vector/map/ > > set, and they think classes and types define something else. However, > > the vast majority of class and type instances in various languages are > > actually maps, and what the class/type defines is a specification of > > what should be in the map. Many of the languages don't expose the > > instances as maps as such and in failing to do so greatly deprive the > > users of the language from writing generic interoperable code. > > My own experience is mostly with Python. Python objects are indeed > essentially maps (Python calls them dictionaries). But even though it > is easy to obtain the map equivalent of any object (object.__dict__), > I hardly see this being done. Python programmers tend to use maps and > objects in very different ways, and that includes experienced > programmers who are very well aware that objects are just maps plus a > type tag plus a set of methods. > IMHO a big reason Python programmers don't typically treat objects like is maps/dictionaries is that the set of things found in the map (dictionary) for that object (__dict__) are just a small subset of the interesting attributes of the object. In Python things like class level attributes, properties, descriptors and multiple inheritance all add a lot of flexibility to defining and using objects that would take a some effort to replicate on top of simple maps. The flexibility of Python however does allow you to treat even complex objects as dictionaries (by implementing __getitem__) or dictionaries as objects (by overriding __getattr__ or __getattribute___). I've used these techniques in places where I need to treat an object like a dictionary for interop, or places where I wanted to use a dictionary but with the nicer syntax for attribute access on objects ( a.foo instead of a['foo'] saves 3 keystrokes). -- Cosmin Stejerean http://offbytwo.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---