2011/2/16 Sean Corfield <seancorfi...@gmail.com>

> On Tue, Feb 15, 2011 at 3:11 PM, Raoul Duke <rao...@gmail.com> wrote:
> > you might also sorta be saying that there are lots of different kinds
> > of polymorphism in programming, and that we need to know when to/not
> > use any given form of it, which i'd agree with :-)
>
> We're probably in violent agreement, yeah :)
>
> I think one of the big sticking points for a lot of folks raised on OO
> - and Java in particular - is moving to a mental model where types are
> "not needed" and adopting, for example, duck typing as a way to
> achieve polymorphism without types.
>

Duck typing is a rather weak kind of polymorphism, and generally not the
kind which I would speak about for promoting Clojure best practices.

In Clojure, you will see some kind of duck typing when doing host interop
calls, e.g. (.length foo). But one has to acknowledge this is very weak :
you don't know if method .length of object foo will happen to implement the
expected the semantics by accident or not.

In Clojure, the focus is on the function, and thus you know which function
you want to invoke, you're in control of its namespace and its name. So if
the function is somehow specialized for the argument foo, it will not be by
accident. It will either be by way of the function's implementation being a
plain old function with conditionals, or a protocol function extended to
foo's type, or a multimethod specialized on some characteristic of foo.

So I'd say: in Clojure, polymorphism of function is an implementation detail
of the function implementor, and the caller does not need to know/adapt.


>
> When I first got into FP it was via languages that either had no types
> or only very weak types. When I first got into OO, it was via C++
> which lets you abuse the type system in interesting ways (and of
> course you have full generic programming via templates so type-checked
> duck typing is essentially possible :) In '97, I got into Java and,
> whilst I liked the clean syntax and straightforward approach to most
> everything, I found the type system very restrictive (and still do).
> Since around 2001 I've been doing nearly all of my programming in
> scripting languages that have very weak type systems and when I'm
> writing OO in those languages, I tend to forego type checking in a lot
> of places so I don't have to introduce interfaces or base classes that
> my own classes then have to implement / extend, unless there's
> specific reasons for using an explicit hierarchy of types (which I
> find is rarely the case).
>
> If your domain model can be represented by a simple vector / map /
> set, then you have a very rich set of tools (in Clojure) to operate on
> your domain model. If your domain model is represented by fixed types,
> you have to write all sorts of wrapper functions to be able to apply
> those operations. One of the nicest things about Clojure in this area
> is that once you have a basic set of operations defined on your simple
> data structures, it's easy to incrementally wrap it up in as much of a
> typed API as you want via records, protocols and macros etc to create
> an aesthetically pleasing façade around the core functionality.
>
> Hope that makes sense?
> --
> Sean A Corfield -- (904) 302-SEAN
> Railo Technologies, Inc. -- http://getrailo.com/
> An Architect's View -- http://corfield.org/
>
> "If you're not annoying somebody, you're not really alive."
> -- Margaret Atwood
>
> --
> 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
>

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