Konrad Hinsen wrote:
> On 11.03.2009, at 23:34, Chouser wrote:
> 
>> 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.
> 
> Not really. Most map operations, such as assoc and dissoc, return a  
> map with the same metadata as the input map. The result thus looks  
> like being of a specific type, even if dissoc just removed a key that  
> is important for that type's semantics.
> 
>> I don't know if that leads to any particular conclusion.
> 
> My main conclusion is that Clojure's system is a lot more flexible  
> but also a lot more fragile. Any function can modify data of any  
> "type" (as defined by metadata), even without being aware of this.

Modifying type tags without being aware of it?  That sounds like FUD to 
me.  Using metadata is relatively atypical in the first place, and 
modifying the :type tag without being aware of it sounds like an 
extremely minimal risk.

> Any function can at any time modify the global inheritance hierarchy  
> in any way it wants. Any module can add an implementation for any  
> type to any multimethod. That opens the way to many interesting  
> strategies for data handling, but also to errors that will probably  
> be hard to track down.
> 
> Konrad.

We've heard this line of reasoning before when moving from static to 
dynamic languages.  If having the power to do what you want with the 
language scares you, then maybe Java is a better choice.  All these 
"hard to track down" bugs people worry about when having more 
flexibility in the language don't seem to crop up often enough to drive 
people away though.

Adding an implementation for a new type to a multimethod is equivalent 
to adding an interface implementing method to a class you defined.  So 
for example you could add to-string or to-xml or to-bytes or whatever to 
your own objects to make them interoperate with some existing library. 
Having libraries built on top of abstract interfaces like this is 
exactly what makes them interesting.

In Ruby you can open any built-in class you want, like String, and add 
or modify any methods you want.  In practice it happens rarely and 
almost never causes problems.

-Jeff

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to