On 2/17/07, Dean W. [email protected] wrote:
As far as I understand, DuckTyping is not something based on method
matz.
For me, this does break the POLS, because it breaks the Liskov
Substitution Principle
you are opening a can of worms (or ducks if you prefer).
I would say that LSP does not apply here simply because in Ruby we do
not have that kind of contract.
In order to apply LSP we need to say at at a point hey here we have an
object of class Base.(let the gods forgive me that I use Java)
void aMethod(final Base b){
…
}
and we expect this to work whenever we call aMethod with an object
that is a Base.
Anyway the compiler would not really allow otherwise.
SubClass sc; // subclassing Base od course
aMethod( sc ); // this is expected to work (from the type POV).
Such things just do not exist in Ruby, I believe that Ruby has
explained something to me:
OO Languages are Class oriented languages
Dynamic Languages are Object oriented languages.
Replace Class with Type and you see what I mean.
This is all very much IMHO of course but I feel that the Ruby
community has made me evolve a lot away from “Class oriented”.
(loosely, "an object of a derived type can be
substituted for an object of a base type", for those of you who
haven’t heard of it…). LSP is essentially the underpinnings of
Bertrand Meyer’s “Design by Contract”.
If I’m iterating through a collection of objects and all of them
respond_to? a method, yet an exception is thrown in some cases, that’s
surprising
Do not let your code surprise you. If it does than it is not the
language’s fault.
But I have seen the smiley
The deep-copy scenario is a good one. In this case, it
would be nice to have a succinct way of copying the object graph
without having to worry about some dup methods “not working”.
Meaning not worrying about the semantics of your program ???
But you still have a good use case below, not good enough for a RCR but
good. → see my last point too please.
“contract” can’t be satisfied transparently by all derivatives. Maybe
that’s just the price we have to pay for being rich
Instead of advocating for a RCR especially in the present scenario which
is:
“Well that might be bad sometimes and goos sometimes, not really worth a
CR”
you might just create your own little toolbox.
class Integer … def dup etc.
Advocating is a good thing but it is not the only one.
After some months of using your toolbox you might still want the CR or
maybe throw it away, who knows?
Cheers
Robert
P.S.
I am against the CR but the discussion is a great one! Thumbs up!
R.