On 2007.12.08., at 3:05, Werner Schuster (murphee) wrote:

>
> Attila Szegedi wrote:
>> Also, I'm talking solely about the problem of selecting among
>> overloaded Java methods invoked from a dynamic language here. Dynamic
>> languages are better off without a concept of an overloaded method
>> altogether, as they can mostly have a single method accepting any
>> types of arguments anyway :-)
>>
> ... which then has to do the pattern matching and dispatching itself,
> and has to implement that itself.
>
>
> http://www.artima.com/rubycs/articles/patterns_sexp_dslsP.html
> http://www.ibm.com/developerworks/linux/library/l-pydisp.html
> http://thinkpython.blogspot.com/2005/03/dylan-style-multiple-dispatch.html
>
> Just think of all the visitor implementations out there which would
> become unnecessary with proper multi-dispatch...

My personal experience is that if you want to do visitors with pattern  
matching, then Java-style overloaded methods don't buy you much in  
terms of code conciseness. Ultimately, if you have:

void visit(Map)
void visit(List)

then your void visit(Object) will need to look like:

if(obj instanceof Map) {
     visit((Map)obj);
} else if(obj instanceof List) {
     visit((List)obj);
} ...

I find Scala's idea of case classes + pattern matching on them to be a  
much nicer fit for implementing this kind of patterns (even if it  
arguably can go against more orthodox encapsulation concepts, anyway,  
that's a different story).

Attila.

--
home: http://www.szegedi.org
weblog: http://constc.blogspot.com





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM 
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to