Re:Julia 0.2 released
by StefanKarpinski on Sunday November 17, 2013 @04:51PM
(#6751110)
Fair point, although R's multiple dispatch barely counts as a language feature at all, but is really more of a standard add-on library (read on). All S4 is doing is using a hash table keyed by method signatures to look up which function body to call. You don't even need any syntactic support since "defining a generic function" is just a matter of defining a function that does a hash lookup and then applies that function to its arguments. R doesn't provide any syntactic support for adding methods to generics – you literally have to give it a vector of strings of argument class names. Since you can do all of this in any language – even C – it's arguable that multiple dispatch isn't really part of "the R language" at all, but rather "the R system" happens to ship with a standard implementation of hash-based multiple dispatch and a few of the built-in function like "show" and "plot" are defined using it.
Due to not being a deep language feature, S4 lacks some crucial abilities. It doesn't support any sort of type hierarchy besides the special "ANY" class. Without the ability to define a type hierarchy and program to abstract types, most of the power of multiple dispatch evaporates. Even though it is technically an implementation detail, I've found that performance is a critical feature for multiple dispatch to really come into its own. R's S4 dispatch has been described as "slower than S3" [1] – and S3 dispatch is not exactly fast. Unless really basic things like + and array indexing can be generic and usably fast, you're not really cooking with gas.
[1] http://www.r-project.org/conferences/useR-2004/Keynotes/Leis...
Re:Julia 0.2 released
by rcthompson on Sunday November 17, 2013 @06:07PM
(#6751483)
Thanks for the explanation. What do you mean by "It doesn't support any sort of type hierarchy"? I've contributed to a package that defines some S4 methods on a base class and relies on that implementation being called on derived classes as well.
Re:Julia 0.2 released
by StefanKarpinski on Sunday November 17, 2013 @07:08PM
(#6751676)
This may be a misunderstanding on my part because I am by no means an R expert (I've done a fair amount of stats work in R, but no library development). Can you add a method for base class "Foo" which will automatically apply to "Bar" which is a subtype of "Foo"?
Re:Julia 0.2 released
by rcthompson on Monday November 18, 2013 @04:49AM
(#6753533)
As far as I know, yes, this works just fine. We rely on this in the BiocParallel package in Bioconductor.
What about R with S4 classes?