On 2/15/07, Hans Fugal <hans at fugal.net> wrote:
> It's always important for the API to be understood. The advantage to a
> dynamic (duck-typing) language is not that you don't have to understand
> or make understood the API. The advantage to a dynamic language is that
> you can pass a guy dressed in a duck suit to the library that was only
> designed for ducks. The difference becomes you documenting "something
> that behaves like a duck in this sense" vs. static type checking which
> requires things that descend from Duck or _are_ Duck. It's not a matter
I see the value of what you're talking about, and I've had to deal
with the inconvenience of making an object conform to an interface so
that it would work with an API designed for said type. This is why
you should design your API using interfaces rather than concrete
classes (in the case of Java). However, not everyone does this so you
ofter have to deal with the short sightedness of another developer.
At least with duck typing I don't need to worry about this. That's a
big win. But, I'd also argue that subclassing or implementing an
interface isn't that much harder, and I know what I'm expected to
implement. Using either straight inheritance or a combination of
inheritance and composition I can work around any API issue.
How do you know what duck-ish methods will be called off of an object
without access to the source code of the library or trial-and-error
with "method not found" exceptions? Telling me that your routine
expects a duck doesn't tell me much about it. Because a "duck" is a
vary fluid concept in a dynamic language. I may think, "Oh, you
naturally want to call a 'quack' method." When really the routine
wants a "waddle" method. How am I to know?
I guess I'm just saying that with a statically typed language I can
look at the API and know how it is supposed to be used. With a
dynamic language, there may be a fair amount of writing and running
code just to see what breaks as you discover the correct way to use
the API. Seems like a time waster.
I'm sure as I use these languages, I'll find that my fears are
unwarranted. I'm just describing the "flaw" in my opinion,
notwithstanding your explanation.
> of power, it's a matter of expressiveness. People argue that static
> languages are safer. I say we have enough of that with our government
> treating us like babies. I don't need my compiler/interpreter to do it
> too.
I'm completely on board with you when it comes to government ;-).
Thinking of that parallel will help me be more accepting of the
liberty a dynamic language gives me, rather than curse the lack of
static type safety. Too much law and restriction is worse than not
enough, but I don't endorse anarchy either.
-Bryan