On Wed, Mar 11, 2009 at 1:54 PM, Cosmin Stejerean <cstejer...@gmail.com> wrote: > > 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.
It's interesting to compare a Python class with a dict inside to a Clojure map with metadata "outside". Interacting directly with a class dict feels a little dirty, because you could be circumventing the API provided by the class methods, making it easy to get the object into a bad state. Clojure's maps being immutable reduces the amount of trouble you can cause by dealing directly with the map. Defining a instance method for a Python class allows you to connect some code to your data, which internally uses a type pointer from the instance to the class. In Clojure you can put functions directly in the metadata (as clojure.zip does), or put a type tag in the map or in the metadata, and use a multimethod dispatching on that to connect code to your data. Similarly, any inheritance in Clojure would normally be defined on a keyword (or symbol or collection of either) that is in the map or the map's metadata. In Python, the object knows its class, and the class knows about the hierarchy. I don't know if that leads to any particular conclusion. I suppose it does suggests a trivial program (or a trivial part of a program) in Clojure will likely have less code for setting up classes than the Python equivalent -- you start with the data you actually need, and can add "methods", polymorphism, etc. if needed later. --Chouser --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---