Hi,

2010/6/3 Christophe Grand <christo...@cgrand.net>

> On Thu, Jun 3, 2010 at 1:56 PM, Laurent PETIT <laurent.pe...@gmail.com>
> wrote:
> > If I understand things well, one problem with ruby monkey patching is
> that
> > if a library I use opens a class C and adds a method whose signature is M
> to
> > it, and if in my own code I also open the same class C and add a method
> > whose signature is M to it, then the library may break because it will
> call
> > my implementation of M, not the librarie's original one.
> >
> > Now to clojure. I can see the same problem occur, while the article's
> author
> > claims that in clojure there's (almost) no problem anymore.
> > If several libraries, including my program, redefine blindlessly a
> protocol
> > implementation for the same type, then the "last to speak" wins.
> > So isn't the problem basically the same ?
>
> my 2 cents:
>
> The surface of the problem is reduced because of namespacing: two
> different "fold" methods (with different semantics) from two protocols
> won't clash.


Of course. I was not thinking about that. I was talking about working on the
same protocol.

Here is the scenario I have in mind: clojure 1.3 ships in december with
loooots of protocols for the whole set of abstractions currently implemented
as interfaces.

A bunch of developers all over the place start adding implementations for
these protocols for types not covered by clojure itself ....


> Plus if there are two extensions of the same protocol to
> the same type, they should be rather equivalent since they satisfies
> the same semantics.
>

... granted, the more specific the semantic will be, the less different the
implementations should behave.

So back to my scenario: lots of people adding protocol impls for lots of
"common java types" : new implementations each time, copied implementations
some other time. Of course some implementations will be buggy the first time
they are delivered. Depending on N libraries each providing their own
implem. in a particular version could lead, depending on the order the
libraries are loaded in the environment, in having sometimes a buggy
version, sometimes an "almost correct version".


>
> I think one must only extend a protocol to a type if he owns either
> the type or the protocol.
>
>
The general example here is java.lang.String. Nobody owns it but oracle/sun
(and arguably clojure itself). People will want to reimplement some clojure
protocols on it, interpreting the String content in a bunch of exotic ways
:).

But I understand the rule : "extend with great care if you neither own the
protocol nor the type".

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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